Spot the dinosaur

Microsoft, the dinosaur
Don’t you just love that illustration? I think it says so much. It’s from an article in The Economist about Microsoft and the new threat from emerging Web 2.0 products.I mean, who wants to use the calendar in Outlook, when Google Calendar was just released. In fact, who wants to use Outlook at all, with an online alternative such as GMail? And as for writing documents I, for one, prefer Writely over Word.
Microsoft must feel this wave of free online software competing with their main products – and I think they are trying to keep up. They are doing something with Live, although I’m not quite sure what they’re aiming at. And they recently released Hotmail’s brand new outlookish, webtwoish style. But can the dinosaur compete? With teams such as Flickr, doing incremental development and releasing a new version of their product every week? Microsoft’s product cycles are measured in .. hmm, years? It takes a long time to turn around a dinosaur. So, which marketing genious decided to make commercials that “show office workers as dinosaurs, stuck in a bygone era.”, as Economist so aptly put it? Anyway, just wanted to show you the illustration, that was all :). Happy easter!

PEAR DataObjects vs. Propel vs. EzPDO vs .. Java!

Using an object perstistence layer can be greatly benefitial for any medium to large size project. Or, any project at all some would say. If you don’t know what I’m talking about, I’ll give you a quick example. Usually, in PHP we would do something ugly-bugly like this to retrieve info about a certain item in the database:

$res = mysql_query(“SELECT * FROM article WHERE ID=5”); if($row == mysql_fetch_assoc($res)) { echo $row[“title”]; // do something here }

Compare it to this:

$article = new Article(5); echo $article->getTitle(); // do something here

Ah, the beauty of OO.

My first experience with this was the PEAR DataObject package. I was amazed – it could generate classes based on the tables found in my database automatically, and I could start using them instantly! Yummy!

Lately I’ve been having a look at Propel. You see, I know the Symfony guys chose Propel, and after listening to a podcast with an interview with one of the project leads there, I’m convinced that the guys behind symfony are smart. Smart people choose the best frameworks, so my logic tells me to look at Propel :)

I haven’t tried it yet – but at first glance it looks better than PEAR DO. Why? Well, Propel will generate 4 classes for each table in your database. Overkill you say? Well, read this from the Symfony Model documentation:

Why keep two versions of the data object model, one in model/om/ and another in model/?
You will probably need to add custom methods and attributes to the model objects (think about the ->getName() method that outputs the FirstName and LastName together). But as your project develops, you will also add tables or columns. Whenever you change the schema.xml, you have to make a new call to symfony propel-build-model to generate the object model classes. The Base architecture allows you to keep using the symfony propel-build-model command even after you added custom code to your classes. Here is how it works: the Base classes kept in the model/om/ directory are the ones generated by Propel. You should never modify them since every new build of the model will completely erase these files. But if you need to add custom methods, use the regular object classes of the model/ directory that actually inherit from the previous ones.

Of course, you could just extend the PEAR DataObjects created but it just … well, it just doesn’t seem to be encouraged. I like when a framework encourage me to do stuff The Right Way(TM).

So, Propel it is, I thought – but that was before a co-worker of mine suggested EzPDO which supposedly had a bit of a different approach. They brand themselves as “A simple solution for PHP Object Relational Mapping and Data Persistence” and they seem to be worth a look.

The final solution I’m looking at for solving this issue is using Java combined with PHP. Using the new Zend Platform it’s possible to use Java objects, in PHP code – is that great or what. A little illustration for you, which I found here.

java in php

That way the db stuff can be handled in EJB’s maybe, everything is transferred via SOAP and I can use objects in PHP like I would with Propel etc. It’s all a bit sketchy, but it’s something I’m looking at.

Comments anyone? I’d love to hear some feedback from people who have actually done this ..

Characteristics of "Great Software Design"TM

This post is not about design-design, but the internal design of a software system. Such a design has several general characteristics, and Code Complete 2 has a list of these. First, a related quote by R. Buckminster Fuller:

“When I am working on a problem I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong.”

Great Software Design would have all these characteristics, but that’s almost never possible. Some of them contradict each other, so often we have to make tradeoffs. Anyway, here’s the list:

  • Minimal complexity – if your design doesn’t let you safely ignore most other parts of the program when you’re immersed in one specific part, the design isn’t doing its job. This is also known as avoiding complexity.
  • Ease if maintenance – design the system to be self-explanatory. Wheter it’s yourself or a maintainance programmer that’s going to sit down and fix a bug in a couple of months time it’ll be worth it.
  • Loose coupling – Loose coupling means designing so that you hold connections among different parts of a program to a minimum. This means; encapsulation, and information hiding [read] and good abstractions in class interfaces. This also makes the stuff easier to test, which is a Good Thing.
  • Extensibility – You can change a piece of the system without affecting other pieces.
  • Reusability – Designing the system so that you can use pieces of it in other systems.
  • High fan-in – This refers to having a high number of classes that use a given class. This is good, the opposite on the other hand …
  • Low-to-medium fan-out – Refers to how many classes a given class use. If a class have a high fan-out (Code Complete says this is more than 7 classes, I don’t want to be that specific) this is often an indication of that the class may be overly complex. And complexity is bad, remember?
  • Portability – How easy would it be to move the system to another environment?
  • Leanness – I guess this could be compared to KISS. Voiltaire said that a book is finished not when nothing more can be added but when nothing more can be taken away. Extra code will have to be developed, reviewed, tested, and considered when the other code is modified.
  • Stratification – designing “in layers”. Can you view “one layer” of the code without thinking about the underlying layer? An example giving in Code Complete is if you’re writing a modern system that has to use a lot of older, poorly designed code – you would want to write a layer of the new system that is responsible for interfacing with the old code.
  • Standard techniques – this means using design patterns whenever it is appropiate to do so. This way, if you say to another coder “Here I use the Factory pattern” he will instantly know what you’re talking about if he knows the pattern. You do not want to be one of those “valued employees” who only write code that the “valued employee” can understand.

And, whatever you do: DO NOT CONSIDER SPEED! NEVER OPTIMIZE WHILE DESIGNING! (yes, those really needed to be capitalized). If I have one more PHP coder tell me that the MVC solution probably won’t be speedy, I will have to slashdot him physically in public. You don’t want to start off by trading any of the characteristics above for speed.

You design the system with design in mind, and if it turns out to be slow then you optimize. You will know what the bottleneck is, and you will make a sensible and thought-through trade-off. Then you will have your good design, and your speed. You will, rule the entire planet. Hah, kidding, the last part I just made up.

Well, what are you waiting for? Run out in a flowery meadow with your pen and paper and design something beautiful!