3 ms·
> Using a hash table for at most 3 entries is astronomical overkill! I disagree. Simplicity of the code is most vital to avoid bugs, and if a hash table is w
by londons_explore 5y ago
> Using a hash table for at most 3 entries is astronomical overkill!
I disagree. Simplicity of the code is most vital to avoid bugs, and if a hash table is what the language typically uses to represent key value mappings, that is what should be used, for 3 or 3 million items.
Keep the code idiomatic, and only optimize where necessary.
A good implementation of a hash table has a special fast path for tiny runtime sizes.
A good compiler could bound the size of the hash table, and switch out the implementation if its size can be bounded at compile time.
Sure, in this case, it didn't work so well. But the principle of idiomatic code still stands.
- userbinator 5y agoFrom experience, I can say that the amount of times I've heard those arguments also corresponds closely with the sort of code this article is about. If you're using a language where all you have are hash tables (PHP comes to mind), then there's no way around it; but it's insanity to overlook simplicity.