Jun 10
I’m taking some time to tidy things up around here, so I’m coalescing a bunch of one-liners into a single post:
- Smashing Magazine generates linkdump posts faster than I can digest them. This one from April 2008 on creative web form design is one of their best. Lots of inspiration there.
- O’Reilly Radar’s Marc Hedlund on Code Review Software.
- Werner Vogels on Eventual Consistency. If you’re concerned with database scaling and used to thinking in terms of ACID, there’s a lot to mull over here.
- Design Principles and Design Patterns is the clearest description of object composition I’ve ever read. Rather than the standard, 15-year-old “Fido’s a Dog, Dogs are Mammals, Mammals are Animals” object hierarchies you get in Introductory OO texts, it’s a short, readable explanation of how to design objects that are maintainable, extensible and loosely coupled. Really really good stuff.
- A Neat Approach to Narrow Windows. Concept 64’s clever way to deal with varying page widths is firmly grounded in usability. If the page width is >800 pixels, the navigation links style themselves as a left-hand navigation menu. As the page width drops below 800 pixels the navigation links restyle themselves as tabs. Easy to do in Javascript by swapping CSS rules around, but a lot of thought has obviously gone into the design here. [It looks like the site's been taken down (wayback link, no javascript). I'm keeping the link because I hope it comes back at some point.]
- Peterbe’s experiences at the 2006 Google London Automation Test Conference. And… wow, I’m back to 2006 already. I sure don’t post much. Anyway, unit testing is one of those things that I desperately want to use in commercial projects, but when you say to management “I want to spend two weeks writing code that won’t make it into the final application” they get a funny look in their eye. Much the same thing happens when I start talking about user stories. Or the separation of presentation and business logic. Not that I’m bitter, or anything.
May 19
I just spent 10 minutes tracking down this particularly opaque MySQL command:
SHOW PROCEDURE STATUS
Followup. To list views:
SELECT * FROM information_schema.views
To list stored procedures and functions:
SELECT * FROM information_schema.routines
I really should have these bits and pieces committed to memory already, but as most of my job currently consists of fire-fighting in other peoples’ code, I don’t get to use sensible features like SPs and views very often.
Apr 08
I just happened to be up at 3AM, and I snagged a Google App Engine invitation. Neato. Now I need to figure out what to do with it…
Jan 02
http://www.ajaxian.com/archives/mad-cool-date-library
/still laughing
Or despairing. Or something. Honestly, who lets these people walk around loose?
Update: found another one. “Eventually the goal is to save all the functions in one php.js file and make it publicly available for your coding pleasure”.
Ye gods. It must be one of those days. Oh well, I guess it makes for good link bait, if nothing else. “javascript_equivalent_for_phps_array_rand” indeed.
Update2: C# this time - this is why high-level programmers who don’t have a handle on the underlying algorithms can’t do their jobs properly. For the record, there are SortedList vs SortedDictionary discussions all over the net that tell you exactly what the differences are. Even some basic testing would give you empirical data to work with. Gotta say, he’s got some chutzpah to slap auto-refreshing Google and Amazon ads all over that.
Jan 02
API Archaeology. Heh.
If he thinks he has troubles, he should try PHP’s string and array libraries. You can really see the accretion of “thought” there. On a related note, here are some signatures for various PHP error handlers. First, an assert handler:
function assert_handler( $file, $line, $message );
an error handler:
function error_handler( $errno, $message, $file, $line, $errcontext )
How to set an assert handler:
assert_options( ASSERT_CALLBACK, 'assert_handler' )
And an error handler:
set_error_handler( 'error_handler' )
Nobody could get it this wrong by chance. I think it’s wilful.
Nov 26
ERROR 1116 (HY000): Too many tables; MySQL can only use 61 tables in a join
If you ever run into this MySQL error, something has gone badly wrong with your database schema. In this case, the database had no foreign key constraints, and I was trying to build a DELETE query that cascaded across ~230 tables. Not pretty at all.
It didn’t help that there was no documentation and no consistency in key names - id, clientid, client, fkClient, they all referred to the same key in different tables.
After a few false starts, I gave up on doing the deletes by hand; instead I went through the database creating the foreign key constraints that should have been there in the first place. It’s the same amount of work, I end up with a slightly saner database (always leave the codebase better than you found it), and doing the delete becomes a simple “delete clientid”, which cascades through the rest of the tables removing related data.
Oct 26
The new Pragmatic Programmers book turned up today - Programming Erlang by Joe Armstrong.
The language looks like a perfect fit for an SMS platform (unfortunately we’re trying to fight the last war there, but that particular post-mortem is a story for another day), so after one guy at work picked it up he didn’t have much trouble convincing a couple more of us to check it out. At this point we’re just trying to figure out what it can do, but it’s interesting that it seems to be on a lot of people’s radar right now - I keep seeing Erlang references at Reddit and DZone. This is probably an effect of it being a Pragmatic book (they scored a major win with the Ruby books), but I find it hard to believe a functional language could ever grow the way Ruby did.
I ran through the first 20 pages or so tonight, so I’ve got some barely-informed opinions. First, the quality of the book is poor - the layout is amateurish and scrappy, as if it was typeset in Word. The content appears solid, but it looks like a PDF that’s been printed on a B+W laser and perfect bound. Second, the language uses makefiles. Makefiles! I get the impression the tool chain is going to be quite primitive. Third, it’s been a long, long time since I’ve done anything in a functional style (beyond a lingering abhorrence of side-effects, and the occasional array map/lambda function pair to confuse the “HTML programmers”).
We shall see, I guess.
May 08
For a while I was fairly active on the php.general mailing list, mostly answering questions.
Occasionally I come across a problem I know I’ve published a solution to, so I Google my own name plus some keywords to track down my original post.
So I was trying to remember how to pass methods of instantiated classes around as variables, and I came across this.
My name’s buried in the code of DokuWiki, an actual, useful, OSS project that’s used by real people! :) I’m absolutely blown away by this.
And just so I don’t have to chase it down again (I have a real blind spot for this), here is the code I was trying to find (which is pretty much obsolete post-PHP 5.2, but was useful once):
/* Class A has method B */
class A {
function B ($s = "None") {
echo ("
input : $s
“);
}
}
/* $C is an instance of A */
$C = new A ();
/* $D is an array of strings */
$D = array (’item 1′, ‘item 2′, ‘item 3′, ‘item 4′);
/* invoke A::B */
A::B (’call 1′);
/* invoke $C->B */
$C->B (’call 2′);
/* invoke A::B via call_user_func() */
call_user_func (array (’A', ‘B’), ‘call 3′);
/* invoke $C->B via call_user_func() */
call_user_func (array ($C, ‘B’), ‘call 4′);
/* invoke A::B via call_user_func_array() */
call_user_func_array (array (’A', ‘B’), array(’call 5′));
/* invoke $C->B via call_user_func_array() */
call_user_func_array (array ($C, ‘B’), array(’call 6′));
/* apply A::B to $D via array_walk() */
array_walk ($D, array (’A', ‘B’));
/* apply $C->B to $D via array_walk() */
array_walk ($D, array ($C, ‘B’));
?>
Apr 20
PHP is a weakly-typed language. By that I mean that variables are assigned values without regard to variable type, and implicit type conversion at runtime sorts out any conflicts. PHP will happily let you compare a string and an integer, and will make its best stab at doing what it thought you meant.
Given that one of the most important features of PHP is the shallow learning curve, and that it is deployed in an environment where everything is a string, it’s (just) possible to argue that this was a good design decision. It allows you to do things like this:
$option = "5";
if ($option == 5) ;
without getting into lots of tiresome explicit conversion. But the implicit rules are sometimes a little too clever for their own good, and throw up oddities like this:
$a = 'string';
$b = 0;
if ( $a == true && $b == false && $a == $b)
{
echo ('universe broken');
}
What’s going on here? Any non-null string evaluates to TRUE, so the first clause evaluates as TRUE.
Integer value 0 evaluates to FALSE, so the second clause evaluates as TRUE.
A string is silently promoted to integer when compared with an integer. If the string is the ASCII representation of a number (eg $a="123"), it is assigned that value. If it doesn’t contain a number, it is assigned the value 0. So our third clause evaluates as TRUE. Oops…
I routinely use the triple-equals operator (identical) instead of the double-equals operator (equality) now, but it feels and looks like a hack to avoid someone else’s bad design decision biting me. PHP is chock-full of these little oddities. If I remember, I’ll throw up some more.
Recent Comments