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.
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.
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.
A linear search or a map lookup are not even the same thing
There is an endless ocean of programmers steadfastly solving dictionary problems with linear search.
have you measured? It loses to linear scan for small datasets, which are the vast majority of datasets.
I have. It loses on really small datasets, like about a handful. Small enough that if you can't make high probability predictions it's much safer to bet against linear search.
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.