Natural Born Programmers
Smart people are not meant to be programmers.
The human brain is smart and efficient. It can analyse and solve many problems in an instant. Some of them simple and some of them difficult. Most of the simple problems it solves are hardly problems at all. Take the simple problem of distinguishing between odd and even numbers for example? How does the brain do that? Does it lookup its memory or does it process an algorithm to figure it out? To help answer the question, it’s best to think way back to the time when we were first introduced to odd and even numbers. We had no idea what they were back then and our brains had to learn them from scratch. We were told that the numbers one, three, five, and so on are odd, and that the numbers two, four, six, and so on are even. We were taught the fundamental rule for odd and even numbers. All numbers that are divisible by two are even numbers and all numbers that are not are odd numbers. To apply the rule to any number, we simply have to divide the number by two and check the remainder. If there is no remainder then it is an an even number, otherwise it is an odd number. This mathematical approach of applying the rule is easy for small numbers but a little harder for large numbers. Smart people who know this find alternative and efficient approaches. Once such approach involves considering only the last digit of the given number. If it is even then the entire number is even and if it is odd the entire number is odd. In this way the given number is reduced to single digit. Remembering ten single digits and knowing which ones are odd and which ones are even is easy to do, involves no math at all, and is extremely efficient for the smart mind.
Consider the following Java code fragment (a), based on smart human logic
// know what is even and what is odd // (humans store this in memory) Boolean even = Boolean.TRUE; Boolean odd = Boolean.FALSE; // initialise results for numbers 0..9 // (humans store this in memory) Map results = new HashMap(); results.put(new Integer(0), even); results.put(new Integer(1), odd); results.put(new Integer(2), even); results.put(new Integer(3), odd); results.put(new Integer(4), even); results.put(new Integer(5), odd); results.put(new Integer(6), even); results.put(new Integer(7), odd); results.put(new Integer(8), even); results.put(new Integer(9), odd); // get the last digit of the given number // (humans look at the last digit) int lastDigit = Math.abs(givenNumber % 10); // lookup the result // (humans recall the result from memory) Boolean isEven = (Boolean) results.get(new Integer(lastDigit));
Now consider the following Java code fragment (b), based on simple math logic
// perform divide by two test and get result boolean isEven = givenNumber % 2 == 0;
Both of the above code fragments produce the same result but the code in (a) is totally redundant in (b) and the code in (b) is much more efficient than (a). This reinforces the KISS principle and proves that straight out simple code is better than overly smart complex code. Programmers often go to extraordinary lengths to write complex programs to do simple tasks. They do this because they apply smart logic to the code that they write. What is smart and efficient for a human can be redundant and wasteful for a machine. A good program has no redundant logic and is both simple and efficient. It takes good skill to write a good program. Gifted programmers are naturally born with it. Smart programmers have to continuously develop it! This is not to say that smart programmers are not good programmers. They just have to work a lot harder to be any good at it.
What do you think?
- Do natural born programmers exist?
- Are smart programmers the best programmers?
- Do good programmers have simple minds?