News for hackers. Stuff that matters.
Re:Why databases use ordered indexes but programming uses ha... by ummonk on Tuesday December 10, 2019 @12:30AM (#21749861)
An ordered map is much better as a default simply because it can do everything that an unordered map can. Choosing to use an unordered map instead is a premature optimization that is nearly always unnecessary.
Re:Why databases use ordered indexes but programming uses ha... by mantap on Tuesday December 10, 2019 @01:09AM (#21750085)
IMO, premature optimization doesn't apply to cases where you are making general decisions about policy or defaults, otherwise you can get into a "death by a thousand cuts" situation where none of your functions are slow individually but the whole program is slow (i.e. big overheads). To me, premature optimization means don't optimize a specific function unless you know it is slow. I'd also say that premature optimization doesn't apply in cases where both alternatives are equally easy to write.
Re:Why databases use ordered indexes but programming uses ha... by mlyle on Tuesday December 10, 2019 @01:28AM (#21750183)
On the other hand, if you pick a TreeMap--- odds are it will be a non-issue either way.

If it does show up on your profiles, it's easy to reconsider and say "I don't think I'll ever access this in order, after all..." and change it and see if you see a benefit.

Re:Why databases use ordered indexes but programming uses ha... by JadeNB on Tuesday December 10, 2019 @09:01AM (#21752458)
> I'd also say that premature optimization doesn't apply in cases where both alternatives are equally easy to write.

I think that premature optimisation applies not only to ease of writing, but even more to ease of debugging.

Re:Why databases use ordered indexes but programming uses ha... by unethical_ban on Wednesday December 11, 2019 @05:56PM (#21767675)
Prematurely optimizing for death by a thousand cuts is what you're proposing.
Re:Why databases use ordered indexes but programming uses ha... by GeneralMayhem on Tuesday December 10, 2019 @12:37AM (#21749910)
That argument works both ways, though.

An unordered map has the narrower interface and generally better performance, so it's much better as the default. Choosing to use an ordered map instead is YAGNI interface bloat that is nearly always unnecessary.

Re:Why databases use ordered indexes but programming uses ha... by kodablah on Tuesday December 10, 2019 @03:37AM (#21750741)
Premature optimization concerns effort. We do a lot of things when writing code that could be considered premature optimization by your vague definition. By this definition too, staying in Java land, I should probably not instantiate my ArrayList or HashMap with a capacity even if I know it...technically premature optimization.

All else equal wrt simplicity, choose the highest performing option that contains the features you need. Dogmatic premature optimization rules are unhelpful. We can apply reasonable thinking, and we should.

Re:Why databases use ordered indexes but programming uses ha... by naasking on Tuesday December 10, 2019 @10:32AM (#21753354)
> Premature optimization concerns effort

And the OP is correct that writing a correct comparison function needed for an ordered map is easier than writing a correct hash function that is properly distributed. So the ordered map is lower effort for that reason alone, although the other properties the OP lists also produce valid reductions of effort.