Hacker News new | ask | show | jobs
by dclowd9901 759 days ago
It's honestly one of the hardest things for me, trying to explain to more junior developers that clever almost is never better. Does anyone have any good litmus or heuristic for figuring out when something is "too" clever?

I was thinking of a way to quantify "complexity" in a process by a sort of "reference counting" style metric, where the moment you have to reference some other location to figure something out, you add 1 to a number and if that number gets above some figure, it's too complex.

2 comments

There's the cyclomatic complexity which I think gets close to your reference counting example.

https://en.wikipedia.org/wiki/Cyclomatic_complexity

But I don't think that captures most of the "too clever" stuff I typically see. That's usually some abomination of a one liner that does way too much. Those won't get picked up by cyclomatic complexity measurements. Furthermore, I find cyclomatic complexity tends to come from less experienced developers rather than experienced developers trying to be clever.

If you're genuinely wondering if something is too clever, ask that junior dev to explain it to you. After all, they will probably be the ones to end up maintaining it later.

If I don't understand something I wrote a month later, it was too clever.

Unfortunately, this is a massively lagging indicator.

Yeah that's the textbook example of closing a barn door after the horse gets out, eh?