3 ms·
Brute force. So very often you see programmers spending days or weeks trying to think up an elegant, efficient way to do something that will never ever make a
by taneq 4y ago
Brute force.
So very often you see programmers spending days or weeks trying to think up an elegant, efficient way to do something that will never ever make a meaningful contribution to the footprint of their code. It's one of those traps that becomes more subtle the more skilled you get, so nobody's safe.
Try the simple, obvious thing first. Need to store an arbitrary number of something? Stick them in a vector. Need to find something in an array? Loop through the array. Yes, there are exceptions, but by the time you find one you've already saved the time it took to identify and optimize that one case, ten times over, by not wasting time in the other 99% of your project.