Monday, February 7, 2011

Why self-made frameworks are too expensive?

As I progress in my PHP programming endeavours I tend to argue a lot about the same topics with different developers. Sometimes there is some reason in madness I hear, but very often there is much overheard information that somehow doesn't make any sense and causes real confusion with some people. As in my opinion many web developers/programmers are very narcissistic, and even if they wont admit it, they think their code is the best for whatever reason, and no Open Source PHP Framework (they're all only open source since it's php, but I like to call it like it is) can match them in the understanding on the domain they are working on and the project will surely die without a custom made framework.
This confusion can sometimes lead to very high development and maintenance cost and I'll try to clear the situation a little bit, so You don't have to make the same mistakes.



The problem:

We have to build an Internet service of some kind, something we haven't exactly been much familiar with because it can be described as innovative.



The typical "solutions" (stuff I hear very often)

1) "Frameworks like Zend Framework or Symfony are slow and heavy, we will need a lot more hardware"
2) We need a lot more features than Open Source frameworks can provide
3) Frameworks are just another dude's point of view and implement things strangely



The crushing(for some) reality:

Let us mark out all the fields that we need to compare home-made-gizmo frameworks with PHP OSF (Open Source Frameworks):

  • learning curve
  • reliability
  • maintainability
  • extendability
  • performance
  • development time
  • overall system cost



So lets maybe start with learning curve.

Unless You made a real effort to document everything in detail, add examples, tutorials and so on, event if you make some presentations and in-house training courses... you can't come even close to the POWER OF COMMUNITY.
Open Source PHP frameworks like ZF (my favorite as You might have noticed) have a great community, testing, learning and developing a lot of code with You and for You. You can hire professionals (like I ;-) ) that already know a lot about a system that you are about to design, build or maintain and spare a lot of head aches on paying someone for a month or two just to get around your system.

That's a clear 1-0 for PHP OSF !



Next we have a reliability comparison

So in my opinion there is only one answer here but let's just see what will be.
IMHO self made framework have a overall lower quality of code, thus offering much lower reliability for three simple reasons.

One - the developers working on in house development (and php programmers anyway) often don't know more (that a sad truth to realize) than two design patterns. the first is Singleton, the second is MVC or a mutant, unusable form of it anyway. I don't have any idea why developers confuse MVC's Model with the data layer, and not the business logic layer but what the hell, let's just go with it. the design becomes unclear, the classes all become dependant on each other and there is no way in hell that someone is writing decent unit tests for that monster.

The second reason is that most of the time there is no time to THINK BEFORE YOU CODE and the obvious pressure is on functionality not on the back end. Many people think that they can just code away and if the service is a bulls eye in the market, they.ll just change the framework "with all the money we will get" :) but in reality this seldom happens. they end up with much higher development costs.

The third reason is again COMMUNITY. It is very simple really. While one developer can write one thing, a hundred developers write a hundred things, find a hundred bugs, and since it's Open Source, entirely free. Unit testing everything just to get their piece of code accepted in a frameworks source makes people very proud and you don't have to pay a cent for the reliability these frameworks offer.

So that's 2-0 for PHP OSF ! Great!



Now let's take a look at maintainability and extendability

How are your projects being maintained ? Another "if" maybe? Well let's just say, you're one hell of a programmer and you create object oriented code that uses design patterns in a reasonable manner and is really great to maintain. You have a great FW that is easy to maintain, but almost certainly just for you, with no real documentation no one will even look at it (unless you have some fanatic followers of course ;) ) and it takes a lot of effort to upgrade some part of the application. OSF's again have the power of COMMUNITY that creates updates, bug fixes, and the code is just from start designed to please the most of users, not just one.

Extendability is tightly coupled (ironic isn't it?:) ) with maintainability, so I wont;t get in to deep. The punchline here is, if you create code that can easily change from eg. JSON output to Array output, without changing any conditional statements you almost certainly create code that can be extended to output XML or something else.

A clear 3-0 for OSF...



Now comes the fun part, performance.

Many developers believe that they truly do good for the project by repeating some overheard information with no real scientific background. NO! If you want to be sure, that you create faster code -> test it. Nothing is just faster or just slower.

In my time I've created a version of Zend_Acl that was made entirely with arrays. Since the code almost entirely run in some simple foreaches, it was 10-20x faster than the original. If you take into account only the speed of working, not the speed of development - you are sure to create code that is used only one and rewritten every time. Speed is not a scalar value, its a function of functionality, so most probably, making really good OOP into procedural programming, will make it works faster, and less memory bound, but also will make you work longer to get to the same place.

In my opinion, OOP is not always the best approach, for high traffic websites, most often used load balancer is something like $readServer = $readServerSet[ rand(1,10) ]; It gets the Job done.

Custom made frameworks are in most cases faster that the OOP approach of for instance ZF. It's a question of power really, the simpler the framework, the faster it runs. OSF's are made for many people, not just for your project, so the creators had to compromise function and form.

I will give one for custom frameworks here, but it's not really a win, as I'll try to explain later. So 3-1...

The real kicker and the whole idea of OSF's is to decrease development time because that's what it's all about. the purpose of most applications is to get the creator money :) I know it's pretty harsh but it's the simple truth. So what does it give us, that we have a team skilled in one framework, like ZF, with a lot of extensions developed, with no time spent creating, testing, maintaining their own custom FW?


More Money!


That's what its all about, the time spent developing is one half or even less that in custom frameworks (not enterprise level frameworks of course) and that results in a lot more projects being created, and more money earned.

Needless to say +2 for OSF's ! That's 5-1 !!!



The conclusion:

So for all you rich bastards, that can afford developing shitty frameworks, by unskilled developers who still think, they can do better than Zend, Symfony, Doctrine or whatever...

... think with your wallet :)

best,
Peter