2.3 debrief: part 1.
Subtract the number from zero (simplest for the computer) or multiply it by -1 (more complex for the computer)​
Deja Vu. Simplest for the computer? More complex? That makes no sense. Are you saying faster? Does it take less electricity? Produces less heat? What? Do you know what hardware and software stack everyone of the students is using? Do you know how hardware will change in the next 10 years? Just don’t say that.
anecdote 1
I was working on the M1 Abrams Main Battle Tank simulator. The most expensive video game ever made at that time. The game controller was an actual tank turret on caster wheels.
We had an old guy who would look at our code and chastise us on efficiency. Nothing made him more angry than multiplying by 2 instead of using the bit shift operation. After years of getting beaten on for writing code with less than peak efficiency, we made a measurement.
It turns out bit shifting took two orders of magnitude longer to run than multiplying by 2. A little research yielded that the computer manufacturer was bit shifting in software while multiplication was using a floating point accelerator. When assembly language died bit shifting wasn’t used much anymore so why waste the silicon.
anecdote 2
I was at Ford working on a program that calculated the cost of making a single car or truck. It is good to know how much money you make when you sell one.
There was a guy there who thought he knew everything. So much so that he optimized the program to within an inch of its life. Doing that meant that it was also a mess. So many bugs.
It also took over night to run. You start it today to get results tomorrow. Even with the extreme levels of optimization.
But then we had a problem we needed to make a change that would double the run time! We had six weeks. I said no. I am going to rewrite the whole program using Extreme Programming making it the world’s second XP project and validating the method at the same time.
So I rewrote it not to be efficient, but to be understandable. Absolutely no optimisation. It was a Friday when it was done. Time to kick off the final test. I expected it with not just no optimization, but anti-optimization to take all weekend. I hit return and it came back immediately. I checked the output and it was perfect. Premature optimization hurts not helps.
moral
Don’t tell the kids to think about theoretical up front optimization. Coding it to be readable always comes first. You can optimize later when you know it doesn’t run fast enough by making a measurement.
And let me know if I need to write you another book on why we (computer programmers) never say such things.