4 ms·
You're distracting form the main topic, which is: > How does a test inform you why a function was implemented using algorithm A and not algorithm B which would
by still_grokking 4y ago
You're distracting form the main topic, which is:
> How does a test inform you why a function was implemented using algorithm A and not algorithm B which would also do the same?
You made up than a straw man saying something something that you assume that both algos get optimized to the same machine code. Which is completely irrelevant to the actual question.
I've only mentioned that both algos need to have the same big-O characteristic obviously as otherwise they wouldn't be interchangeable in the first place.
> What are you sorting? Which algorithm did you choose and why?
LOL, that's exactly the question a good code comments should answer.
Because code can't do that!
The example here is: Big-O is one thing, but "what are you sorting" matters, and some algo may be better suited for the task than the other.
If this isn't obvious it needs to be documented.
The best place to do that is right where the code is. As only this will make sure it will be read together with the code. (Otherwise someone could for example rewrite the code to something "more standard" and it's not a given that the people reviewing the change would know about the reasoning behind the original implementation; a comment would have prevented bugs and regressions in such a case).
Thanks for proving my point… :-)