Skip navigation.

Code's Worse Enemy #

Steve Yegge talks about choosing the right programming language in the face of Code's Worse Enemy:

I'll give you the capsule synopsis, the one-sentence summary of the learnings I had from the Bad Thing that happened to me while writing my game in Java: if you begin with the assumption that you need to shrink your code base, you will eventually be forced to conclude that you cannot continue to use Java. Conversely, if you begin with the assumption that you must use Java, then you will eventually be forced to conclude that you will have millions of lines of code.

There's a lot of truth in what he says. You can't fault his taste: He prefers Mozilla Rhino, a Javascript/Ecmascript implementation.

When we coded in ASP, we were a JScript shop. When we were looking for something that ran cross-platform, the closest thing that fit the bill was PHP. Javascript with perl-style $variables. Neither language is perfect. But good enough - or as some prefer to put it: worse is better.

Why Should PHP ever be taught in school? #

Happy New Year Folks! Let's keep on blogging.

This posting by Ka-Ping Yee on why PHP should never be taught is precisely why PHP should be taught. If something is popular but hard to understand then we need an education process. To just shake our heads and give up is simply immature (or trolling). Otherwise we might as well say that English (or any other spoken language for that matter) should not be taught, because spoken languages are illogical, imprecise and therefore ... useless :)

Most programming languages have similar gotchas. Oracle's PL/SQL has "" being equivalent to null. Javascript believes that 0 and "" are equivalent. C has non-zero being equivalent to boolean true. Lisp's gotcha begins with ( and ends with ) -- (just a joke). Java's gotcha begins with J2EE and the obsolete baggage that comes with it.

PS: The confusion is because === is the real equality operator and should be used here. In PHP, == is equality after typecasting, where 0 == "0" and "" == "0" evaluating to true are accepted conventions. They are useful constructs in many situations in a similar vein to C's convention of 0 being boolean true and non-zero being boolean false, which the critics cleverly ignore. See the PHP Manual on type comparisons

Web cluster redundancy with mod_backhand revisited #

In my last blog entry on mod_backhand, I mentioned that you could implement redundancy in a web cluster by having multiple load balancers and using round robin DNS pointing to the load balancers. This technique is mentioned in the mod_backhand presentation notes by Theo Schlossnagle, one of the author's of mod_backhand.

But if you think about it carefully, in my opinion, this solution doesn't really work well:

  • Round robin DNS systems simply return a list of IP addresses (sorted randomly) that resolve that domain name. Most DNS servers do not perform checks to detect if any of the IP addresses are down. So clients will get the IP addresses of load balancers that are down too. The DNS client normally just picks the first IP address in the list to use - and it could be the IP address of a load balancer that is down.
  • Secondly, when a client resolves the domain name, this IP address is cached on the client. So a failure in one of the load balancers would still mean that all web browsers that previously connected to that load balancer successfully because of DNS caching would be unable to access the system for quite a long time (e,g. 10-15 minutes).

I can think of several solutions, but the best one as far as I can see (if you still want to use mod_backhand of course) is to run mod_backhand on a high availability hardware solution (or if a few minutes downtime is acceptable, keep a spare box configured with mod_backhand around to swap with any balancer that goes down), and not push the hard problem of high availability and redundancy to DNS.

Ahmad Amran Kapi from Melaka, Malaysia, points out that you can use Wackamole:

Wackamole is an application that helps with making a cluster highly available. It manages a bunch of virtual IPs, that should be available to the outside world at all times. Wackamole ensures that a single machine within a cluster is listening on each virtual IP address that Wackamole manages. If it discovers that particular machines within the cluster are not alive, it will almost immediately ensure that other machines acquire these public IPs. At no time will more than one machine listen on any virtual IP. Wackamole also works toward achieving a balanced distribution of number IPs on the machine within the cluster it manages.