MVC from Rasmus

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

MVC from Rasmus

Post by Buddha443556 »

New entry on "Rasmus' Toys Page" dated Feb 27:
MVC?

I don't have much of a problem with MVC itself. It's the framework baggage that usually comes along with it that I avoid. Even parts of frameworks can be useful as long as you can separate the parts out that you need. As for MVC, if you use it carefully, it can be useful in a web application. Just make sure you avoid the temptation of creating a single monolithic controller. A web application by its very nature is a series of small discrete requests. If you send all of your requests through a single controller on a single machine you have just defeated this very important architecture. Discreteness gives you scalability and modularity. You can break large problems up into a series of very small and modular solutions and you can deploy these across as many servers as you like. You need to tie them together to some extent most likely through some backend datastore, but keep them as separate as possible. This means you want your views and controllers very close to each other and you want to keep your controllers as small as possible.

Goals for this approach
  1. Clean and simple design
    * HTML should look like HTML
    * Keep the PHP code in the views extremely simple: function calls, simple loops and variable substitutions should be all you need
  2. Secure
    * Input validation using pecl/filter as a data firewall
    * When possible, avoid layers and other complexities to make code easier to audit
  3. Fast
    * Avoid include_once and require_once
    * Use APC and apc_store/apc_fetch for caching data that rarely changes
    * Stay with procedural style unless something is truly an object
    * Avoid locks at all costs
From: The no-framework PHP MVC framework
Wonder if they're listening at Zend?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It is interesting to hear someone like that talk about frameworks. It looks pretty old school to me. I agree with most of the intent, but I have found that that style of development doesn't work as well for me as the application gets larger (which is most of the time).

I get the sense that the Zend Framework will be a more modern controller based design.
(#10850)
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

March 1 - Disclaimer: Since a lot of people seem to me misunderstanding this article. It isn't about OOP vs. Procedural programming styles. I happen to lean more towards procedural, but could easily have written the controller and data model code in an OOP style. In fact I did in another incantation of this.
What I am hoping to get across here is a simple example of how you can use PHP as-is, without additional complex external layers, to apply an MVC approach with clean and simple views and still have all the goodness of fancy Web 2.0 features. If you think I am out to personally offend you and your favourite framework, then you have the wrong idea. I just happen find most of them too complex for my needs and this is a proposed alternative.
Once again, he's catching some flak.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

* Avoid include_once and require_once
I've been seeing a lot of blogs note this in the last few weeks. Am I missing something? Last I checked the maximum difference possible should only be measurable in milliseconds. The difference is something like a hash lookup in C... minor. How could that come even close to comparison to a database response latency?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it seems a bit odd to me too.. almost like a grasping at straws for the all mighty optimization.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Actually I believe the performance problem with the _once() functions has to do with opcode caches like APC or Zend's. See http://www.zend.com/zend/week/week274.php#Heading3

After reading the disclaimer I get the impression that Rasmus, though well intentioned, did not think through the implications of his post. If you have a thorough understanding of the subjects he is addressing then it makes sense. But against the backdrop of the current PHP landscape it comes across as anti-framework, anti-MVC, etc. which is not exactly what the troops need to hear right now (in my opinion).
(#10850)
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Rasmus is entitled to an opinion like everyone else. I hear what he's saying but for a large application I doubt its the most beneficial approach. How many people actually have the discipline required for that approach these days? I always considered OOP is to be easier than a disciplined procedural approach which seems.

But then that's not his aim - he's just stating MVC is possible without a lot of OOP. Which is entirely valid and true. His framework reference I can agree with - it's one thing to use them as a quick application base, another when you need something specific and realise the whole thing is so interconnected its parts are useless in isolation. Go ezComponents...;)
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

arborint wrote:Actually I believe the performance problem with the _once() functions has to do with opcode caches like APC or Zend's. See http://www.zend.com/zend/week/week274.php#Heading3
In the thread, however, Rasmus makes clear that it is NOT the opcode cache that is causing the difference - its PHP's core that is. The difference in the code listed is substantial.

How high an impact that is *definitely* varies. I had one test that showed an inconsequential impact - almost not even there. But after tinkering a bit, a specific section of my game showed a monster difference in impact from it. Your mileage may vary and all that, so do keep in mind that it may not affect you in the same way.

As with any optimization, you should really only take on changing your code if you see a performance hit in a specific section of code that needs to be addressed. If your benchmarks and testing doesn't show a difference for the things you do - then there is no advantage for you. :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Maugrim_The_Reaper wrote:Rasmus is entitled to an opinion like everyone else. I hear what he's saying but for a large application I doubt its the most beneficial approach. How many people actually have the discipline required for that approach these days? I always considered OOP is to be easier than a disciplined procedural approach which seems.

But then that's not his aim - he's just stating MVC is possible without a lot of OOP. Which is entirely valid and true. His framework reference I can agree with - it's one thing to use them as a quick application base, another when you need something specific and realise the whole thing is so interconnected its parts are useless in isolation. Go ezComponents...;)
That's the thing about the article. He talks about interesting possiblities but ignores the complexity and confusion of MVC. We don't have a majority of developers who even do Model/Presentation separation (or even know what that means). I don't think he appreciates that he has the bully pulpet and that people will use his words to defend all sorts of poor PHP development methodologies. He should have erred on the side of making the stuff that was really beside his point to be safer for newbies.
(#10850)
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

TGIF!

Post by Buddha443556 »

Maugrim_The_Reaper wrote:But then that's not his aim - he's just stating MVC is possible without a lot of OOP.
I think OOP has nothing to do with the article.
Lerdorf wrote:So you want to build the next fancy Web 2.0 site? You'll need some gear. Most likely in the form of a big complex MVC framework with plenty of layers that abstracts away your database, your HTML, your Javascript and in the end your application itself. If it is a really good framework it will provide a dozen things you'll never need.
You can abstract the database, HTML, Javascript and the application using procedural too. The point he's making is none of it is needed. I think he even used the term "monolithic controller" not as a reference to Front Controllers but any Input Controller that grows beyond a simple page. It's all about keeping it simple.

When did simplicity become offensive in programming? Oh I could go on a nice long rant, guaranteed to offend 99.9% of those who dare read it but ...

TGIF!! :D
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Interesting. I personally don't like to use a single front controller like that quote mentions. On a really large application that can start become a bit of nightmare, unless I've just been doing it all wrong.

I actually create separate controllers for each module... each controller extends a template engine. As for templates, again, that's always something I've handled myself and they're just HTML with standard HTML comments, nothing more :)

Of course, not all the work is done in the controller... that would just be silly. That's why you have a well planned and organised directory structure with some form of systematic class loading (or __autoload() in PHP5) so that you re-factor things and each component (class) is then doing a specific job. I wouldn't refactor things just because I think I can... that's when you do just start complicating things, it's only for things that do different tasks.... (*realises he's gone way off topic and started rambling drunkeny, then leaves sentence half complete*
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

d11wtq wrote:realises he's gone way off topic and started rambling drunkeny, then leaves sentence half complete*
Cheers!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: TGIF!

Post by Christopher »

Buddha443556 wrote:It's all about keeping it simple.
When it can be simple. But when it can't be simple is has to be well designed. This is the great divide in PHP. To build a few dynamic pages you can keep it simple -- at which PHP excels. But grow it into something larger (say like phpBB) and you can see the growing pains and problems from not "keeping it well designed."
(#10850)
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Re: TGIF!

Post by Buddha443556 »

arborint wrote: ... "keeping it well designed."
Shh! They hear you! Spies everywhere! Design a naughty word. No design in the Agile/XP era of coding by the seat of your pants! [Unless it's a LSS project, they've seem to have discovered design is a necessary evil when you try to super size the Agile/XP methodology.]

Now how about more talk of BEER and less talk of nuts! TGIF!!
Salute! <Buddha spills a few drops of beer for the honorable Arborint!>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

8O :lol: :mrgreen:
(#10850)
Post Reply