views:

716

answers:

12

This isn't a question about what framework to use. I've learned both Rails and Django, and I write all of my webapps in PHP. My question is why bother with the frameworks? It's always taken me longer to use a framework than to reuse old MySQL code and build "models" with phpMyAdmin. I also like writing everything myself, because I know what's going on. I can still reuse functions, etc. and do things how I want, and this freedom seems to be missing from most frameworks.

I'm not saying that my way is right; in fact, I'm trying to figure out where my logic fails. The hype can't be just thin air. What am I missing?

+20  A: 

Frameworks allow you to concentrate on the application itself rather than worrying about the boilerplate code that you'd otherwise have to write for every application. They allow you to structure you site in a much more logical (mostly object-oriented) way, using tried and tested design patters such as model-view-controller. The code in framework is generally more mature and of a higher standard than code you would write yourself for one-off projects as framework have a large community of developers perfecting the code perfecting the code over year. This means that framework-driven sites often perform better and are much more secure.

You also mentioned you like writing things yourself - I know where you're coming from. My solution to this was to write my own framework - I get to reuse and improve my code with every project I do and I know the entire codebase inside out.

HarryM
+3  A: 

I think a big part of it is what you focus on. Frameworks standardize the parts that you shouldn't have to keep revisiting, which helps you focus on the application as a whole. If you reuse your own code all the time you're already using your own makeshift framework.

Jarrod
That's true, but frameworks attempt to completely restructure how a web app works. That's the part that takes too long for me. For reusable functions, I one could just use something like the "Simple PHP Framework" which is effectively just a library.
ankur
I second that. SPF does not get in your way. Its libs provide functions to simplify boilerplate code, like authentication and session management, without forcing any design pattern on you.
Jeff Ober
That's all a framework is, really. Just a bunch of pre-written code and design patterns. Chances are you're already following your own design patterns.
Jarrod
Not all frameworks force a structure on your project, but those that do can save you the most work, if you work with rather than against them. Trying to retrofit an existing project into the structure required by a framework would be painful and a waste of time, though.
Michael Borgwardt
A: 

I think a good step for you is to create your own framework with the code you've programmed so far. ;)

Try to make your code parametrizeable, in other words: create components which you can reuse in different parts of a website (for instance: styled containers), or in different websites (form generators/validators).

You can even go further and create base-classes from which you extend new classes to build your websites. (for instance: data objects with generic select/insert/update/delete methods).

I bet this gives you the best view on why frameworks are so damn handy ;)

Ropstah
A: 

Frameworks are there mainly to help people who are semi-new to PHP (or the specific language it is built on) to be able to build a website to an extent that it is secure and easy enough to add on extra parts to the site without having to know a lot about the specifics like security, MySQL (or other database types). In my opinion it is a fairly good way to help break coders into a language, allowing for the fact that the framework isn't too complex of course.

EDIT The reason behind me saying they are for beginners is because myself, as a beginner has used frameworks to break myself into languages a lot better.

Marc Towler
I'd -1 this if I had any votes left - the idea that frameworks are for newbies is absolute nonsense. In fact, it's the most experienced developers who are most likely to have learned enough humility to stop wanting to reinvent the wheel.
Michael Borgwardt
+3  A: 

Your comparing a framework (Rails) to a language (PHP). A framework is going to give you pre-built components so you can spend time on what makes your project unique.

You may already have a code base that helps do this for you. Check out some of the PHP frameworks since that's where you are more comfortable. Take a look at CakePHP, CodeIgnitor and/or Zend Framework.

If you are building many small apps/sites, using a framework may make your life easier.

Chris Bartow
+5  A: 

Writing it your self may make it easier for you to understand things your self but unfortunately it can make it much harder for other developers to understand what is happening. Frameworks will often be better documented and have a larger community that can support a new developer that is working on the app that you wrote.

Graham Ambrose
I can't stress this enough. You can look at *ANY* Rails application and start working on it without spending time trying to figure out what "bob's custom php framework" does.
Brian Hogan
+1  A: 

It'll take you longer to initially use a framework for the same reasons a PHP developer would take longer to initially use Ruby - you're not familiar with it.

Once you're familiar with them, frameworks can offer the ability to skip the mundane and focus on actually writing the important parts of the app.

ceejayoz
A: 

Sounds to me like you have already written your own framework in php, since you do mention code reuse.

I can imagine it being easier to use your own set of wheels instead of adapting to someone else's. No shame in that.

Kris
+14  A: 

The basic idea of a framework is to allow you to work at a higher level of abstruction and write only the code you have to write to implement your specific requirements. All the other repetitive stuff is handled for you by the framework, and probably with far fewer bugs and security holes than if you did it yourself.

It may feel like it takes longer to learn a framework than to just do it yourself using basic language features and standard APIs, but it's simply not true - not if the framework is good and the app is non-trivial, and especially not once you have learned the framework (using a different one for each new project would of course be idiotic) and factor in the time it would take to find and eliminate all the bugs and correct all the design mistakes that have long since been found, eliminated and corrected in the framework by its developer community.

Almost every developer has cowboy coder instincts that tell him "Doing things yourself is much more fun than using code others have written, and I'm sure I'm good enough to get it right the first time, so it will even be faster and better!". These instincts are almost always wrong.

Michael Borgwardt
"These instincts are almost always wrong." I wish I could vote this answer up twice. I fall into this trap way too often!
A. Levy
A: 

You should also just use a PHP based framework like Symfony or CakePHP using them should reduce your production time considerably.

One reason to use a frame work is code separation. Take symfony for example. The model is all done with propel or doctrine libraries. Very little SQL needed. You instantiate a new object and user getters and setters, to store your data, and instead of writing SQL in your page code you create functions in the objects related to the query. When you need to access the same kind of data on different pages you are asking the model for it, keeping the business logic with the model where it should be, so there's never any difference. All the work is done in the "action controller function". You get all the data you need, and then put as little php in the display, basically just echoing the variables you got in the action controller, (with the exception of some for loops and if statements for conditionals. I have found this a more efficient way to code, and on my 2nd project saw the production time cut in half.

You don't need to learn a new language python/ruby just to use a great framework, just have to fin one that works for you.

A: 

First, PHP has frameworks too, so the question as stated misses the point.

Yes, you can write your own framework, and as Kris said, there's no shame in that. However, part of the leverage of code reuse is the collective value of the efforts of many. It's not just about reusing your own code. Frameworks encapsulate the common tasks and patterns we all share and provide well tested solutions with many iterations of improvements from the community. No individual effort is going to measure up to that, no matter who you are.

If you roll your own, it will only become world class due to the collective effort of world class people, and that will only happen if your idea merits the attention. The top frameworks out there are already proven on those criteria.

DHH is a smart guy, but the Rails we have today never could have been realized by him alone. Not even close.

If you like "writing everything yourself" as you say, then choose a framework with a core philosophy that matches yours, and start making core contributions in the areas where you can see room for improvement.

Walt Gordon Jones
A: 

Depending on the functions of your Web Application, it can be faster to develop without a framework. For example when the Webapp is just some kind of data viewer.

But as soon as you begin to implement more advanced functions, you are much more efficient with a framework.

Try do do this from scratch: - proper Form validation - Handling of multiple Language and Date/Time formatting - Authentication

See a framework as free tools and stable implemented function for you to use.

Andre Bossard