> -----Original Message----- > From: Adam Richardson [mailto:simpleshot@xxxxxxxxx] > Sent: Friday, December 10, 2010 12:05 AM > To: PHP-General > Subject: A general discussion of libraries and frameworks > > I see that the ORM thread has generated a broad-ranging discussion. Some > of the posts have discussed the utility of frameworks and/or libraries, and > because it's Friday, I thought I'd toss out my observations on the subject and > see what ideas those on the list had regarding the subject. > > Libraries and frameworks both offer the general hope that their carefully > crafted and maintained code is better than my one-off stab at the problem > will be within the timeframe I have to complete the project. However, I > tend to make a distinction between frameworks and libraries. Simply, > frameworks control the flow of the application, whereas libraries provide > functionality that fits into your applications flow. > > On the homepage, Doctrine says it's a library, and that seems to fit with the > above distinction given my limited knowledge of the code. JQuery is a > javascript library, and, although Zend is called a framework, I tend to use it > as a library (SMTP email, etc.) to augment my own code, although it can > certainly be used as a framework. CakePHP, Ruby on Rails, and Code Igniter > are all frameworks because they control the flow of the app. > > Martin Fowler has a nice blog post which speaks more clearly on the > distinction I tend to draw: > http://martinfowler.com/bliki/InversionOfControl.html > > As one point of curiosity, I'm wondering when a function or group of > functions is, in your eyes, deemed a library. I tend to use the pornography > approach to identifying a library ("I know it when I see it"), but I'm sure > there's a more formal analysis. For some, maybe it's as simple as "The > developer calls this a library." :) > > <http://martinfowler.com/bliki/InversionOfControl.html>Moving on, this > distinction between frameworks and libraries helps inform my choice of > tools. If there is a simple task that I'm going to perform and I know that > many before me have been faced with the same hurdle, I'll look for a > function. However, if there are a set of related tasks I'm going to perform, > I'll look for a library. If none is suitable/findable/trustable, then I'll see > what I can muster. > > I use frameworks when there is a particular flow I wish to enforce > throughout the application. For instance, my web framework enforces a > general flow during all requests: Adam, I find that 'enforce' leads to inflexibility eventually. As for framework, I'm still looking for a good implementation of the presented concept (MVC, ORM, etc.). Case in point: MVC. You could just add or do some minor change in either/all the Model, View, or Controller, having that flexibility to adapt w/o major base code change is very nice. The problem lies therein of implementing the abstract concept MVC into concrete, workable (learning, understanding, maintaining, etc.), reliable, and flexible (modular, 3rd party add-ins, etc.) code while retaining good performance. IE: Zend Framework. The code base is somewhat bloated, IMO. But as others have mentioned, it's still useful due to its modular design as you can choose to use parts of it within your app and not need to implement the entire framework. I don't have enough experience with ZF yet to see how expandability it is in terms of third party add-in/plugin/module. Here's the list of PHP frameworks [1]. I don't know how current it is. As you can see from that table, only 2 supports everything that's current under the sun, including template & event driven. Yii isn't very mature from what I've read so far. PRADO's, although acronym is both catchy and meaningful, code base is too much ASP.NET like even though it's based on PHP >.>. Ironically, both projects are started by the same person. Regards, Tommy [1] http://www.phpframeworks.com/ > > - Input validation on all incoming Get, Post, or Cookie variables, and > delete any not expected or accounted for. > - Short-circuiting of the request if the client only wants an html > fragment (one dynamic region of the page instead of the whole page, as is > used to update pages via Ajax.) > - Automatic output escaping, automatically adjusting for context. > > Now, I could use libraries to get the same effect, certainly. However, I > prefer that this flow occur on every dynamic page, and a framework allows > me to easily achieve and enforce this flow. Are these the same reasons > some of you use frameworks? > > I'm also curious if some of the custom "libraries" people have built fall into > the category of framework using the definitions above. C'mon, you can 'fess > up, there aren't that many people listening :) > > Last, I want to be clear and say that I'm not saying you should always use a > framework or library. Especially with frameworks, you have to be judicious > in your decision, as the same control of flow that can prove so helpful can > also wreak havoc when it takes you and your developers out of their > standard flow, and can make simple task into complex riddles Solomon > couldn't solve. > > It's nice that those on this list do such a solid job of arguing whether to use > frameworks or libraries or custom code, as this will better inform those who > are new to programming and/or PHP. > > Adam > > -- > Nephtali: PHP web framework that functions beautifully > http://nephtaliproject.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php