← Back to context

Comment by devit

4 years ago

You have to be a terrible programmer to even consider using a base 10 logarithm for this.

Their proposed improvement is also terrible, since it divides multiple times unnecessary, and checks for negativity multiple times unnecessarily.

The proper simple solution is of course a handwritten binary search with if-else blocks that starts with the most likely range, annotated with "likely" annotations, and a single division.

If this is the main task of the program for a while, and thus a large fraction of the cache can be dedicated to it, then solutions with large lookup tables are worth trying (obviously optimizing string formatting is also essential in this case).

This is why software is so often broken, there's a lot of incompetent people programming.

"You have to be a terrible programmer to even consider using a base 10 logarithm for this."

That's not a fair statement.

Good programmers are programmers who deliver value - who build robust, maintainable features in reasonable time that address user needs.

Whether or not you would quickly find the correct approach to this specific problem is a miniscule, pedantic detail in a giant ocean of programming skills and experiences.

You may think that, but I’m partial to the ‘for-loop version’ that everybody and their dog can understand.

About the "terrible" aspect of it, to quote: "Granted it’s not very readable and log / pow probably makes it less efficient than other solutions. But there were no loops and almost no branching which I thought was pretty neat." No need to insult the author over it.

About your "proper simple solution": I don't think that's a good idea either. Based on your next paragraph, the version you suggest with the handwritten binary search and "likely" annotations is for the case where the code isn't performance critical: for where the code is performance critical, you suggest a different solution. If the code isn't performance critical, please do not turn it into an unreadable mess over what would become a negligible overall performance gain. Write it in a simple, obviously correct way, keep it boring, and you'll keep it stable; you can use the time you save on fixing bugs in your super optimised version on improving more critical parts of your program.

Wait. I always use logarithm for this kind of tasks, how exactly does it make me incompetent and terrible? This is literally what logarithm represents?

You're right, however I think they were going for a "branchless" version just to see if they could.