PHP is the Devil!

I’m a big fan of podcasts, and recently I stumbled upon this jewel. It’s not a podcast per se, but eight audio files containing presentations from Carson Workshops entitled ‘The Future Of Web Apps’. I’ve listened to three of them by now, and here’s what I’ve learnt so far:

  • Joshua Schachter, Delicious [mp3]; Don’t write for scalability, you won’t know what breaks before it breaks. People will molest your server.
  • Cal Henderson, Flickr [mp3]; Write an API, use an open system; let users know that they can export their data if they don’t want to use your service anymore (it will get you more users!)
  • David Heinemeier Hansson, 37 signals and one of the developers behind Ruby On Rails [mp3]; Flexibility is overrated, and PHP is the Devil!

Great stuff! :) Can’t wait to listen to the next five. And since I’m going to Manchester this weekend (or, stoke-on-trent to be precise, but that’s almost Manchester isn’t it) there should be some travel time to listen to some of this :)r

Cutting the Gordian Knot

“Gordius, the King of Phrygia, once tied a knot that no one could untie. It was said that he who solved the riddle of the Gordian Knot would rule all of Asia. So along comes Alexander the Great, who chops the knot to bits with his sword. Just a little different interpretation of the requirements, that’s all… and he did end up ruling most of Asia.”

So begins chapter seven of one of my favourite programming books of all time.

Finding the answers to impossible problems is all about asking the right questions. So, here you have them ;-)

Problem solving questions

  • Is there an easier way?
  • Are you trying to solve the right problem, or have you been distracted by a peripheral technicality?
  • Why is this ting a problem?
  • What is it that’s making it so hard to solve?
  • Does it have to be done this way?
  • Does it have to be done at all?

TPP promises; “Many times a surprising revelation will come to you as you try to answer one of these questions.”

One of the original books on heuristics in problem-solving was G. Polya’s “How to Solve It” (1957). Although his book is about problem solving in mathematics, it can just as well be used for software engineering.

Here’s a summary of Polya’s problem solving approach:

    1. Understanding the problem. You have to understand the problem. What is the unknown? What are the data? What is the condition? Is it possible to satisy the condition? Is the condition sufficient to determine the unknown? Or is it insufficient? Or redundant? Or contradictory? Draw a figure. Introduce suitable notation. Separate the various parts of the condition. Can you write them down?
    2. Devising a Plan. Find the connection between the data and the unknown. You might be obliged to consider auxiliary problems if you can’t find and intermediate connection. You should eventually come up with a plan of the solution.     Have you seen the problem before? Or have you seen the same problem in a slightly different form? Do you know a related problem? Do you know a theorem that could be useful?     Look at the unknown! And try to think of a familiar problem having the same or a similar unkown. Here is a problem related to yours and solved before. Can you use it? Can you use its result? Can you use its method? Should you introduce some auxiliary element in order to make its use possible?     Can you restate the problem? Can you restate it still differently? Go back to definitions.   If you cannot solve the proposed problem, try to solve some related problem first. Can you imagine a more accessible related problem? A more general problem? A more special problem? An analogous problem? Can you solve a part of the problem? Keep only a part of the condition, drop the other part; how far is the unknown then determined, how can it vary? Can you derive something useful from the data? Can you think of other data appropriate for determining the unknown? Can you change the unknown or the data, or both if necessary, so that the new unknown and the new data are nearer to each other?     Did you use all the data? Did you use the whole condition? Have you taking into account all the essential notions involved in the problem?
    3. Carrying out the Plan. Carry out your plan. Carrying out your plan of the solution, check each step. Can you see clearly that the step is correct? Can you prove that it’s correct?
    4. Looking back. Examine the solution. Can you check the result? Can you check the argument? Can you derive the result differently? Can you see it at a glance?     Can you use the result, or the method, for some other problem?

    Woh! That’s a lot of problem-solving questions for you – it’s almost like finding the “unsub” in an episode of the CBS show Criminal Minds isn’t it?

    Also, notice how similar this is to design patterns? Those problem solving questions are almost like a design pattern for finding solutions! Go ahead – print them out, and refer to them when needed.

Code checklists

The best things in life are free smart and simple! As code checklists for example. I’m currently reading Bob Walsh‘s recent book Mirco-ISV – From Vision To Reality, which is a book about running your own Micro-ISV (independent/internet software vendor). Micro-ISV’s are often one-man companies, for example single developers producing and selling their own software. Early in the book Walsh talks about ‘developing the Micro-ISV way’, and this is where he gets into code checklists:

Using a code checklist is the easiest method of the lot. Go into Microsoft Word, write the half-dozen coding mistakes you’ve last made, print the document, and look at the list as you review the code you wrote today. See any familiar faces? Write down other ways you miss the mark as they crop up, and revise your code’s checklist.doc periodically. What you’ll notice over time is coding is just like spelling. You make certain coding mistakes repeatedly, but if you focus on them, you’ll make them less often. Just the process of checking my code against my private coding checklist identifies about half of the coding mistakes I make, especially those nasty increment-by-zero blunders and other simple errors. Give it a try!

Strange I haven’t thought about this before, or done it before – but I haven’t. At least not that I can remember. I’ve just started doing it, so I don’t know how much it will pay off, but it looks like a good idea at least :) .. I’ve decided to use one checklist for each language I code in (e.g. java.txt, php.txt, javascript.txt, etc.) – as I code in multiple languages each day. In addition I think it could be a good idea to include functions and things I often forget that I have to look up way too often (like various string functions in JavaScript!).