Don't be sloppy while coding
"Don't be sloppy please".
This is the advice I give during a code interview, and this is the attitude every programmer has to avoid every day at work. Usually writing efficient code takes the same time to write inefficient code. Look at the following snippet (c++ code):
for (int i = 0; i < 10000000; ++i) {
v.push_back(T(i));
}
writing the following instead doesn't take longer
const auto mySize = 10000000;
v.reserve(mySize);
for (int i = 0; i < mySize; ++i) {
v.emplace_back(T(i));
}
I already ear someone claiming that the second snippet involves more typing. This is usually one of the argument people puts on the table, as if the bottleneck in coding are the key-strokes.
One argument also is the D.K. quote
premature optimization is the root of all evil
note that doesn't mean you need to be careless while coding and I believe it's used as a lame excuse for being lazy.
The real issue is that some time programmers do not know how the hardware or the operating system works, memory operations are free, the cache is a myth, the big O complexity is just something seen in books while in college. Sometime the very same programmers are claiming they care for the environment. CPU cycles aren't free, if you care for the environment then you need to aim for efficient software, faster simulations mean less energy spent to get the same result, less servers needed in the datacenter to permit all students to do their work, less recharge cycles for our mobile phones and so on.
Some time the "excuse" is:
My boss prefers to spend money in better hardware than in salaries to optimize the software, CAPEX anyone?
Every time I ear this my Software Engineer core dies a bit because that's actually true, some one prefers, for real, to buy new hardware than fixing the code inefficiencies.
I understand that, some time indeed programmers spend too much time in optimizing. Note that optimizing and write efficient code is not the same thing, spending days to choose the best algorithm, spending days to go for ASM is not exactly the the right thing to do.
The second snippet of code above is not optimized code it's just reasonable code to write while the first snippet is just utterly bad code.
So please do not be sloppy at work and save some baby dolphin.
This is even more important with mobile development. Most devs lean on the latest hardware to test performance, but when you run it on lower end handsets, all the kinks come out.