3 ms·
Writing simple programs that meets requirements should be your goal. Premature optimization is the root of all evil.
by smegel 9y ago
Writing simple programs that meets requirements should be your goal.
Premature optimization is the root of all evil.
- rdiddly 9y agoSimplicity is great when it's not borne of ignorance and when it doesn't over-simplify. Some things are unavoidably complex. Even the word "simple" is complex, and has many meanings. What if simple is defined as... - relies on simple "Programming 101" concepts - doesn't require using or learning a framework or library - corollary to above, doesn't require ascertaining that said framework or library implements a .Get() method - doesn't rely on anyone else's code and has no dependencies or references - doesn't require understanding ancillary concepts that might be present such as hash tables Then writing the loop is "simpler." To answer your original question. And just to turn things completely topsy-turvy, how about your .Get() method. If it's implemented the way such things are usually implemented, that means it uses hash tables and is very efficient. But that means it's a premature optimization, right, and therefore the devil? (Well we haven't defined "premature" either.) The real answer is to think for yourself like a grown-up and don't rely on dogma. Every situation is different; tackle every problem by optimizing for what's important in that specific problem, using whatever resources and minding whatever constraints apply to that specific problem.
- djur 9y agoSelecting appropriate data structures and algorithms for a problem is not optimization. It's one of the basic skills and responsibilities of a programmer. That's why the bulk of the first volume of Knuth's _The Art of Computer Programming_ is about data structures.
- wtetzner 9y agoUsing the Set interface is probably the right thing. Then you profile, and if the set implementation you chose is too slow, you just swap it out for another implementation that implements the Set interface.