Having done a fair few academic computer science courses and various coding jobs in a past-life I found that it was often thinking about the smallest code snippets carefully that you pick-up the raw building blocks for good, safe and efficient code. I haven’t written much code recently so have been brushing up my basics.
Compilers are now so good and computers so powerful that in practice you can write pretty terrible code and still make a perfectly performant and functional application.
One famous code problem is to swap two numbers without using an additional temporary variable. So you use only the memory already storing the numbers without requiring extra for the temporary variable. Consider…. Continue reading “Code pondering – Number 1: Swapping two integers”