Naming variables

A common advice that all programmers have heard at some point in their lives is that you should use descriptive variable names. However, programming languages generally impose restrictions on which characters can appear in an identifier, not allowing the use of subscripts or other formatting.

Two years ago when I was implementing the Runge-Kutta method of order 2 in Octave I found that restriction very frustrating because it was not possible to name the variables with the same notation used in the text book to describe the method, neither in the code nor in the comments.


The interesting thing is that it does not look too complicated to implement that feature for a programming language and all the necessary changes can be handled by the IDE (and optionally a documentation generator). If it is easier for you to type y_n (like you do in latex) the IDE can display the corresponding notation automatically. If not, you can use a WYSIWYG tool. In any of those cases the compiler will not know anything about the cool notation just by having a correspondence between your formated name and the syntax supported by the programming language.




2 responses to this post.

  1. I’d worry about editing that code afterwards. What would you do if you don’t use an IDE? How would you add the x_{n+1} subscript? [i.e, add a new sytactic element, like latex’s {}?]

    A WYSIWYG editor would only make matters worse. I value my touch-typing speed too much, I wouldn’t like to exchange it for a trip to the mouse every time I need to type a variable name.

    However, it would be nice to write latex-like syntax on the documentation.


  2. Those are good comments. I will need to think more about this :*



Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )


Conectando a %s

A %d blogueros les gusta esto: