Development

Cracking the Cryptext with PHP

In the book the DaVinci code there’s a fun little device called a “Cryptex”. It a container for a secret message, and to open it, you need to align some dials to the correct position. In an quiz somewhere you were invited to crack such a cryptext consisting of 6 dials with 6 letters on each to find the correct combination, which would spell a word. To find the solution quickly, all you need is PHP.

Everything is cooler on a Mac

… even crashes. While it shouldn’t matter too much, the eye candy (cool graphics, sweet effects and other eye pleasing stuff) on a Mac even makes me smile from time to time – and you just have a little more forgiveness to a program, which crashes with grace. Take Adium - my favourite Instant Messaging client. Being a multi language expert (and thus speaking both MSN, Jabber, GTalk, ICQ and other protocols) it does have a hard time, and some times – weeks if not months apart – a may go down in flames.

Do you use PHP Constants?

Browsing in other people code can be an interesting experience. Sometimes you learn stuff, other times you just get scared of the things you see. One recent observation I seem to make a lot, is that handling “application configuration” is often handled less gracefully as a would have wished. The plain basic configuration handling in many PHP applications seems to be creating a php-file and declare all configuration values in this file – then have all other scripts in the application include this one config file – and sure it works.

Do I need a primary key and should it be called id?

While working with databases – especially Mysql – most people seem to ask the same question over and over again when it comes to Primary Keys. Here’s my typical answer to the question(s) above (and more).

Do I need a primary key?

No, you don’t need it, but if you haven’t got one, there’s probably something wrong with your data model. A primary key is the unique key to a row in a table. It can be a single column, but in some cases it can be a combination of two or more columns.

MVC for PHP

With the amazing buzz around RubyonRails, everyone seems to be hooked on the Model-View-Controller (or just MVC) paradigm – and do strive to mindlessly implement the ”Ruby way” into other programming languages without too much reflection and thoughts on how to do it. . Even tough most of the efforts I’ve seen so far seem pretty hopeless; I do believe you could actually do something good with MVC and PHP. Let me try to tell you how. My ”systems thinking” is usually in the ”large professional genre” and it’s an absolute requirement that the PHP code developed is Efficient, Secure and Maintainable. To get a decent shoot at these, we really can’t reuse ideas and ideologies from Java or Ruby into PHP – we must adapt them to the strengths, weaknesses and ”php ways” to get a good result.

QuickSilver

I finally get it. QuickSilver that is. Its an application for the Mac OSX and is the best friend any OSX Power User can have. I’ve downloaded it a couple of times, tried to figure what it was and uninstalled it – but not any more. It’s just great and ought to be build into the OSX. QuickSilver is sort of a power tools basically has made my muse workless today. It’s a power-edition of the Dock and it probably has a ton of undiscovered features I haven’t figured out yet.

Coding style

I usually edit more code others made, than I create new files, and while most of the code is in PHP, there’s a huge difference in the coding style applied by different developers, and some styles are much more annoying than others. I do respect that people are different and that is probably more efficient to allow for some degree of personal style than to try to enforce a single common style. If possible try to make standards where all can agree upon them, and where it isn’t possible, don’t force it too hard (on less pressing issues makes it necessary).

Emptying mysql tables

There are actually two ways to wipe a mysql table either using delete or using truncate – which is better and why? So far my most commonly used form to wipe a table has simple been by using:

DELETE FROM tablename;
which works fine for most cases, but mysql also offers a different method:

TRUNCATE tablename;

Besides the fact that it seems to be faster (even on small tables with few rows) – which in itself is a reason to favour this method - it also has another nice feature, which may be desirable. It resets the AUTO_INCREMENT field if it exists, and let the counter start over from 1.