, 1 min read
Evil abbreviations in programming languages
Programming language designers often abbreviate common function names. The benefits are sometimes dubious in an era where most programmers commonly use meaningful variable names like MyConnection
or current_set
as opposed to single letters like m
or t.
Here are a few evil examples:
- The C language provides the
memcpy
function to copy data. The clearer alternativememcopy
requires one extra key stroke.1- To query for the length of an object like an array in Python and Go, we use thelen
function as in len(array). The expression length(array) would be clearer to most and require only three additional characters.- Though most languages use the instructionif
or the equivalent to indicate a conditional clause, when it comes to “else if”, designers get creative. Ruby uses elsif, helpfully saving us from typing the character e. Python uses elif, saving us two key strokes. PHP alone seems to get it right by using elseif.- In Python, we abbreviate string to str. Most languages seem to abbreviate Boolean as bool.
I am not opposed to a judicious use of abbreviations. However, by going too far, we create a jargon. We make the code harder to read for those unfamiliar with the language without providing any benefit to anyone. Let us not forget that source code is often the ultimate documentation of our ideas. Credit: John Cook’s comment on G+ inspired this blog post.
Update: Commenters point out that memcpy
had to be shortened due to technical limitations restricting the length of functions to 6 characters in the old days. Fair enough. However, common C functions that use more than 6 characters also look like alphabet soup: fprintf, strcspn, strncpy, etc.