What's your favorite line of code?

daniel13rady profile image Daniel Brady Updated on ・1 min read

Abstract answers and actual code snippets are both welcome 😄


Editor guide

My favorite lines of code is those which saves me typing and makes my code cleaner. Like:

global log = console.log

Over the time that line grow to a full module, but I think that saved me hundreds of console dots.


I love doing things like that with my output statements! It lets me swap out the implementation or even disable output entirely without modifying every log statement in my code. 👌


To be honest, that line was later refactored to:

global.log = function (...p) {

log.data = []
log.console = console.log
console.log = log

To create a log history to be flushed later, and redirect all console.log() to log(). But lost a little bit of its beauty.


Maybe not the most elegant example, but this line in Cloud Foundry's deprecated v2 API let us implement rolling "no downtime" app deployments on v3 without breaking the legacy stuff.

It basically let have more than a single "web" process for an app at a time, but let v2 continue to only concern itself with the newest.

The beauty of Ruby is that we could mix it in to all of the v2 controllers that needed it!


A wise old wizard I used to work with once said,

My favorite line of code is the one I get to delete.

It's taken me a few years, but I've finally caught on to that appreciation.


And a wise old wizard I currently work with offers up a bottle of Scotch during our company's annual Hackathon to the dev who creates a PR which deletes the most code while maintaining bug-for-bug compatibility without adding new code. 😍😅


My favorite line of code is that I will never delete, because is perfect and cannot be replaced.


That sounds great, but I'm not sure I'll ever be good enough to write a line of code that never gets modified before being deleted. Seems like a good goal to strive for!

Sorry for the 'never'...

I mean, a line of code to be "perfect" must:

  1. Solve the problem
  2. Be reliable
  3. Be easily tested or (pardon the heresy) dispense testing
  4. Be as terse as possible
  5. I can forget about it.

But my really favorites, "the perfect ones" are those that beyond that, yet saves me the typing of another lines. :D