Sync’ up! … without getting drained

mar 8

Please, kill your darlings

‘Your scientists were so preoccupied with whether or not they could, they didn’t stop to think if they should.’

―Ian Malcolm from Jurassic Park

Quick, what does the following line of Ruby code do?

@sentence = @sentence.split(' ').map!{|x| x = x[0..0].upcase << x[1..-1]}.join(' ')

I have seen my fair share of source-code, and it’s common to see code like the above; code I fondly refer to as ‘the programmer’s darlings.’

Thanks to user-friendly languages, it’s trivial to pack tons of functionality in a line or two. Many us do it; perhaps it makes us feel like we have superpowers.

However, it takes superpowers to understand such code.

So, why do we do it?

It’s as if hackers want to flaunt their bright colors to the pea-hens. Perhaps we want to say: ‘Isn’t it amazing what I can do with this language?’

A request

It’s not fun to deal with ‘darling’ code — neither that which we ourselves have concocted, nor the ‘darlings’ of others. Darling code is hard to read, makes it hard to re-factor, and if there are errors in any one part of it, the next coder has to break it apart (yes, rewrite it) to investigate what’s not working.

From one hacker to another, I implore you, ‘kill your darlings’ before you check-in that code. Show off skills some other way. In the long-run, the glitz of such code just wastes time & brain cycles.