August, 2009

Archive for

Stuff I Like that You Should Too: Hacker News

hn Stuff I Like that You Should Too: Hacker NewsThe use of “hacker” in Hacker News is the broad, old-school definition, of which computer security is only one subsection.

Hosted by the tech startup venture firm Y Combinator, it should be no surprise that Hacker News has plenty of stories about tech startups, as well as programming and other “hacker” topics.

It’s become my go-to daily tech site. I still check Slashdot semi-daily but have long ceased taking part in the conversations. I recently started reading Reddit, though mostly just the programming page (or “Progit”), as there’s a lot of dumb stuff in other Reddit sections. But HN is better than any of those at aggregating stories of interest and sparking conversations with high signal-to-noise ratios. HN discussion threads are extremely no-nonsense and lacks that “in-joke” atmosphere of those other sites.

Stuff I Like that You Should Too: Movin’ the Chains on SIRIUS NFL Radio

sirius nfl radio Stuff I Like that You Should Too: Movin the Chains on SIRIUS NFL RadioI love SIRIUS NFL Radio. The shows on SIRIUS NFL Radio and the availability of radio broadcasts for all NFL games is the prime reason why I have an XM subscription, despite having more podcasts & music on my iPod than I could possibly listen to. I remember in past year, traveling during the NFL playoffs (they take place during the holidays, after all) and trying to listen to games on static-y AM radio stations. No more. In two of the past 3 years, I’ve had to travel during the draft, too. SIRIUS XM and SIRIUS NFL Radio ensure I can keep up with the NFL while I’m stuck in my truck.

But one particular SIRIUS NFL Radio show stands above the rest. It’s Movin’ the Chains, with Pat Kirwan and Tim Ryan.

pat kirwan Stuff I Like that You Should Too: Movin the Chains on SIRIUS NFL Radio

Pat Kirwan

TimRyan inside1 Stuff I Like that You Should Too: Movin the Chains on SIRIUS NFL Radio

Tim Ryan

Ryan was a defensive linemen for the Bears in the early ’90s. Kirwan’s career went from scouting to assistant coaching to director of players administration (contract / salary cap guy) for the Jets.

Their show is geared toward the fan that wants to understand how offensive and defensive schemes work, how contracts and the salary cap actually work, etc.  They’re not the ones who talk about Michael Vick all day.

They pride themselves on making their listeners think like GMs and coaches. It’s the kindof in-depth football eye that is sorely lacking in sports media.

Movin’ the Chains airs from 3-7pm Eastern (12-4pm Pacific) Monday through Friday, and re-broadcasts again late at night.

Unfortunately, it misses both my commute hours, but I get to listen at lunch, and online at my desk.

Testing Twitter Tools

Testing

The Aftermath of Dan, addendum

One thing I forgot to include in the previous post:

Either Dan never had our MySQL server’s root password, or he lost it along the way. You’d think he’d, I don’t know, ask someone for it, but no. So, instead of creating new databases for each new site (which he was unable to do without root or another privileged user), he just jammed all the tables for whatever new site he was making into an existing database that he already had access to. So we’ve got a database that’s for a registration page for some corporate event in 2007 (and is named as such) that is packed full of tables for a whole mess of other sites.

*sigh*… yeah…

The Aftermath of Dan

I work for a small design studio. Their core business is creating logos, designing signage for corporate events, and all that jazz. Over the past few years, they’ve found clients wanting more and more electronic-based content from them. First it was email blasts and static websites, then they wanted websites that did more than just serve up static content, and pretty soon it became web applications and even small desktop applications. Hence the creation of the job which I now fill.

I wasn’t the first one to fill the job. A couple of guys came before me. My immediate predecessor, we’ll call “Dan”. Dan was not particularly beloved. On the contrary, it was those oh-so-important “people skills” (or lack thereof) that led to his, shall we say, unscheduled exit from the position. My first week on the job ended with me getting the raise that would have been saved for after my 3 month performance review, helped in no small part to solving problems in that first week that had been long-standing issues. Most importantly, I was Not Dan.

I recently read a cute little article linked on Hacker News and reddit: Signs that you’re a bad programmer. A lot of these can be applied to the code Dan left behind. Particularly, #2: “Poor understanding of the language’s programming mode”, and its first symptom: “Using whatever syntax is necessary to break out of the model, then writing the remainder of the program in their familiar language’s style”.

Dan apparently got started as a FORTRAN programmer back in the day. It’s clear that he never really understood PHP. One of the most contentious parts of PHP development is mixing PHP code alongside HTML markup. Whether the HTML is separated out in templates, mixed with inline PHP, stored entirely in echo statements or HEREDOCs, or even just written there in the file after “jumping out” of PHP mode, there’s a number of ways to approach the issue of PHP’s coexistence with HTML markup.

Unfortunately, the language’s flexibility means approaches like Dan’s are possible. Dan clearly never quite wrapped his head around the practices I mentioned above. Instead, his concept of HTML within PHP was to wrap all HTML generation inside of tiny PHP functions. Here’s an example:

startTable("725", "0", "", "id=addTable");
 startRow("center","2","","","noPad");
 if($assId) {
 displayButton("Update Record", "what");
 } else {
 displayButton("Add Job", "what");
 }
 displayButton("Reset", "what", "reset");
 endRow();
 startRow("center","2","","","","top");
 echo "<b>Attach File:&nbsp;</b> ";
 displayFormItem("file", "fileNam");
 displayButton("Upload", "what");
 endRow();

This generates the HTML:

<table width="725" id=addTable border="0" cellpadding="0" cellspacing="0">
<tr><td class=noPad align=center colspan=2>
<input type=submit name="what" value="Update Record">
</td></tr>
<tr><td align=center valign="top" colspan=2>
<b>Attach File:&nbsp;</b> <input type=file name="fileNam" value="">
<input type=submit name="what" value="Upload">
</td></tr>

Yes, instead of simply writing the HTML, everything is stuck in a function. “endRow()”, for example, is literally nothing more than an echo statement for “</td></tr>”. Every tag related to HTML tables has a function, some of which accept a ton of possible arguments for every possible thing you might want to put into that tag (a CSS class, id, border, inline CSS, etc). startRow() takes up to 7 arguments. Reading Dan’s awful code means needing to remember what those arguments are (and what order they’re in), as opposed to simply reading the very clear HTML that they spit out. What are those blanks for arguments #3 and #4 for in the startRow on line 2?  They’re some potential <td> attributes (because, despite being “startRow”, the function echoes <tr> with no attributes, and then echoes the first <td>, and all these attributes belong to that first <td> tag). In this case, they’re attributes that aren’t being used. Which attributes? Who knows? You’d have to go look at the definition of startRow. (Also note: this isn’t a worst-case example. This is a pretty tame example of the kind of crap Dan did like this.)

PHP can be useful in HTML generation – using Zend_Form from the Zend Framework, for example, can be very handy for creating forms with validation. Dan, however, wrapped trivial HTML into PHP functions, providing absolutely no additional value of their own, while unnecessarily increasing complexity and destroying readability.

That’s not the only gift Dan left behind, of course. Relative paths seemed to confuse Dan greatly. That meant the use of a lot of unnecessary absolute paths. It also meant that Dan would take his “lib” folder, which stored all his library code, and copy it into subdirectories so that the relative path “lib/” would still be valid, as opposed to using  “/lib/” or “../lib/” (or, on the HTML side, the <base> tag. Dan and <base> have never met.)

These are just immediate things I ran into today, when fixing some old Dan code. It should come as no surprise that, even ignoring the “WTFs” like these, Dan Code ™ is pretty bad code. None of it is shocking enough to be TheDailyWTF material, but it gets a small moment of recognition here today.

Now I hate Dan too.

(Side note: one of the most frightening parts of entering the work force was doing so with no professional programming experience. I’d been writing code nonstop since entering college, but it was a constant flurry of jumping from language to language, paradigm to paradigm, and no settling in and mastering one development technology. That’s a good academic approach, as it breeds the ability to rapidly pick up new technologies, and develops an understanding that separates a concept from its implementation in a specific language… but it’s no fun to then go out and see job postings wanting X years of experience all centered around one language. That blow is softened when, even in your greenness, you’re still better than the guy that was there before you.)