3 ms·
> Clever code isn't usually good code. Clarity trumps all other concerns. I'm glad I'm not the only one who thinks this way. I've had countless arguments with
by woutr_be 6y ago
> Clever code isn't usually good code. Clarity trumps all other concerns.
I'm glad I'm not the only one who thinks this way. I've had countless arguments with colleagues about this, and they always made it seem like I was the crazy one for thinking this.
They would often optimize or use clever tricks in their code, to the point that unless you asked that specific engineer, nobody would understand it. In most cases, the performance benefits you get from that don't outweigh the negative impacts.
- xmprt 6y agoClever code that's actually significantly faster is fine as long as you document every single thing that's clever about it, even if that means writing 20 lines of comments for a 2 line function. The worst thing is someone who writes a clever one liner without any comments because that would "ruin" the elegance of the one liner and because their code is "self-documenting"
- woutr_be 6y ago> The worst thing is someone who writes a clever one liner without any comments because that would "ruin" the elegance of the one liner and because their code is "self-documenting" Sadly this was some of my colleagues, no documentation and clever one liners without comments and often obscure naming conventions. And again, we didn't need the performance benefits for our use case. I think in the end it was just a play to keep some people employed, because without them we wouldn't be able to work on this part of our application. Sadly for them the business decided to outsource and they ended up being forced to switch teams.
- njharman 6y agoFaster code is not fine. Faster code should only be written after finished product is shown to be too slow for purpose and after profiler has shown which parts of code are worth optimizing.
- username90 6y agoYou should always have a good idea of what part of the codebase will be the bottleneck when you write it. If you have that just optimize the things it spends time on. The only time you really need a profiler before optimizing is when you are micro optimizing to try to handle cpu ordering etc, other than that performance is mostly predictable.
- meheleventyone 6y agoThis can be too late for the product though. If you have real performance requirements for example you’re making a game and it needs to render at 60Hz optimising at the end can be an impossible task. This is also further complicated when data dependencies also impact performance. For example level designers need some understanding of the complexity of the scenes the game will be able to support.
- kyberias 6y agoUnit test that documents the required functionality of code helps a lot. After that, one can refactor the code with all kinds of cleverness.
- woutr_be 6y agoI'm not sure if I agree with that, unit tests would help document what code does. But it doesn't help when you're reading through code. It's also important to understand how your code does what your unit tests document.
- mbeex 6y ago> and they always made it seem like I was the crazy one for thinking this. Ask them a specific question about their code three months later.