Sunday, October 28, 2012

Reading the PHP manual...

Today I decided to read as much of the PHP manual as I could.  While working through examples, multiple times the thought "coding horror" came to mind.  But I can't afford to be that kind of snob can I?


I finally hit a language "feature" where variable names can be created by other variables.  They are called "Variable variables".  So if a script assigns a string to a variable $a:

$a = "horrifying";

that string can become the name of another variable:

$$a = $a." is as ".$a." does.";

It can be referenced as ${$a}.  Or it can be referenced as $horrifying.


Did I mention coding horrors?  Can anyone explain a legitimate use of such a construct?  What drove the language to put it in there in the first place?

This language feature reminds me of the first assembly language code I wrote in High School, on a Sharp PC-1500 Hand-held Computer.  [I had to use POKE commands to enter the ASM code in by hand - there wasn't any assembler.]  What was cool was that the code was self-modifying!  It wrote to a relative address in the code itself to increment a comparison, and change the minimum pitch of an oscillating tone.  At the time, I didn't know that self-modifying code was a bad idea.  It was just pretty cool how it all worked to make a wah-wah- gaming sort of sound.  And I could brag about it to whoever understood what I was talking about.


So web-searching for "coding horror PHP" yields no shortage of blogs complaining about how bad a language PHP is.

My theory at the moment, is that this is fine.  Really bad code can continue to be generated, and there is no shortage of enthusiastic 14 year old's out there to wade through it all.  For the price of 1 experienced engineer, you can hire 10 teenagers instead.  They won't know why the above example is a bad idea - they'll think it's really cool.

This gives me great pause at considering any work prospects involving PHP coding.  As a good friend of mine once advised: 

"Always read the whole prospectus before making any investment."

1 comment:

  1. The underlying premise: "Do the thing right."

    http://www.youtube.com/watch?v=C2hSJOS9pks

    Even if you can meet product requirements with a bad architecture, it will still be difficult to maintain or modify when needed.

    Also, the term "coding horror" comes from Steven McConnell's MUST READ book Code Complete http://www.amazon.com/exec/obidos/ASIN/0735619670/codihorr-20

    ReplyDelete