Combing The Net

As usual, stuff I've spotted but have been too busy to properly comment on:

Framing Things The Right Way

One of the coding catchphrases I retained from Lisp (yeah, I did my time counting parenthesis too) was "lists are everything, and everything is a list" (purists can complain about atoms to /dev/null). So, when I decided to improve my photo section's look with a nice frame and alpha-blended shadow (background colour had to be adjustable, of course), I thought nothing of drawing a shadowed square, chopping it into PNG sections with an alpha channel and doing this:

$hNewImage = imagecreatetruecolor( $nNewWidth, $nNewHeight );

$aBackground = hex2dec( $szBackgroundColor );
$hBackground = imagecolorallocate( $hNewImage,
$aBackground['b'] );
imagefilledrectangle( $hNewImage, 0, 0, $nNewWidth, $nNewHeight, $hBackground );
imagealphablending( $hNewImage, true );

// Frame Element List
// dstX, dstY, dstW, dstH
$aCorners = array( "frame_tl.png" => array( 0, 0, 16, 16 ),
"frame_tm.png" => array( 16, 0, $nNewWidth-32, 16 ),
"frame_tr.png" => array( $nNewWidth-16, 0, 16, 16 ),
"frame_ml.png" => array( 0, 16, 16, $nNewHeight-32 ),
"frame_mr.png" => array( $nNewWidth-16, 16, 16, $nNewHeight-32 ),
"frame_bl.png" => array( 0, $nNewHeight-16, 16, 16 ),
"frame_bm.png" => array( 16, $nNewHeight-16, $nNewWidth-32, 16 ),
"frame_br.png" => array( $nNewWidth-16, $nNewHeight-16, 16, 16 ) );

$aCorners as $szFile => $aParams ) {
$hCorner = imagecreatefrompng( $szFile );
imagecopyresampled( $hNewImage, $hCorner,
$aParams[0] - 1, $aParams[1] - 1, 0, 0,
$aParams[2], $aParams[3], 16, 16 );
imagedestroy( $hCorner );
imagecopyresampled( $hNewImage, $hImage, 15, 15, 0, 0,
$nNewWidth - 31, $nNewHeight - 31,
$nImageWidth, $nImageHeight );

A friend of mine who teaches at college looked at the foreach loop and $aCorners and despaired. According to him, not a single kid in the programming class he teaches (we're talking 4th year students, the kind of people one year away from having to code for a living) would even consider approaching the problem like this. "They have no grasp of data structures, and would probably have cut and pasted eight imagecopy calls."

I was dumbfounded, since it is such a trivial approach.

According to him, cut-and-paste programming and "instant gratification editors" (just for the record, they are using Visual Studio) are killing the reasoning involved in solving problems, because it's easier to cut and paste "dumb" code than actually type out code to properly handle complex data structures.

"Kids click around in the class browser and think it natural to have skeleton code there waiting for them", which, according to him, makes them totally ignorant of why the skeletons exist or how they interact, let alone design data structures to handle the problems.

I won't go as far as to concur with him that application frameworks and GUI editors should be held back from students (if they can use them properly, they should be allowed to), but I am worried that we might be creating a whole generation of half-baked programmers by making some things too easy.

Or am I just becoming an old fogie?