How to Speak Like a Geek
Lets look at a second snippet of code:
if(X >= Y) {
Z = X;
}
else {
Z = Y;
}
This snippet of code takes two numbers and returns the maximum of those two numbers. If we pronounce this snippet of code, we get something like, “If X is greater than or equal to Y, Z equals X, else Z equals Y”. The code is simple, but the pronunciation is verbose and confusing.
There are three problems with this trivial piece of code. First, the pronunciation of the assignment operator and the comparison operator are the same which is confusing. Second, In order to determine whether “Z equals X” is a comparison or an assignment, you need to evaluate the context of the statement. There is no explicit marker between the two parts when you pronounce the code. Third, the pronunciation of the conditional clause is needlessly confusing and verbose.
Lets see how we can do better.
Back in the olden days of Pascal, “=:” was the assignment operator and “=” as the equality operator. That is all well and good, but how should we pronounce ‘=:’? Pronounce the assignment operator as ‘becomes’ and the equality operator as ‘equals‘. The word ‘becomes’ embodies change, motion, and dynamic action. It is very clear that an action is taking place. If we change the pronunciation of assignment, it becomes more clear that we are in the body of the if statement. With that small change, we would say “If X is greater than or equal to Y, Z becomes X, else Z becomes Y”.
That is better, but there is no clear delineation between the test and the body of the if statement. To clearly mark the end of the test and the beginning of the body of a conditional statement, say ‘then‘. So, we would say, “If X is greater than or equal to Y, then Z becomes X, else Z becomes Y”. Closer, but that doesn’t really flow properly. Pronounce ‘else‘ as ‘otherwise‘. “If X is greater than or equal to Y, then Z becomes X, otherwise Z becomes Y”.
Lastly, and perhaps most importantly, we need to clean up the comparison clause.
When you were taught multiplication in elementary school, your teacher might have taught you that 3 X 4 was the sum of three groups of four, but that isn’t how you evaluate multiplication in real life. That was useful in teaching the concept, but doesn’t do much for facilitating its use. Similarly, you were taught three comparison operators: less than, equals, or greater than, and then you were taught these could be combined into other operators so ‘>=’ meant greater than or equal to and ‘<=’ meant less than or equal to and maybe even ‘!=’ meant not equal to. These terms were used to help you understand the concept, but they don’t lend themselves to reasoning with them. These terms are unwieldy when using them for reasonsing. Make all comparison operators their own first class operators.
- >= means ‘at least’
- <= means ‘at most’
- != means ‘differs from’
- > means ‘greater than’
- < means ‘less than’
- = means ‘equals’
This might seem like a minor detail, however in complex expressions, it makes a significant difference. If we use our new rule in the pronunciation of our code snippet we have “If X is at least Y, then Z becomes X, otherwise Z becomes Y.”
Lets compare our original version:
“If X is greater than or equal to Y, Z equals X, else Z equals Y.”
with our final version:
“If X is at least Y, then Z becomes X, otherwise Z becomes Y.”
November 13, 2011
Posted in: Programming


Leave a Reply