CakePHP 2.0 Rant

C

I was recently visiting the CakePHP bakery and decided to read a little bit about CakePHP 2.0-dev.  I’ve rather enjoyed CakePHP as a framework since version 1.1 all the way through to version 1.3.  However, after reading some of the “features” for version 2, I have to say, I’m a little disappointed about their focus.

In the bakery, there are 6 core features listed that they deem worth mentioning.  The two that stand out to me the most are:

– Lazy loading model associations – Associated models are loaded on-demand greatly improving the memory use and performance of larger applications.

– Lazy loading of Helpers and Components – Helpers and components are loaded/constructed as needed helping performance.

Lazy loading, like most people, you are probably thinking, “oh wow, what a great way to improve speed!”.  Well, no offense, if you’re thinking this way, you are the one that’s lazy!  Sorry for the shot.  But if you really think about it, if your application is developed correctly in the first place you shouldn’t rely on the framework implementing features like lazy loading, your application should be setup in a way that it is only retrieving the data that it needs and most importantly, when it needs it.

I can see it now, all of our models relationships will have recursive set to 2 because CakePHP will only fetch the data when I need it.  This will make development so much easier!  Well, yes, I agree that development times might speed up, but unfortunately, speed of development isn’t the only thing we can care about.  At some point, hours and hours of time needs to be dedicate solely to ensuring OUR (not the framework’s code) is as optimized as it can be.  If we don’t, no matter how optimized CakePHP tries to be, your code will never be.

Ok, I’m done ranting, I just don’t like it when developers are taking the lazy way out!

About the author

  • Jose Lorenzo

    I think you are misunderstanding what the lazy loading means. It has nothing to do with database queries of data fetching.

    In previous versions of CakePHP all model associations where constructed, loaded and linked to each other for each request, even if you don’t queried the database at all. in other words in a blog application, the Post model would need to find the Author model file, construct the class, initialize the internal variables, check the existence of the table on the database and other stuff, and if Author is relate to another model it would have to the the same exact thing for it.

    So, as you may have already thought, if you have a application with 100 models linked to each other, you would need to do this process for all of them, even if you only are going to query a couple of those. That’s not very good for performance.

    In CakePHP 2.0, this was changed to be transparent, you can link models to each other as you did on the past, but it is not a performance hit anymore. It has nothing to do with database queries, just with php objects.

    I hope this clarifies a bit your understanding of what we have been doing for the next version of the framework.

    Cheers

  • Pingback: Tweets that mention CakePHP 2.0 Rant | End Your If -- Topsy.com

  • Jamie

    Yeah, what Jose said. You can almost think of lazy loading as autoloading (i.e. with the __autoload() magic method): Cake will only load models, helpers, and components as it needs them. You’ll still be constructing your queries in the same way.

  • Abbas Ali

    Jose is correct. Lazy loading will prevent the unnecessary class initializations rather than preventing the unnecessary database queries.

    To make your “find” calls more efficient we already have “Containable” behavior with us and a good cakephp developer should already be using that.

    Cheers

  • Pingback: skin tags

  • Pingback: gardening recipe

  • Pingback: secrets 4 loss weight

  • Pingback: gold secrets guide

  • Pingback: online PC repair

  • Pingback: Goozle Zone

  • Pingback: Ania Antonette Quisumbing

  • Pingback: bad credit loans

  • Pingback: long sleeve guayabera

  • Pingback: online song downloads

  • Pingback: www.onebuckresume.com

  • Pingback: ultimate power profits

  • Pingback: zig zaga

  • Pingback: Personal Injury Solicitors in Manchester

  • Pingback: Motorbike Accident Claim Solicitors

  • Pingback: ZigZag

  • Pingback: ZCode System

  • Pingback: new york asian escorts

  • Pingback: Blog

By Jamie

My Books