Monday, 11 February 2013

Named Constants

























const float TRACKWIDTH = 12.5;

In this example, we nd another good practice, that of capitalizing constant names. This
helps to di erentiate constants visually from ordinary variables in the program. We see that
if the programmer uses a named constant throughout a program and places the declaration
at the very top of the program le, then it is easy to \port" the program to the second robot
with trackwidth 14cm. Changing the 12.5 in the constant declaration to a 14 does the whole
job{no searching and replacing throughout the le. Furthermore, using a named constant
in place of a naked constant makes a program more readable, e.g. we see TRACKWIDTH which
means something instead of just 14.


No comments:

Post a Comment