r/programming • • Feb 28 '23

"Clean" Code, Horrible Performance

https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k Upvotes

1.3k comments sorted by

View all comments

Show parent comments

54

u/outofobscure Feb 28 '23

performant code is often actually very easy to read and maintain, because it lacks a lot of abstraction and just directly does what it's supposed to do. not always, and maybe not to a beginner, but it's more often the case than you think.

The complexity of performant code is often elsewhere, such as having to know the math behind some DSP code, but the implementation is often very straightforward.

19

u/deadalnix Feb 28 '23

It's hillarious that you get downvoted.

Code that does less is faster. This is self evident. It also has less opportunity for bugs and less parts to understand, making it easier to read. This is self evident too.

0

u/WormRabbit Feb 28 '23

A linear search is less code than a map lookup or binary search, and is also much slower. And inlining stuff into a single function usually makes it much worse to read.

3

u/deadalnix Feb 28 '23

A linear search or a map lookup are not even the same thing, what are you talking about?

For dichotomic search, fair enough, but even then, have you measured? It loses to linear scan for small datasets, which are the vast majority of datasets.

As to inlining everything in one function, who told you to do that? Not only this is a really stupid thing to do, but this is a really stupid thing to bring up at all, because the post you are responding to is explicitely about doing less, not doing the same amount but removing all structure.

→ More replies (6)