PHP, Zend Framework and Other Crazy Stuff
Archive for April 18, 2006
The perfmon thing I have yet to finish
Apr 18th
Catching up on my email I found a request for details about that overdue adodb-lite module for performance management. One of these days I’ll simply forget to check my email for a few months and everyone can live on in darkness and despair.
I might have peace thereafter…
Anyways, the module still progresses at a snail’s pace. As I said here on the blog before I was expecting to be taking time off PHP development (except for adodb-lite perfmon). Since my last update on the subject I have fixed a few issues I was having. I also updated the HTML output to XHTML 1.0 Transitional (complient but for 1 error). I also renamed a few function calls and standardised others. I have been testing on MySQL 4.1 and 5.0 and it seems to work just fine. I have not tested on PostgreSQL so that’s next on the agenda.
Before I continue I need to port the work to date to the newest ADOdb-Lite version which was announced with changes which may alter how its included. Not sure yet – so something for a future post. I have decided not to separate out the presentation elements. It’s too much work, and would require a fairly large overhaul – even in comparison to what I’ve adapted to date.
The only bug I know of at the moment (without intensive testing) is a failure of the SQL Log pages to run EXPLAIN commands on logger queries. It offers a blank page with a standard footer but no error message (for non-SELECT statements) or explanation for SELECTs. Probably something small that got passed over while cleaning up the class. Maybe if progress inches too slowly I’ll just make a test release in case anyone’s interested in peer review and feedback.
Programming is a language – use it correctly
Apr 18th
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.
