3

That way lies madness

 3 years ago
source link: https://qntm.org/madness
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

That way lies madness

2010-05-07 by qntm

PHP is well-documented. It is forgiving at first but can be ratched up in strictness. My knowledge of the language gained me my first serious employment and began my software engineering career, and this last point has secured it a place in my heart where it will never be dislodged, if admittedly in an Iron Man sort of way.

But baby, why?

<?php
	class Animal {
		static $dbTable = "animals";

		function printDbTable() {
			echo(self::$dbTable);
		}
	}

	class Bear extends Animal {
		static $dbTable = "bears";
	}

	$bear = new Bear();
	$bear->printDbTable(); # prints "animals"
?>

This has somewhat stymied a reasonably hefty piece of refactoring of this very site's backend, which I had hoped to do this weekend. I was hoping to make it so that the name of the table where a particular class of object, such as a Page or a Comment, is stored, could be reconfigured just by altering a static variable in each class. Unfortunately the Row superclass's retrieve() method, which would need to grab that static variable in order to query the database correctly, can't. It just can't. At all. Oh, and get_class() has the same issue. There is get_called_class(), which is only in 5.3.0 plus. I'm on 5.2.0. I should ask my host to upgrade, perhaps. Or find a programming language which isn't broken.

Just another of the whacking great heap of enraging programming fun which I've ploughed through so far this week. Most of you know I've been hitting the JavaScript quite hard, and most of you will probably therefore not need to be told why that has irked me of late. Here's another which springs to mind, this time a piece of code by someone else which I had to refactor slightly. This is Perl, but the programming language is basically irrelevant because the problem is universal and eternal. Why would anybody write this:

for(my $i = 0; $i < 10; $i++) {

	# code

	if( [condition1] ) {

		# maybe 200 lines of double indented code

		if( [condition2] ) {

			# hundreds more lines of triple-indented code
			# etc., maybe to two more levels of indentation
			# and the first loop was probably indented a bit already anyway

		}

		# no code at all down here
	}

	# or here
}

When something like:

for my $i (0..9) {

	# code

	next unless [condition1];

	# 200 lines of code

	next unless [condition2];

	# hundreds more lines
}

is entirely acceptable? If you're about to say "coding standards", the script in question plainly predates such things. Maybe the original coder is from Single Point Of Exit land. I'm not. Perl has these lovely keywords for a reason. This can be done in almost every other language too, if a little less beautifully.

One more minor riddle which wasn't worth a distinct post. Every few weeks, seemingly at random times and triggered by nothing whatsoever, Notepad would open on my laptop. The problem was so rare and intermittent that I never bothered to look it up. The reason? Dell's touchpad drivers have an additional "feature" which opens Notepad if you hold down three fingers on the pad for more than one second.

This feature is completely absent from the mouse/touchpad settings. I know this having been over every detail of the available options when I first acquired the machine in question. It cannot be configured or disabled. The only way one could possibly know that the feature was there was if you first investigated the specific touchpad driver, discovered that it had been manufactured by Synaptic, and then stumbled onto this page which actually documents this baffling, inexplicable feature.

Meanwhile there are people running around out there who think that they have a virus of some kind! They're running virus scans and upgrading their firewalls. The worst part is how difficult it is to figure out how to reproduce. Whoever even heard of a touchpad which did anything when three fingers were applied? This may be the very first thing I've seen which behaves so much like a bug and yet genuinely is not a bug, but an undocumented feature.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK