Posts Tagged with "php"

Simplicity Rules the Day

February 27th, 2007 at 9:16 pm by Mark
Tags: , , , , , ,

     Before I start this little rant, I just wanna say, this is not to ridicule Chris — he’s certainly worth his salt.  This was just an example — and a rather basic one, at that, given that this was more of an oversight than a faux pas — of something that’s been getting on my nerves for years.

     Every once in a while, someone’ll do something, semi-cool with a piece of software, but their execution makes it appear that they’ve forgotten why a given function works the way it does.  It happens a lot these days, and I’m glad I’m old enough to remember “why” things are like they are.

     A case in point — and Chris is a brilliant guy, mind you, and again, I’m not bashing him — was the beginnings of a WordPress plugin (blog software, for the initiated) to show extra formatting buttons in the Text Editor.

function st_addAdvanced($buttons) {
    unset($buttons[22]);
    array_push($buttons, ‘wp_adv’);
    return $buttons;
}

     It’s a pretty elegant little function.  It takes an array called $buttons, and changes the last value to ‘wp_adv’ and returns it.  Unfortunately, it makes things look ugly because of the way the $buttons array is used elsewhere in the code.
     He says, “Ahh, there are some formatting issues to take care of.”

     I’ve always had this bizarre K.I.S.S. approach to programming anyway.  I mean, hey, why bother calling two other functions, unset() and array_push() when I can do what I need with a single, local variable?

function st_addAdvanced($buttons) {
    $x=$buttons[21];
    $buttons[21]=’wp_adv’;
    $buttons[22]=$x;
    return $buttons;
}

     Sure, I could’ve used two, and said, “$a=$buttons; $x=a[21]; $a[21]=’wp_adv’; $a[22]=$x; return $buttons;” to save keystrokes…. but… I’d be wasting as much memory as I gained CPU by foregoing the functions.

     But that’s basically my argument about most Developers these days.  It’s a pretty serious can of worms for me to open, because I know I’ll have developers coming from all over to tell me I’m full of it…  Even though I was writing Assembler before their parents ever met, and have some pretty cool — working, useful, debugged — software under my belt…. Joke ’em if they can’t take a f… *shh*

     Seriously, it’s no wonder our CPU and Memory requirements are so ridiculously high these days.  There’s an API or a DLL or a Library for freaking everything!  Layers upon layers, upon more layers, with repositories and snippets and widgets and scripts galore!

     Our Universities teach this method, often telling people, “Do it this way!” without telling people “Why it should be done this way.”  The “simpler” things get, the more abstract they become.
     They’re not churning out programmers and problem solvers.  They’re churning out memorize-and-regurgitate linkers who can’t write code without the assistance of a Visual Integrated Development Environment.

     Hey … Wasn’t the whole point of all this Link Library, Visual garbage to make software development easier?  Faster?  More bug free?

     I used to sit down with vi, edit or Notepad and it’d take me a couple of days to write a program.

     I can use all these neato-keen, new-fangled hooks and VIDEs, and it’ll still take me a couple of days to write a program…
     But it might take weeks to debug.

     Most developers do the same thing… And spend a lot of time setting up their VIDE.  Or getting a bit of code they copied off the internet to work.  Or…

     But, hey … I’m probably full of it, right?

     As employers, educators and policy makers, we need to get back to basics.  Yes, teach how.  But teach why, as well.