Is PHP suffering from a handicap of a head start?

In dutch we have a nice expression (“Wet van de remmende voorsprong”) and translated in English it is something like The Law of the handicap of a head start. A company or a product can be very innovative but after a initial success it can be too slow to react on changes and then become outdated.

In my opinion PHP is suffering from this particular problem. PHP has made a real fast start and has an made it to a great deal of the websites of today. But now it is suffering from a burden of legacy and innovation is going really slow. To name a few:

  • With the release of PHP 5.3 we finally got namespaces, Java has it by design for a decade or so.
  • Annotations are used in a “poor mans version”, in comments instead of native in the language.
  • Dynamic typing, this is not really a PHP issue but it can work out very dangerous with SQL injections that are possible “by design”. A GET query parameter is not checked anyhow. All checking should be done by the programmer instead default in the language.
  • Refactoring, with the dynamic typing comes another problem that refactoring is almost impossible in large projects. We changing a function signature you must manually search for all references and change them. The only way to find out you forgot one is at runtime. The compiler will not complain.
  • Exception handling is not always used. Some newer classes are using exception throwing when something is going wrong. But a lot of older functions are not using exceptions but still generate a plain old E_ERROR or similar. This way it is impossible to catch some errors and react on it. And then people start using the @ sign.. with all consequences.

I think PHP should react on these legacy problems by supporting optional typing (like Scala does), so a programmer can make a choice and old legacy software will keep running and professional programmers can use static typing. And maybe drop all the old procedural functions or refactor them to support exceptions were possible. This way PHP can become better in my opinion. Because Java becomes very tempting for me 🙂

 

Science or fiction?

There is a thin line between what we call science and what we call fiction. If some imaginary story or event becomes true it becomes fact and even becomes common accepted in the science. For example, if you told someone who lived hundred years ago that we can construct microchips with a million transistors on it they would not believe you. Let alone the fact that the earth is not flat (actually the earth has become flat again but in a slightly different way [ref]http://www.youtube.com/watch?v=53vLQnuV9FY[/ref]).

So what we now call fiction can become faction and even science within a few year or few decades. Nature still has a lot of secrets that she will not share with us for a long time but once she will reveal it and we will learn something new about our existence. I can’t wait for the replicators and warp-drive 🙂

Bottom line is that we never can know anything for certain because we can’t oversee the present, future events and discoveries that has to be made. Scientists should always be open minded about the “truth”. Truth is very complex and in my opinion impossible to grasp. We never can be certain of anything. Einstein has a great quote that covers it in a very nice way:

“Whoever undertakes to set himself up as a judge of Truth and Knowledge is shipwrecked by the laughter of the gods.” – Albert Einstein

 

Singleton pattern in PHP 5.3

With the introduction of PHP 5.3 some nice object oriented features are available. One of them is the function get_called_class. Below a short example when this function comes in handy.

When we have an abstract CacheDriver as shown below and we extend this with a MemcachedDriver. We only want one instance of this driver available so we apply the singleton pattern. But before PHP 5.3 it was very difficult to put the getInstance method in the base class. There is a solution to use the factory pattern (eg. CacheDriver::getInstance('Memcached')) but the following solution is more elegant and possible from PHP 5.3

Because get_called_class() yields the name of the class we are using (MemcachedDriver) we get directly an instance of the MemcachedDriver without duplicating the getInstance method or using the factory pattern.

How big is Google?

What started in the late 90’s (1998 to be exact) is now a very large company that reaches probably the most amount of people worldwide. It started with their search algorithm and an interface to use the information they had stored and indexed. But now they have their own operating system (Android), a browser (Chrome) and a whole bunch of other products.

In this article I will give a short oversight of what they are doing and how all these products interconnect with each other. Also why some products are not creating money but are very important to sell their main product. While Google is really big and you can discuss if they aren’t too big they always claim to “Not do any evil”. Continue reading How big is Google?

Some personal notes on Software Engineering, Robotics, Programming etc..