« Exceptional PHP: Introduction to Exceptions | Adapting The Joel Test To Web Development » |
Lots of people have the itch to write their own frameworks. They think that they can do better than Zend, Cake, Symfony, or application-level frameworks like Drupal. They’re convinced that those designers and developers made fatal flaws, and they can improve upon them. They’re just itching to give it a shot.
So for those of you wanting to write your own frameworks, feel free. But don’t even think about putting it in production until you’ve read this blog post.
Lots of times new developers are shot down from writing their own frameworks by bosses or community members who insist that “NIH” (not invented here) has no place in their organization or language. They’re told that the existing frameworks are the “gold standard” and that they should take the time to learn those, instead of toying with their own.
To me, that doesn’t make a whole lot of sense. When comp sci students are attending school, they (hopefully) learn C, even though that there are higher level languages that do many of the low-level functions of C automatically. Why do they do that? Because they need to learn the basics.
Elizabeth Smith says basically the same thing about frameworks in a tweet, when she said “I think every PHP developer should write a framework – not necessarily to use but to LEARN from, it’s amazing how many don’t know basics.” This drives home a very important point: writing your own framework is a fabulous learning experience.
Writing your own framework will force you to make architecture choices that will in turn make it easier to see the wisdom (or lack thereof) in other frameworks. It also forces you to make decisions that you might otherwise have thought you could avoid: architectural decisions, coding decisions, lack-of-time decisions. Suddenly, the other frameworks don’t seem so kludgy and awkward.
Programmers should be wary of putting their frameworks into production, but should be willing and able to write one if the situation calls for it. The tried, true and tested frameworks that are out there are more than sufficient to meet most needs, and anyone who writes a framework will quickly learn that the decisions of the framework authors are common solutions to difficult problems, and should not be taken lightly.
So feel free to write your own framework and learn from the experience. I know I have – I called mine Modus.
Brandon Savage is the author of Mastering Object Oriented PHP and Practical Design Patterns in PHP
Posted on 11/6/2009 at 1:00 am
Abhinav Singh (@imoracle) wrote at 11/6/2009 1:11 am:
If one is an experienced PHP developer, i guess with time he himself develops his own framework which is basically a collection of thing from his experience put into a single folder.
However Elizabeth’s tweet is right in saying that very few people actually know how to write a PHP framework.
Sudheer (@bngsudheer) wrote at 11/6/2009 1:30 am:
Right on. Using frameworks makes a lot of sense for companies and developers having experience. Beginners often spend anywhere between 3 to 6 months to learn a framework or content management system. This happens mainly because lack of understanding and experience in
* software architectures these frameworks and content management systems use
* object oriented programming and design patterns
* depth of features offered by programming language
* team work
* security issues
* standards compliance
* testing
* and moreLike you said, if you roll your own framework from scratch, you will understand what it takes to promote an application to production. Every beginner should at least try to write a production quality framework and application from scratch. This is one of best approaches to learn programming.
Miles Johnson (@gearvosh) wrote at 11/6/2009 2:00 am:
I started my own framework, mainly for all the points you listed above. I wanted to try certain ideas I haven’t seen in any framework before, or improve on other ideas.
Im interested in seeing yours :]
tg2345 wrote at 11/6/2009 2:09 am:
Yea, thinking about this now I learned some php and then went straight to cake. After I finish my projects this seems like a great idea to really learn how PHP really works. As well there is so much new with PHP 5.3 it should be fun learning such great new things.
Gyorgy (@feketegy) wrote at 11/6/2009 4:47 am:
I miss does days when frameworks didn’t existed.
Sure, frameworks are great, but I’m too seeing a lot of newbies who just learn a framework without knowing the basic concepts of programming and OOP.
Even if you’re using a framework, only a “true” developer can modify it to suit their clients’ needs.
steve (@steveify) wrote at 11/6/2009 5:54 am:
I’ve written my own framework. Not because I thought I could do better than anyone else, but because I thought I could be lighter and simpler than everyone else.
I’ve only recently got into PHP after years of Java, Delphi and C++. I looked at the frameworks available and tried some out. I really liked Code Igniter. Problem was, as great as the documentation is for most of them I was always left with a bunch of questions about how to do stuff. As soon as I wanted to do something a little bit different I quickly got lost and ended up looking in the source or Googling. My thinking was that if I built a framework myself from the ground up then I’m never gonna get lost.
No way is my framework anywhere near as good as CI, Cake or the others. But it is light and fast and it has been a great learning experience and has really helped me get into PHP in a big way.
It’s in production too!
Crazy norwegian wrote at 11/6/2009 6:48 am:
Even though this topic is very true (learning is everything), I guess there is a lot of newbies actually start learning OOP, MVC patterns and different programming concepts because of the introduction of a framework.
Also developers can keep on learning, without writing a framework for him/herself from scratch. A framework isnt perfect, it has to be further developed.. and here is a good opportunity to get a very good understanding on architecture, security issues, team work etc.
Education come in many different forms. As long as people are willing to learn, there is no problem.. but there will always exist lazy “developers” who just want the fastest solution for ripping money from a customer.
Have a nice weekend!
Matthew Turland (@elazar) wrote at 11/6/2009 8:15 am:
Two good things about using existing frameworks that I don’t think were mentioned here:
1) Finding developers who already know the framework. If you write your own, unless you release it as OSS and it gains a substantial amount of traction in the community, you’re going to have trouble finding new developers who are fairly familiar with it as compared to ZF, CI, Cake, or symfony. Granted, any good developer should be able to learn the ins and outs of a framework, but it’s significantly easier to bring someone in who already knows the framework used by your shop and have them hit the ground running than to have to take the time to teach them how yours works.
2) Larger frameworks have many contributors working on them everyday. Rolling your own framework and using it internally means maintenance is entirely your responsibility, along with whatever projects that are built on that framework.
Les wrote at 11/6/2009 8:29 am:
I wouldn’t say few people are required to develop their own framework, but fewer people are required to do so and this really is the issue.
I’m an advocate of developing your own framework (I have done so myself) because it actually does force you to learn and develop skills that stand you in good sted later.
You are forced to think for yourself, stand on your own two feet and just get on with it – you not only learn new skills but you learn how to and develop better approaches to problem solving – by your self without any help from people on a forum or your colleage next to you.
It really is so important but sadly fewer people do this [develop their own framework] because a) they have pre fabricated frameworks already available (why bother?), b) they are just too lazy and/or stupid to even attemp such a task or c) other reasons, such as their employer.
I would say though that freelancers are better positioned to develop their own framework rather than those employeed and may I suggest that it is freelancers (ie me) that are more prone to push their own personal levels of acheivement?
It’s an imperfect world however :(
Jakefolio (@jakefolio) wrote at 11/6/2009 9:17 am:
Brandon do you plan on blogging about the decisions you made and what “components” were required to accomplish your framework?
Jamie (@JamieHolly) wrote at 11/6/2009 9:17 am:
I actually use my own “framework” for clients who I can’t convince to go with OSS solutions. It’s the accumulation of about 5 years of work, which started with my own database layer. Over time I kept adding to it (form generation/validation, theme layer, cache handling, user management, etc.) and use it in some larger production sites.
I do have to say it was a learning experience, but also a very valuable one. After years of PHP development I have learned that you keep learning. Developing your own framework is a great avenue for this (and if you stop learning then something is wrong). Of course using it in production must always be evaluated closely.
When I do go the OSS route I generally use Drupal as a framework. The reason is so many clients know everything they want when you start working, but after a couple of months they want new features and they want them fast. With Drupal I can generally find a module to fit their need, and if not I can develop one so rapidly that it makes the client happy in the end.
Matthew Weier O'Phinney (@mwop) wrote at 11/6/2009 10:12 am:
I think the popular quote is that every PHP developer writes 2.5 frameworks in their career. The first is a good learning experience, and typically fails due to bad decisions. The second is usually much better, but still is not fully comprehensive. The .5 comes in when they start contributing to an existing framework, because they realize they don’t have the time or knowledge to write all facets of their own framework themselves, and that their time is better spent improving existing code.
Really good developers will only do .5 or 1.5 frameworks. ;)
Chris (@chrisvoo) wrote at 11/6/2009 10:30 am:
Writing a PHP Framework it’s not an easy task and it requires a lot of time and experience.
My approach for now is to do by myself all the things that requires an immediate solution, for the rest I prefer to extend an existing framework instead of reinventing the wheel.
Keith Casey (@CaseySoftware) wrote at 11/6/2009 11:03 am:
I think a developer can learn many of the same things by picking up a framework – especially a lesser-known one – and refactor it. You can explore other peoples’ implementations and design tradeoffs and as long as you can identify weaknesses, you can figure out how to make things better.
Of course, maybe that was the Supreme Allied Commander’s point with 0.5 frameworks… ;)
Brandon Savage (@brandonsavage) wrote at 11/6/2009 11:22 am:
Miles, I promised Keith Casey I would never make my framework public. I fear death if I back out on that promise, so for now it will have to remain under wraps. The framework was a learning exercise anyway; not really something I’d ever share.
snipe (@snipeyhead) wrote at 11/6/2009 12:03 pm:
Great post, Brandon. I completely agree with you and Elizabeth. While other people have commented that it helps developers who might have really only used frameworks in the past learn more about PHP, I’d go so far as to take it a step further and say it helps them learn about good dev practices in general. MVC, file structures, deciding where configurations (etc) should live any WHY. It’s the why part that they often won’t realize until they bone it a few times and have to fix it, but they’ll walk away with a better understanding of how an app should be structured, both conceptually and programmatically, to be as flexible and lightweight as possible. You can study existing frameworks or read 100 books, but sometimes the only way to really get it is to screw it up for yourself. :)
Miles Johnson (@gearvosh) wrote at 11/6/2009 12:31 pm:
@Brandon – Thats a shame, was thinking maybe we could share ours and maybe merge and create a pretty nifty one ;)
However, mines PHP 5.3 only.
Michael Gatto wrote at 11/6/2009 12:31 pm:
Maybe we’re better off writing a PEAR component as a learning experience instead of a Framework. I know that working on my proposal for VersionControl_Hg (shameless plug!) has given me plenty of decision making about architecture and coding and its productive. Writing a framework for a learning epxerience but not releasing it seems not so useful to the community, nor even to us ourselves since unreleased code has few if any eyes reviewing it.
A PEAR component gets released and open sourced so others can suggest improvements and may well benefit from our learning exercises.
Brandon Savage (@brandonsavage) wrote at 11/6/2009 12:41 pm:
Miles, you can make your case to Keith Casey. He is following along with the comments. ;-)
Michael, you make an excellent point. PEAR is another great opportunity for developers. I’m working on my own PEAR extension, and I’ve learned a lot.
Jesse Donat (@donatj) wrote at 11/6/2009 3:28 pm:
This goes along with what I’ve been saying for years now, from experience, every PHP developer worth their chops will develop at least one framework in their time.
Hodicska Gergely (@felhobacsi) wrote at 11/6/2009 4:36 pm:
Hi Brandon, I absolutely agree. My diploma thesis was a PHP framework (and security) and I can say I learned much more in half year than in the previous two years. Not only because of creating the framework itself but from the research how others framework solved the typical parts of an MVC framework.
Jase (@jase.com) wrote at 11/6/2009 5:12 pm:
Back in the day, before there were any available, you had to write your own framework. I based my first two on the MFC document-view pattern in 2002 (which were for Trivial Pursuit and Technorati, respectively). Over the years, I have tried many, but continue to go back to my handrolled version because it is sooo much more productive to refine something that fits perfectly into your own programming aesthetic, rather than to fight with the nuances of someone elses. Also, considering the 9 years I’ve put into my own IDE (in C++) that works seamlessly with my framework, I recommend everyone give it a try.
sokzzuka wrote at 11/6/2009 6:33 pm:
I agree 100% with you, I’am now writing my own framework because I see most php frameworks wery similar. I’ve learned so much during the developement. Also in my framework I’am trying to solve problems that I see every day using ZF in work. I think I will give it a shot and publish it when it’s ready :>
Paryank (@paryank) wrote at 11/7/2009 6:33 am:
I agree with you.
Programmer should at least know the basics and be able to write his own framework. Well, I haven’t developed my own framework and I use Zend Framework, but I learn the way it works, especially its MVC components and Tool framework so that I can develop my own extensions to it whenever needed.
Well, I don’t prefer to reinvent the wheel and keep using Zend Framework for production, but I want to be able to do it myself when needed.
Tomáš Fejfar (@tomasfejfar) wrote at 11/7/2009 7:53 am:
I went from pure-php-madness to CodeIgniter and from CI to Zend Framework.
The first change was a BIG BANG. Complete change of thinking. But (not expected) the other one was even bigger! Great thing about ZF is that it’s a gallery of best approaches. Other good thing is that there is class for everything, that can do anything. And even greater is that if that class is an overkill for your needs, you can write your own and substitute it to the framework. That means you don’t waste you days writing a decent router, but you can write your own authentication adapter, db model, super-cuzstomised view helper, etc. learning from the polished interfaces available. You don’t like ZF’s view? Use Smarty instead, or your own layer. Missing some web service API in ZF? Make a class for it using Zend_Rest_Client.
That’s the 0,5 that MatthewW’OP was talking about. And it helps you big way ! I’ve become a better developer in last 1,5 years using ZF then in the 6yrs doing my own PHP :)
Les wrote at 11/7/2009 10:04 am:
> You can study existing frameworks or read 100 books, but
> sometimes the only way to really get it is to screw it up for
> yourself.:agree:
You have to live and learn; that in it’s self is what learning is all about – you learn from your own experiences, mistakes included.
Doesn’t matter how much APIs you study, you got to get your hands dirty. And it’s not only about developing a framework, it’s as much about the other responsibilities that go along with it.
You will never get that feeling simply by using a pre fabricated framework no matter how great it is, how flexible it is or even if it’s loaded full of features, not to mention bloat.
till (@klimpong) wrote at 11/7/2009 11:02 am:
IMHO, the beauty of some frameworks is the use-at-will architecture. The advantage here is that you can exchange components for a better implementation — or let’s be honest, one that’s more appropriate situation.
I’ve seen a lot of frameworks and my biggest issue with custom frameworks is that no one but either one developer or a relatively small team see the code. And in this situation anyone is more likely to screw up sooner or later than in an open environment.
When people complain about frameworks, they often forget that frameworks are not written just for them or for their particular use case. No, a framework is written for a wider audience.
The better frameworks communicate this fact very well and allow developers to replace components, or plugin their own.
Andy Walpole (@http://www.suburban-glory.com/blog.html) wrote at 11/8/2009 3:44 am:
If by having your own framework you mean that PHP developers should have their own library of tried and tested code, then yeah, I’m 101% with you on this.
Bertrand Mansion wrote at 11/8/2009 5:50 pm:
I have written my own framework. It is better than anything I have seen because it fits my needs and my colleagues’. I don’t think using an existing framework is a good idea unless you have no other choice.
sole wrote at 11/8/2009 7:49 pm:
Every developer who knows ends up writing his/her own framework so that it has *exactly* what he/she needs, and not the myriad of options and modules that ‘established’ frameworks have so that they can cater for a wider audience.
Looking at other frameworks is generally a good idea, if only to see how things should not be done ;)
Tomáš Fejfar (@tomasfejfar) wrote at 11/9/2009 8:17 am:
sole: Problem is that you never know what you need until you really need it ;) And more heads = more knowledge = less hidden flaws.
You never needed to update some data in view and echo it somewhere in layout (higher in the page layout, than the actual place). For me it would mean like 3 days of studying and googling. Framework developers (at least some of them) has already needed it, so they know that it’s needed. If you start your framework, than you will need to rebuild it every time new feature emerges. That extremly ineffective.
I agree everyone should write his own framework, but nobody should use it for any serious work.
Les wrote at 11/9/2009 11:20 am:
> … but nobody should use it for any serious work.
Why not?
I can think of one reason – security, however any developer with some experience who could develop their own framework would already know enough to secure their framework too.
It is when you have an already established framework and you yourself start to tinker with it, introducing third party modules – modules I might add that are foreign to the established framework – you introduce security holes not only into the framework but your application.
The only other thing I can think of that would make you ponder about a framework is that the code base has been developed from the ground up with no prior application development to test the water.
Tomáš Fejfar (@tomasfejfar) wrote at 11/9/2009 12:59 pm:
Yes, security is main concern. But what about a lack of documentation, lack of coding standards, etc? :) I’ve never seen a framework, not developed by community, that had good coding standards, documentation and (other) people are able to use it effectively. There are only a few, that can handle themselves, so that the code is useable for other people. If you let BFD (bloody f**king developer) develop a framework of his own, he will eventually end up having a pile of isolated scripts, which quality is based on the time they were created (new ones are the best).
Well, Nette is (was for long time) developed by only one person, and is an exception to the rule.
sole wrote at 11/10/2009 9:40 am:
Tomas, if your framework is properly designed, you don’t need to rebuild everything each time you want to add a new feature.
I have used somebody else’s frameworks several times and most of the times there is so much automagic going on that they go against you. You need to learn how to do things their way, look for strange and unpredictable/undocumented behaviour and etc, whereas if you know what you’re doing (here’s the basic premise) you just do it and jump to the next item in the to do list.
The security aspect is quite important as well. With code that you’ve developed, you know exactly what is going on. With somebody else’s code, you either audit everything or have hope ;)
Tomáš Fejfar (@tomasfejfar) wrote at 11/10/2009 9:53 am:
sole: That’s EXACTLY what I’m talking about! Problme is that everyone thinks about everyone’s elses framework that it’s lame! :) That’s why everyone develops his own. And that’s using a prefabricated framework developed by comunity is the only option for serious job.
Imagine you make your framework, use it for several projects and then leave the company (no docs – you know how it works, why docs?). This actually happened in a company in our town. The company is using little custom-extended Zend Framework since that day :D :P
That’s what I meant by “I agree everyone should write his own framework, but nobody should use it for any serious work.” :P
Jayant Patil (@jayantworld) wrote at 11/12/2009 8:06 am:
Creating your own framework is good thing. I think every developer should make it. But it should have some concept. Why you require it when it is already developed by someone having more features. If you are serious about making framework with some concept, it should be well documented irrespective of user [may be you] and this is the point where we probably fail. I had seen, most of popular framework is well documented. Again provide the examples files, so the concept should be more clear.
You should probably use your framework in serious work otherwise there was no new development in any subject, but sure to clear your picture. Dont loose confident.
Svetoslav (@lordspace) wrote at 11/13/2009 11:55 am:
I think every decision should be based on your task/goal/project.
If you want to build a simple & small site then it’s not worth the time of building something sophisticated.Matthew has an interesting point with the 2.5.
I’ve never heard of that.I think I am at 0.5 stage :)
Les wrote at 11/13/2009 12:04 pm:
> no docs – you know how it works, why docs?
That just wouldn’t happen in a professional evironment, simple as that – if it did, the project manager(s) should be booted the -beep- out of there.
I can understand it may happen in smaller firms, but hey! they are small for a reason right? they ain’t gonna advance any further than what they have done because they don’t have organisational standards in their company, never mind their -beep- IT department.
To develop, maintain and deploy using your application you certainly do need a level of commitment, professionalism and integrity to complete on it and in some cases those personal characteristics are sadly missing.
But that isn’t a reason as to why not to develop a framework.
« Exceptional PHP: Introduction to Exceptions | Adapting The Joel Test To Web Development » |