Friday, January 20, 2006

What's in a function name?

When a computer language is created, what guides the choices made for command names? One might hope it would be easy of writing and reading, but sadly not in the case of most scientific software.

Most of these systems have roots that pre-date modern desktop computing. What makes modern computers different? Speed and capacity. It's capacity that has had lasting effect on language design.

Why did Maple invent a new word "int" to express integration and Matlab invent "quad"
while Mathematica used an existing word "Integrate"? The answer is 3 bytes in Maple, 4 bytes in Matlab and 9 bytes in Mathematica. Such considerations were once important when PCs came with 640k of RAM but we suffer these choices decades later.

We rarely abbreviate words in normal life because it doesn't help us express ourselves. Or perhaps I should say "We rar abbrv wds in nml life bec it dnt help us xprs ours". Except in the one place where hardware limitations still control our behaviour- texting on mobile phones.

It's hard to read back and hard to remember when the words we use in programming are so different from the ones we use in real life.

Of the popular systems, suprisingly only Mathematica does not fall into this trap, being just young enough to have been designed with anticipation of megabyte computing.

Consider some examples
Task: Dimensions of a matrix
Matlab: ndims
Mathematica: Dimensions

Task: Row reduced eschelon form of a matrix
Matlab: rref
Mathematica: RowReduce

Task: Change to cartesian coordinates
Matlab: sph2cart
Mathematica: CoordinatesToCartesian

Task: Comparison test
Matlab: ge
Mathematica: GreaterEqual

Task: Rational approximation
Matlab: rat
Mathematica: Rationalize

Task: Select a column of a matrix
Maple: col
Mathematica: ColumnTake

Task: Polynomial interpolation of data
Maple: interp
Mathematica: PolynomialInterpolation

Task: Number of occurrences
Maple: numboccur
Mathematica: Count

Task: The covariance of two data sets
MathCAD: cvar
Mathematica: Covariance

Task: Pearsons correlation coefficient
MathCAD: corr
Mathematica: Correlation

Task: Inverse fast fourier transform
MathCAD: icfft
Mathematica: InverseFourier


I will leave the reader to guess the meaning of the following commands in use in Maple and Matlab: gc, statevalf, PSLQ, cfrac, nops, ne, erfcx, decic, speye, sprank, dF, dpois, rnd, PRNCOLWIDTH, Yn, K1.

And if you can guess, try remembering the correct abbreviation later.

And of the future? Not bright. Even new systems often are developed by people so immersed in this culture that they do not question it. Only Maple has the courage to address the issue in an existing system. They are gradually making parts of the system obsolete and replacing them with new functionality with clearer naming: The linalg package with functions like LUdecomp and diag replaced with a LinearAlgebra package with LUDecomposition and DiagonalMatrix. But they have chosen to do this gradually, to keep the existing user base on board. Perhaps in 10 years it will look just like Mathematica!

Apologies to non-English speakers for whom this analysis does not apply, though if you are reading this article, you probably do!

1 comment:

Anonymous said...

An int example from Maple is not that great in this topic, because the same command can be also executed as integrate. It is users' choice what to use, int or integrate. Why people use int instead of integrate? Because it is shorter and easy to remember.

Some abbreviations are standard, such as sqrt, and some come from mathematics, such as sin, cos, and log.

If I had a choice, I would use old linalg names in Maple instead of new LinearAlgebra names; for example, det instead of LinearAlgebra:-Determinant.

Unfortunately, one doesn't have to wait 10 years for Maple commands looking like Mathematica's ones. Maple already has command names taking more than 2 lines to write.