Published 2008-03-26 16:07:00

Yeah, at one end we have our happy little hackers trying to make a quick CMS by throwing together a few includes and hiding functions everywhere in their wonderful directory structure, at the other we have those glorious frameworks.

So If you enjoy my rather questionable grammar, and High Horse views, here's the dig through CakePHP.

Dissent always welcome so comment away...

I was asked a few months ago to look at Cake PHP as an option to develop a new project, rather than use the components that various members of the maintenance team actually knew (mostly PEAR packages). While there always significant benefits with sticking with what we knew, It was only fair to do a reasonable evaluation. It did not come of much better than those CMS's. Although the code quality is significantly better...(yeah commenting / documenting!)

Let's start pulling apart some of the problems. - This is just from browsing SVN trunk.

My base class is better than yours .... the Object class

Now there's a name asking to be caught by internals, (they probably won't, as namespaces are pending, but you never know). But this is a bit of a clanger.

$x = (object) $somearray;

$x = new Object();

Great way to confuse programmers who do not know PHP inside out...

PEAR has had the PEAR class as a bit of a albatross around it's neck for a while. It worked well with PHP4, as it had a few useful features, like exception faking (PEAR_Error etc.) and fake destructor's etc.. , but for the most part, newer classes in PEAR do not always require it as much as they used to. Often it's only loaded as needed if an error occurs.

But the overriding conclusion that most PEAR developers have come to is that a Base class is not really a great idea.... - And calling it Object sounds like a really bad idea... (Cake, Cake_Core or Milk might have been better) . but then going to use it as a base class is not really a step in the right direction. Let alone looking at it struggling to find a purpose in life....

Making Objects out of the built-in features - The 'Array, String' classes

You can't imagine the number of times someone has suggested an Array class and String class to the PEAR dev mailing list. It's been shot down due to the basic premise, this is just wrapping native features of PHP with mostly simple and dumb methods..

Even before PHP6 (the unicode version), PHP still features quite a few tools to work with unicode and multi byte character-sets, iconv and mbstring provide pretty much all you need and are far more comprehensive than something that you can put together in a small file. I should know this, I live and work in one of the few countries that use multi byte character sets..

If you really want a good laugh have a look at cake/conf/unicode/casefolding ... looks like someone missed mbstrtolower()..

Lost Classes...

ScaffoldView is a class hidden inside the scaffold class (it is in a file and directory that has no direct, simple relationship to the name of the class)

How would anyone know where to find ScaffoldView?, I can just see the irc chat.
"Where's that ScaffoldView Class"
- oh it's in cake/libs/controller/scaffold.php
-- wow that's obvious isn't it..

- Opps we're repeating a deadly sin there...

Making simple things complex ... Session, Cookie classes

yes, I think we all have had that idea at one point, it goes in the trash when you realize all you are doing is replacing one or two lines with a new API, and a whole lot of redundant code. Forcing maintainers, and users to learn and remember things they dont need to know...

$_SESSION[__CLASS__]['mysetting'] = ......

$_COOKIE['...'] or set_cookie(....);

Who's been reading the Patterns book to much... Model?

It's a nice name for what when you really get down to the meat of things, usually ends up being a object representation of a database table. While not a complete relationship, the benefit's of working this way significantly outweigh the downsides of creating abstract model objects for your project along side having a database mechanism.

That's why just using DataObject database wrapping model is far more efficient in terms of code and readability over abstract modeling (which funnily enough is called DataObjects.) - And I will not dig too deep into the fact that Cake's layer here is just yet another 'not invented here' redo....

PHP's good at some things, It sucks as a template engine (or install your virus here free)

Yes, although Richard quoted me as justification for his crazy idea that PHP makes a great template language, It doesn't It's a crap one. It's sooooooo easy to accidentally write code that can accidentally output unescaped data, and open up your site to so many types of hacking (like finding out what your admin password is!).

That is the whole purpose of Template engines. They should protect you from yourself by default (while allowing you to be explicit when you want to shoot yourself in the foot). Not the other way round. This is where PHP fails. It defaults to outputing raw data, and you have to be explicit if you are escaping! - It's ass backwards....

Thankfully the introduction of ExtJS and Ajax based interfaces have significantly reduced the need for template engines and HTML outputing in general. Although unfortuntaly without a few Security hacks ExtJs author's seem to like security holes just as much.

PHP as a template engine does not scale, If you have more that two or three templates in a project, then you want unescaped output to be easily spotted (so you can do security reviews quickly and frequently) rather than be a matter of sifting through craploads of HTML searching for accidental echos which are missing htmlspecialchars, or data that may have been slipped through your complex plan to escape it before it got there......

Anyone got a good project to nail next?


Mentioned By:
www.dzone.com : CakePHP taking it apart, and the better written world of sinners.. (447 referals)
www.diigo.com : AKBK home - CakePHP taking it apart, and the better written world of sinners.. | Diigo (273 referals)
www.planet-php.net : Planet PHP (259 referals)
it-republik.de : CakePHP in der Mangel || IT-Republik - PHP - News (241 referals)
entwickler.com : CakePHP in der Mangel - entwickler.com (207 referals)
www.diigo.com : AKBK home - CakePHP taking it apart, and the better written world of sinners.. - Annotations | Diigo (155 referals)
groups.google.com : We're under attack - Cake PHP | Google Groups (155 referals)
entwickler.de : CakePHP in der Mangel (118 referals)
www.xing.com : Symfony, CakePHP oder Zend....vielleicht auch PRADO - PHP-Entwicklung | XING (113 referals)
google.com : Cakephp sucks (60 referals)
google.com : march (49 referals)
www.dzone.com : DZone - fresh links for developers (48 referals)
www.xing.com : XING - Groups - All Groups - PHP-Entwicklung - Article thread "Symfony, CakePHP oder Zend....vielleicht auch PRADO" (43 referals)
google.com : cakephp template engine (35 referals)
groups.google.co.uk : We're under attack - Cake PHP | Google Groups (34 referals)
www.spatiallink.org : spatiallink_org:: Linking Spatial Professionals and Volunteers Through Search, Profile, News, Blog, Forum, Map, Chat, WIKI, WAP (33 referals)
google.com : cakephp (27 referals)
google.com : orm sucks (27 referals)
google.com : cakephp orm (24 referals)
feeds.feedburner.com : Planet D (24 referals)

Comments

Ouch!
Quite a beatup; but probably well deserved.

I don't suppose you want to do the same to PEAR itself, do you?

That way we can file design bugs and fix 'em where needed.

We just had a Bug Triage Day, and we're looking for firm directions for the next one, I think.

#0 - Daniel O'Connor ( Link) on 2008-03-26 10:19:40 Delete Comment
Hmm...
I'm in agreement with most of what you said. Lost classes always annoy me: I shouldn't have to break out grep to find a class declaration.

As for "Making simple things complex", these sorts of wrappers do help out when they end up needing to modify the behavior of cookies or sessions slightly; having everything centralized is very nice. It might be over-engineering, but it can be useful.

"Anyone got a good project to nail next?" Those are fighting words, Alan! I'm tempted to volunteer my own, HTML Purifier, but it's not a CMS. :-) (Still, if you could take a look, I'd be much obliged!)
#1 - Edward Z. Yang ( Link) on 2008-03-26 11:41:25 Delete Comment
Me-ouchhhh ;)
Hey what do you expect when you're trying to COPY Rails.

My personal opinion is that ORM sucks. SQL is a standard, so why not use it. Why rely on generated SQL that may not be optimized.

Cake does minimize development but you spend so many wasted cycles digging thru the code because the "docs" are truly lacking. But to be fair a lot of PEAR stuff also lacks docs.

Version 1.2 has taken so long to release - no idea how long it's been in development. Each framework has it's disadvantages.

Anyway, I suggest that you take the nail to Symfony and then Zend ;)
#2 - Manny ( Link) on 2008-03-26 13:50:57 Delete Comment
Part of the learning curve
Having developed a number of CMS solutions in the past I definitely see a few holes in CakePHP that I (and probably everyone here) have fallen into, however I think this is all part of a steep (sometimes slippery and oft repetitive) learning curve.

I think your article is well warranted and although not a developer on the project, some constructive criticism would have been helpful for the actual developers.

So before nailing the next project, any suggestions for what direction this one should take?
#3 - Harry Birrell ( Link) on 2008-03-26 15:21:07 Delete Comment
MidCOM 3?
Hi, Alan!

I'd actually be delighted if you took the time to pick apart MidCOM 3, especially since we're still in such an early stage where things can be fixed. We're trying hard now to fix the main problems in earlier MidCOM versions...

http://repo.or.cz/w/midcom.git
http://bergie.iki.fi/blog/midcom_3_at_a_glance.html
#4 - Henri Bergius ( Link) on 2008-03-26 15:21:15 Delete Comment
CSS leaking into feed
For some reason some of your CSS is leaking into the feed, which is quite bad...
#5 - Anders ( Link) on 2008-03-26 16:02:14 Delete Comment
ORM
@Manny: ORM not suck, is very useful and comfortable
#6 - sf ( Link) on 2008-03-26 16:03:12 Delete Comment
take aim...
This NIH syndrome ("Not Invented Here") seems contagious - from what I can tell, it's infected the CodeIgniter project as well.

I shudder to think of the number of projects that have reimplemented code, such as validation classes, rather than using established ones and feeding any bug fixes upstream.

With this in mind, I'll echo Daniel's invitation that you take a look at PEAR next.

#7 - Ken Guest ( Link) on 2008-03-26 18:01:07 Delete Comment
Fully agree with you
I could not agree more, and especially the comment on the "Not Invented Here"-syndrome, it's widespread in the php community is just disastrous.

How about taking a look at Symfony, Zend Framework or Code Igniter (the three "large" other then Cake) ? Any of them would make a fitting case to compare against Cake.
#8 - Fredrik Holmstrm ( Link) on 2008-03-26 19:09:14 Delete Comment
Dig around in symfony
Dig around in symfony. That would be my pick.

I am so guilty of NIH that I shouldn't be allowed to comment, but honestly its hard to avoid, a lot of pieces of things that should be reusable lack conceptual integrity with the rest of a project and just beg to be rewritten, even if they strictly don't require it.

Doug
#9 - Doug ( Link) on 2008-03-26 20:24:55 Delete Comment
Me?
> Yes, although Richard quoted me

Me? I don't remember that. But then, I don't remember a lot these days...
#10 - Richard Heyes ( Link) on 2008-03-26 21:05:41 Delete Comment
C'mon... seriously?
Are you really that stupid, or are you just pretending to be that stupid for the folks at Nielsen?

(1) "My base class is better than yours .... the Object class" - right, because typecasting is relegated to only those elite who've been bred from C hackers. Get real.

(2) "Making Objects out of the built-in features - The 'Array, String' classes" - Right, because native PHP functions will generate UUIDs and let you extract data from arrays using XPath. For God's sake, pay attention next time. You'll make yourself look like slightly less of an ass.

(3) "Lost Classes..." - For the love of all things non-retarded, it's not a user-land class you moron. Show me one code example anywhere that demonstrates directly accessing the ScaffoldView class. I defy you.

Honestly, do I need to go on?

I'm all for constructive criticism, but try to give me something *not useless*.
#11 - nate ( Link) on 2008-03-26 23:31:21 Delete Comment
ORM 2
@sf,

IMHO, you write more code then there is SQL.

Also, we use a ton of stored procedures! I've never understood how stored proc's fit into ORM theory. Willing to learn though!

Maybe I'm a little jaded because we don't have to support a whack of databases.
#12 - Manny ( Link) on 2008-03-27 02:20:28 Delete Comment
ORM 3
@Manny: even if more code it's no matter

stored procedures have nothing with ORM so I do not understand your problem too ;)

ORM is cool beacuse your code is more comfortable, not faster, not smaller, using php not sql

1.5 years ago my code was clear sql ;) now is only DAO / ORM

sorry for my english
#13 - sf ( Link) on 2008-03-27 16:14:08 Delete Comment
View escaping
I completely agree on one highlighted point - defaulting to raw output in a PHP-only template is quite possibly the stupidest thing imaginable - it suddenly adds a completely unnecessary responsibility to the template writer which could easily have been removed using some light filtering on incoming data in the first place. Sure your objects in views might now be harder - but the security risk is a hell of a lot lower.
#14 - Pdraic Brady ( Link) on 2008-03-27 17:01:41 Delete Comment
Take a peek at Drupal 6.x
Drupal 6.1 might have too large a scope, but I would be interested, as a Drupal user, to see critiques of Drupal as a framework.
#15 - Samir M. Nassar ( Link) on 2008-03-28 07:06:06 Delete Comment
conference ideas
Very refreshing read Alan, please keep this series up. Judging by the audience participation and heckling experienced during the Framework Shootout talk at the recent PHP London conference I think this (the sober evaluation of "leading" PHP frameworks) would make a great basis for a future conference topic.
#16 - Demian Turner ( Link) on 2008-03-28 17:24:15 Delete Comment
Well...
I'm a long-time Cake user, and although I can't speak for the dev team, I think the re-implementation of things that have already been done in PEAR, etc is for a good reason.

That reason being the vast disparity between various PEAR libraries. Yes, you have coding standards, but the fact that there's so many different authors working on code means that there's more than one way to skin a cat. By having all the code developed by a small team, you ensure consistency. And that is the main advantage.

Secondary to this advantage is that of licensing. Cake uses the MIT license which I believe is a far better choice than GPL, or even LGPL - purely because it's so much less toxic (watch out, I'm about to get flamed).

I think the core problem here is that you disagree with the very concept of a framework. In my case, and that of many others, Cake has drastically sped up the process of developing websites.
#17 - Stephen Orr ( Link) on 2008-03-29 00:48:28 Delete Comment
Good Project to nail next?
There's always the "talk less, code more" response to a non-constructive criticism like the one exposed here... If you want a Good Project to "nail" on PHP, you're just wasting your time... Try reading Perl's DBIx::Class and/or Catalyst, and compare them with your own PHP code and documentation (surely there's not much of it)... But hey, you can always shoot your own foot and use whatever you want.

P.D. The checkboxes on the comment submission form are just hilarious... (This is not working yet)... 'Nuff said!
#18 - Johnny Walls ( Link) on 2008-03-29 01:30:14 Delete Comment
Something is seriously going wrong here
Yo folks, yo Alan.

I must admit this is one of the worst articles I have ever seen written on PHP yet. Yes I am from the Cake camp. No, my opinion is not biased because of that. Let me explain.

"Great way to confuse programmers who do not know PHP inside out..."

--> Do you think you are supposed to do anything like "$something = new Object()" in CakePHP? No it is used for internal logging, error related stuff, attaches a "toString()" method (which outsputs the class name) to all cake objects, and is used for caching objects (by writing them serialized to a file).

It is not at all intended to be used by programmer peeps, so wtf are you talking about?



"Making Objects out of the built-in features - The 'Array, String' classes"

Yes I agree one should not compromise the language's features. However, ever heard of separation from interface and implementation?

Also, what does this paragraph of your article have to do with Cake?

"If you really want a good laugh have a look at cake/conf/unicode/casefolding ... looks like someone missed mbstrtolower().." Constructive criticism anyone?

"ScaffoldView is a class hidden inside the scaffold class (it is in a file and directory that has no direct, simple relationship to the name of the class)"

Judging from the depth of your knowledge I assume you haven't looked much into the code and just got this from the API pages. Yes I agree it should probably not be there, because it isn't intended to be used by peeps. However if you actually looked at the api pages you would have seen http://api.cakephp.org/1.2/class_scaffold_view.html. See the line + file info there?



"Making simple things complex ... Session, Cookie classes"

Wtf? What about checking of a key in the session exists, in order to prevent notices from popping up? Do you always want to do an isset() in front of $_SESSION['someKey'], or rather use $this->Session->read('someKey'), which return false if it is not set? Also with an API you can extend it if needed with your own functionality. How do you do that with your $_SESSION and $_COOKIE approach? Wrapping it all into functions and then ending up with an army of functions so that your code seems more procedural than anything else? How about most of the commenters here can agree with such stupidity?


"Who's been reading the Patterns book to much... Model?"
"..While not a complete relationship, the benefit's of working this way significantly outweigh the downsides of creating abstract model objects for your project along side having a database mechanism."

Did you even bother to look at Cake's Model class with all the relationships?

"And I will not dig too deep into the fact that Cake's layer here is just yet another 'not invented here' redo...."
Whut? Why redo it if someone else found a very good solution? Use it, extend it and the broadcast it as OPEN-SOURCE.. You are kidding us.


"PHP's good at some things, It sucks as a template engine (or install your virus here free)"

You don't even mention Cake here..


Conclusion: The comments on this article just make me sad. You guys should open your eyes and really read what Allan is writing.

@Alan: If this article was intended to be controversial to drive traffic to your site: Great job, well done. If not, you should stop writing anything now.
#19 - DarkAngelBGE ( Link) on 2008-03-29 20:44:20 Delete Comment
Prado? Joomla?
What are your thoughts on Prado or Joomla's "framework"?
#20 - Anthon ( Link) on 2008-03-30 09:44:13 Delete Comment
Why?
@Anthon: why do you care to know the opinion of someone who's ignorance (and bias, for that matter) is so painfully obvious?
#21 - nate ( Link) on 2008-03-30 11:39:37 Delete Comment
Not Quite on the Mark
I dunno, after reading some of your other posts and this, I must say you love to pick on a few things and act as if they mean the whole project is pointless.

I like the idea of your posts, in that you are being critical of existing PHP projects, I just think you need to be a little more thorough in your investigation and a little less quick to write off different approaches.

DarkAngelBGE did a pretty good job of refuting most of your points and making it fairly obvious you haven't really used Cake for anything. It seems more like you glanced over the code and site before writing this post. It is possible I am completely wrong on this account, but that is sure how it seems.

I guess your post also explains why there are so many different PHP frameworks/libraries. With such a diverse group of people using PHP (from noobs to experienced software engineers) using PHP for so many different tasks (from contact forms to web apps and intranets), there are bound to be lots of different approaches and things to focus on.

After seeing lots of discussions like this on the web (for lots of different software topics), I've been sure to spend some time writing rationale and motivations behind adding my own PHP library to the fray. This way hopefully no one will ever come to the site and say, "why the heck did someone make _another_ PHP library with so many out there?"
#22 - Will ( Link) on 2008-03-30 12:18:33 Delete Comment
Rok on, yo. Is that the School Bell?
Alan, are you taking everyone back to school?

whoa! yours is definitely the most entertaining, and educational site i've discovered lately.

i find it amusing (no, that's the wrong word... sad? alarming? hmm...) that so much of the feedback here is on the offensive. that so many are not humble enough to learn from your illustrations.

(re: Neilson comment -- What is the point of /that/ reference? i mean-- if you're comparing dude to Neilson, then-- WTF? its like you know what's going on, then turn around and ask, "what's going on?")

I'm glad i'll have something, perhaps, interesting to read this week.

Cheers. suds
:-)
#23 - IsleOfBigNipz ( Link) on 2008-03-30 17:39:42 Delete Comment
Nielsen
@IsleOfBigNipz: I guess my references are a little too esoteric for you. Let me spell it out. Firstly, if you go back and look at my original comment, you'll see I referenced "the boys at Nielsen" as the reasoning for writing this post.

As http://en.wikipedia.org/wiki/Nielsen_Ratings tells us, Nielsen Media Research is responsible for the measurements of television viewership, aka "ratings".

Put another way, one could say that Alan wrote a controversial post for the "ratings," i.e., the traffic. When it comes to writing diatribe of this nature, only two motivations come to mind: either you want to attract attention by starting a fight (or trying to), or you have an axe to grind.

In Alan's case, I think both probably apply. This post has clearly generated some traffic, and as the principle author of DB_DataObject, he has a vested interest in promoting his solution, even though DBDO couldn't stand up to Cake's ORM if it were duct taped to a tree.
#24 - nate ( Link) on 2008-03-31 11:09:36 Delete Comment
Where's the love?
Why must we all be so condescending? Can't we just give our opinion without being asses about it?

A base class called Object scares me a bit. But it's not a huge deal - it wouldn't be too hard to change it something else in the future if name were to get used internally by PHP.
#25 - Joel ( Link) on 2008-07-17 17:39:10 Delete Comment
Sometimes, OOP is best done meticulously
Wrapper classes for GPC might seem to be over-engineering at first, yet it is proper OOP, while global variables are not. Just think of "action at a distance": anyone in the team can write to GPC as he sees fit, whereever he wants, and in case of $_SESSION without even checking whether a SESSION actually exists.

Same goes for wrapper classes around existing PHP functions. PHP functions usually don't throw exceptions and in some case accept whatever you feed them, whether it makes sense or not. Wrapper functions allow you to better follow the principles of OOP in general, having your exception handling in place instead of just getting PHPs Warnings.
#26 - Claus-Christoph Kthe ( Link) on 2008-08-30 06:55:34 Delete Comment

Add Your Comment

Follow us on