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:

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:

   - 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.


Nephtali:  PHP web framework that functions beautifully

Reply via email to