Hacker News new | ask | show | jobs
by chhickman 1863 days ago
This is perhaps going to be an unpopular sentiment, but I think far too much breath is wasted on the "don't be clever" edict. No examples even spring to mind of any past experience where I ran into someone's "too clever" code causing me headaches. It has been dealing with the mountains of "not the least bit clever" code that has sucked thousands of hours out of my career. Mundane, "straightforward" code where they've re-used variables for different purposes, or deeply nested conditionals with multiple, multiple booleans in each check (often redundant, if not contradictory) and generally taken 50 lines of code to accomplish what could be done more cleanly in 10 or fewer. I'll take puzzling a few minutes over some too clever code over slogging through spaghetti code any day.
2 comments

From your description it feels less like an issue with the code not being clever enough and more like an issue with the code not being organized and architected efficiently.

I think the "don't be clever" edict applies to code segments that are best described as "you won't believe what happens next!", and fairly so.

imo unclever code != poorly designed / spaghetti code

Reusing variables in a way that is confusing is a code smell, and rather than being "unclever", I would characterize it more as just "bad".

In my mind, an example of code that is "too clever" looks more like this:

  while (*dest++ = *src++); 

Unless you've seen that exact pattern many times, when trying to understand it you will have to unwrap it in your mind into something that looks more like the longer, "unclever" version anyway.