Page 31 - Designing Autonomous Mobile Robots : Inside the Mindo f an Intellegent Machine
P. 31

Chapter 2

            pline, but as time went by new incarnations of the language began borrowing the
            best ideas from other languages.
            That humble Basic would evolve into the massively powerful programming environ-
            ment that is VB, and that it would come to displace many of the specialized lan-
            guages in their own native disciplines is an amazing testament to the power of the
            concepts it embraces. But we are getting ahead of our little history.
            In conventional programming the basic elements are simple:

               ■   Main line code (or threads in the case of multithreaded programs)
               ■   Functions (subroutines)

               ■   Variables
            Main line code is the place where the high-level thinking goes on, and the functions
            are called to solve particular problems. Functions need input to act on, so function
            calls came to include arguments to tell the function what the calling program wanted
            to do. For example, if a function is to multiply two numbers, then the arguments
            would naturally be the numbers to be multiplied. Since functions could call other
            functions, libraries quickly evolved to unwieldy size.

            Variables began to appear in an ever greater variety of flavors ranging from Boolean
            (true/false) and integers to Variants (chameleon-like types that can take on the
            form of almost any data type) and from single variables to multidimensional arrays
            and user-defined data types (defined collections of other variables). The more com-
            plex structures resulted from more complex programs and more complex data
            environments.
            In the earliest languages, all variables were global—any function could access any
            variable. This of course led to some very evil things. As computers began using
            interrupts to service simple I/O requirements, it became almost certain that there
            would be conflicts. For this reason, the concept of “local” variables quickly took
            root. A local variable is owned by a function, and is often stored on the processor’s
            stack by the function. If all a function’s variables are local, then it is said to be
            reentrant (more will be said about this subject in the next chapter).

            At this point in software evolution, many of the qualities of object-oriented pro-
            gramming were already beginning to appear. Once functions could be called with
            arguments and perform all of their calculations using only local variables, then a
            function could be called from any number of places, even before it had finished





                                                    14
   26   27   28   29   30   31   32   33   34   35   36