Just Wondering (math notation in C)

Jim Giles jlg at lanl.gov
Wed Apr 26 11:01:56 AEST 1989


>From article <29544 at apple.Apple.COM>, by desnoyer at Apple.COM (Peter Desnoyers):
> I don't agree. If the form in which everyone learned the equation uses
> X, x, and z, then use those very same symbols. Which would you rather
> read: 
>     Area := ratio_of_diameter_to_circumference * radius_of_circle ^^2
> or
>          ___  2
>     A =  | | R	  


Neither.  I'd rather see:

c1.area <- @pi * c1.radius^2

This has several advantages.
1) It is possible to write with my keyboard without multi-line superscripting
   or special character drawing.
2) Pi _should_ be a built-in constant in a programming language.  Its value
   should be kept to the maximum (machine dependent) precision, but it should
   be used only to the precision required by the rest of the expression.
   (I think that '@' is just as good a character as any to signal intrinsic
   constants.)
3) This example identifies, completely and uniquely, _which_ circle is
   having its area computed.  You might argue that the data type 'circle'
   should have sub-field names that are shorter (I won't argue that point).
   But both your examples imply only one circle in the computational
   universe of possibilities.  This is the difference between forms that
   you learn and forms that you _use_.  The form you learn is a template
   that must be filled out with specifics in actual use.  Programming
   is a medium of _use_, not a medium of learning.  It must, therefore,
   have not only the learned _form_, but be filled out with the specifics
   as well.
4) It has an _assignment_ symbol.  Your example is misleading in its use
   of the equal sign.  In a functional language, like VAL, your second
   example could as easily mean that you're defining 'R' instead of your
   probable intent to define 'A'.  (Of course, ":=" looks nothing like
   a left-arrow and should be avoided for assignment in a programming
   language design.)



More information about the Comp.lang.c mailing list