IMHO, CakePHP made PHP bondage-and-discipline.
Hi everyone,
In My Humble Opinion, I think CakePHP made PHP bondage-and-discipline.
The first time I heard about RubyOnRails, CakePHP, PHPonTrax, JavaOnSails &c… I thought: “Hey! it’s no novelty, actually there’s a book named ‘Design Patterns’ that deals with all that stuff of Active Records and so on… What’s the need of such things?”
I never paid too much attetion to them, in fact I related them to the dreaded COBOL - but Ruby and PHP are not as verbose as COBOL-fingers.
As everybody knows, a well respected hacker will never admit to have learned COBOL - but unfortunately I have learned it in College, so I am not a hacker (yet
). Hey! Hold on! It was just a semester in that bloody Mackenzie’s (yes, we have a Mackenzie in Brazil) and I’ve abandoned it in the middle of the discipline.
You know, COBOL has a very strict structure on how programmes should be engineered and written. There are only two level of tabs, and those DIVISIONs on each you define variables, file descriptors, io masks - this sort of pedantic way of programming.
But COBOL enabled brain-dead people to develope all types of commercial softwares. COBOL was written in english and supposedly an english-speaking person should be able to create, read, understand and modify any routines made by someone else. COBOL even had paragraphes.
This characteristic could only be achieved if everyone did everything in a single and common way - I should be guided, through the language syntax, to write the same solutions in the same way as you would do. Gosh, was COBOL the computer’s NewSpeak?
Well… Time has passed, those dinosaurs mainframe were gradually replaced by new servers, and the languages evolved into a more structured and more free syntax, like C.
The issue with C, Perl, PHP, Java and all-alike, is that you can always do the very same thing in a different way, opposed to COBOL which is bondage-and-discipline.
The phisolophy of “Convention over Configuration”, or whatever you call it, is just a modern way to enforce bondage-and-discipline on programmers. Convention itself is harmless, Kernighan and Ritchie have the blessed ident style and so Java people, GNU people.
The problem rises when Convention replaces Freedom - a forced standardisation of programming which affects almost every aspect of coding: naming style, code organisation and even the “best practices”.
Someone thought to consolidate all those Design Patters in a single project and give a name to it. CakePHP was inspired by RubyOnRails, both share some features - and both turned vanilla languages into bondage-and-discipline.
RubyOnRails and CakePHP are not only tools which would help the developer to be more productive - oh no… they’re schools of thoughts. They have a way on doing things which are considered “best practices” and should be followed closely.
Bondage-and-discipline is not Bad And Wrong. It is a leverage for those who are more pragmatic in solving problems or creating fast-food solutions - to problems which the kernels are the same among near 80% of them.
I like CakePHP… But I like PHP better. Sometimes I want to have freedom to model a solution according to a very special line of thoughts that oftenly is not the same of CakePHP. Now I have arrived to the point I wanted.
As CakePHP makes PHP into bondage-and-discipline language, programmers - specially the begginners - tend to adapt their solutions into CakePHP frame… Sometimes the best step is something quicker and more direct, but CakePHP, RubyOnRails or [your language of choice]on[transportation of choice] forces flowing or spliting the solution into meaningless parts.
In an exaggerated representation: “Hey, I just want to print out a formatted number! Why create a helper_to_format_number method in the PrintHelper class?” or “Why am I iterating all the result set in Model class into an array to iterate again in the View?” Or even, “I must structure this data into that framework-structure to output using the MagicalOutputHelper class…” (which likely would take longer to do).
I don’t if I am being clear here. These frameworks are wonderful tools - actually I develope a tool for CakePHP named dbdesigner2cake - but I don’t twist my solutions logic to fit the CakePHP’s mold. Don’t you even bother to talk about that vendor directory on CakePHP, because few things just won’t work; some third-party modules count on the fact that’s being run standalone or isolated - not within a framework.
There are situations that RubyOnRails (that’s gonna ache on the Ruby Envy guys) and CakePHP just won’t do, they’re closures with programmers stuck inside.
Design Patterns should be used a la carte. “Oh God! My code is messed up, let me organise it using MVC”, “Ahan, I am just doing CRUD here, I guess Active Record will fit just fine”, and so on.
Perhaps there’s something to learn with DJango guys, they actually stated they’re against auto-magic. As they don’t hide the magic behind the stage of an all-mighty framework, the programmer DOES HAVE the option to use or not one of the magics available without being considered too unelegant. Or extend it to make it able to do the desired functionality. When the framework is too magical simply there is not sockets to connect an extension…
These frameworks do the dirty work for the programmer charging a price: less flexibility and freedom of choice of how to do things. Is this good? I don’t think so…
I love CakePHP productivity, but I dread that it will make all programmers to code all the same code. Oh you don’t agree… If you want to make a blog with the too-obvious table Posts on it, unless we’re talking about different frameworks, on CakePHP the model class would be exactly like this:
<?php
class Post extends AppModel {
var $name = “Post”;
}
?>
See? There are thousand of ways on naming, invoking and accessing a database table in PHP. But in CakePHP this is the only way.
The same applies to [Your Rail Framework Of Choice]. Or even [Your language-of-choice] made bondage-and-discipline.
UPDATE: I found in Technorati two blogs supporting my point of view:
http://www.jonlee.ca/switching-from-rails-back-to-php/
http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html
Category: Technology
October 12th, 2007 at 07:07
It’s really interesting to read this post - and in many ways I agree with you - but right now I’m enjoying the bondage and discipline of CakePHP.
Perhaps a lot of your opinion is as a result of learning COBOL at college - I’m guessing you studied Computer Science or Engineering or somesuch thing - myself I went to art school studied sculpture and have drifted over the years into web development…
Its kind of hard to explain, but I reached a point as a developer when I felt the urge to go looking for some structure to use to underpin my code. I think the main motivating factor for programmers is boredom - or to put it the other way the desire to learn… I’ve developed CMS systems in ASP and PHP over and over again. The early ones were often rubbish - but the latter ones were really good. But I wanted to learn OO programming and in many ways the easiest way to do this is to imesre yourself in something that aleady exists.
I touched on all sorts of frameworks (including ROR) and felt I quite liked Cake - I’ve been working with on and off for about six months.
Some days I feel like I never want to use anything else and other days it makes me want to tear my hair out, however the import thing is that it makes you think about different ways of getting to the same result.
Some things are just plain wierd.
- if you make a framework why don’t you make it secure by default?
- why the total lack of a native HABTM checkbox solution?
- why isn’t there native support for extra fields in join tables? (I know there is in 1.2)
Other things really annoy me - I know in strict MVC sense that perhaps one shouldn’t have direct access to session variables in the Model - BUT doing things like appending a session id to a row is such a common action that it seems daft to write reams of code just so you can post it through the controller - the RIGHT way…
(This sounds like a total moan - so I should say I love using Cake and have a lot of respect for the guys who built and continue to build it)
I’ve been thinking a lot about Code Ignitor recently thinking that maybe that offers a good balance and also written my own CRUD classes for use in other projects. At the end of the day a framework should take care of the grunt work not tie you down.
Right now I have no idea what the answer is.
October 24th, 2007 at 05:27
[...] Read more :: http://blog.cirello.org/2007/09/24/imho-cakephp-made-php-bondage-and-discipline/ [...]