Archive for April, 2006

Programming is a language – use it correctly

I have determined this day to blog about a topic which is sorely missing in at least half the PHP (and other!) projects I have reviewed over the space of the last year. I say a period of a year, but you can drag it back in time.

My first presumption is that all people have at least a working knowledge of their native language (questionable I know ;-)). Languages are weird things, often full of obscure rules which may not only differ between related languages – but between dialects also. However they all generally have similar standard rules, terms, and conventions.

Programming is a language. Most people tend to agree with that statement. Afterall how many would interpret:

if($i == 2){
echo ‘True’, “\n”;
}

as:

If variable i equals 2 then echo True-newline.

Most people would be my guess. The if statement is one of the most common constructs in programming today – even BASIC on the Commodore 64 I vaguely remember playing Dizzy (horrible thought…) used it. Unfortunately there is an enemy of language. This enemy is a crafty nefarious beast who slithers across text editors and IDE’s across the world whispering madness. You will recognise this creatures foul deeds when you happen across something like

if($i == 2)
echo ‘True’, “\n”;
$i = 3;
echo $i, “\n”;

This is something horrific which should immediately be banished to the Netherworlds from whence it crawled.

But there is worse. Much worse. There are horrors whose malevolence may drive you insane, tearing hair from your head and leaving you slumped on your keyboard moaning in fear… There are developers who may resist so much as a suggestion of a flaw…

Therefore I have collated the following rules (dutifully plagiarising some in the blogosphere tradition):

1. A programming language is like any language; use full sentences with correct grammer. Please…

2. An if statement without braces (curly brackets if you’re confused) is an if statement capable of unimaginable evil. Brevity is not an excuse for laziness. And yes, it is lazy.

3. Remember that short tags, asp tags or any other alternative are also evil. Only the most depraved would dare use them. Use

4. Register globals cannot be ignored. In short, don’t rely on them. If you do you shall be punished in unspeakable ways by people whose server leaves it off as a security precaution.

5. If you decide to comment code, than use full sentences. phpDoc generation makes no sense unless comments actually explain the code – not simply summarise it as “My DoThis() function”. All those funny @return, @param and such tags are essential – they’re not optional.

6. depreciated != deprecated

7. Do not mix functions or object methods which do the same thing. It’s annoying, confusing and makes Maugrim a little crazy. Likewise do not mix using a getter/setter with directly accessing a class property – its just as bad.

8. Indent code appropriately. It makes reviewing code a simpler faster process.

9. Always update 3rd party code as required, i.e. whenever the 3rd party releases an update.

10. Never ignore constructive criticism – it’s officially termed “peer review” and considered a good thing.

11. When someone tells you your code contains a security vulnerability, please – do not ignore it for 6 months until someone with access to a major security listing decides to give it a lot of publicity. It’s a bit rude.

12. Never claim you are separating PHP from HTML in an application… Because that’s plain stupid.

I give these in no particularly order, and in no particular category. They are just some things I most often find annoying me when trying to read or adapt code. Some annoy because what they claim to do may differ from what they actually do – particularly annoying when its pointed out and they refuse to update documentation.

Nearly all of these I view as common sense. I’m not above admitting my common sense may differ from someone elses. But from a personal point of view the above 12 points usually capture most things which frequently annoy me when reading someone’s source code.

Twas inevitable…and who is this Norris guy?

After 2 weeks waiting for the bug to bite, it seems the long running progress on Quantum Star SE Evolved has finally stumbled to a halt. On a regular basis I reach points in time where my attention span on a hobby project will simply drop. As of today, I have not really worked on the code to any great degree for a few weeks, and have instead fallen into a backup cycle of planning the next stage of my plan for world domination of the browser game market…as if. Maybe I’ll have a few epiphany moments – always a sure sign the activity is about to accelerate once more. Anyways, until further notice I will not be actively developing QS. The break may last anywhere between a few weeks to a few months depending largely on what I end up doing as an alternative.

I know folk rarely like hearing such sentiments, but I’m not a machine (unforunately :-)) and I need to take a break from projects to let my brain recharge and come up with some nifty new ideas that will re-ignite my enthusiasm. Watch this blog. The project is not dead, Maug just needs to recharge his QS batteries…

In the meantime having recognised the symptoms I have been casting about for a creative outlet. I’m already committed to a performance management module for ADOdb-Lite (still enthusiastic about finishing that off, just held up by TES IV: Oblivion). I’m also thinking about digging around in my fiction notes and pulling together a storyline to build into a Mod for Oblivion. I’ve been kicking around the Silgrad Tower forums to keep an eye on mod developments – and wondering if it would be too embarrasing to add my thick Wicklow accent to the recently formed Oblivion Voice Actors’ Guild group. Maybe would be embarrasing – as much as I can write decent english, speaking it is quite another thing. Looking on the bright side, the hard to quite recognise as english accent may be useful. It’s certainly unique unless the Guild is swarming with fellow Irish.

Morrowind mod making was something I always regretted missing – but in 2002 I was a mere noob on the bottom of the corporate career ladder with an obligation to work attrocious working hours for peanuts. 4 years later and I’m not about to let the fun slide away. I have stories to tell, and a medium to tell them with. More on the mod scene in later posts no doubt after I get a little working experience with the fiendishly difficult object lists in the TES Construction Set.

On a final note, I have found further confirmation that the legendary BNT mailing list does indeed exist. This sanctuary of all things BNT where admission of new initiates is rumoured to involve the ritual sacrifice of a goat, two chickens and an iguana, is rumoured to be the source of the first Chuck Norris Fact. Chuck’s publicist declined to comment stating, “Chuck Norris doesn’t go on the internet, he has every internet site stored in his memory. He refreshes webpages by blinking.”