                    C Class Lecture # 2

I've been informed by my family that there is a company Christmas party this
Thursday night, and that my attendence is mandatory.  Therefore, CO this week
_only_ will be WEDNESDAY night (Same time, same station: 7PM-9PM PST (10PM-
midnight EST) room 3).

            REMEMBER CO THIS WEEK IS WEDNESDAY NIGHT

    In reviewing the syllabus, I notice that in my desire to have a homework
assignment (or two) for you to ponder (and hopefully submit), I further note
that I did'nt include my 'what is a varible' section in Lecture 1.

    This is going to be basic basic, but may resolve some problems that
newcomers have when designing their first programs.  I believe that the
reason the concept of a variable is so often misunderstood is that computer
languages (at least in the expression area) tend to look like the 'equations'
we learned in Algebra.  There are two drawbacks to this for the novice
computer programmer:

    1.  The statements which contain an = are NOT assertions of 'truth' as
    they are in Algebra.  That is, lines which look equivalent to:
    
    x + y = 5
    x - y = 3
    
            equivalent 'lines'
            
    x = 5 - y
    x = 3 + y
    
    do NOT mean, as in Algebra, that some 'global truth' has been revealed. 
    In Albegbra (after a bit of fiddling around) we would come to the result
    that for this 'problem' that x=4 and y=1.  The misunderstanding starts
    with our (computer languages....and their designers) use of the 'equals
    sign' (=) to show an "action" rather than a "condition".  We get into
    problems as soon as we read the line
    
    x = 5 - y
    
    as "x equals five minus y".  The stage is set for misunderstanding.  It
    can be argued that the "statement is 'TRUE'" immediately AFTER the
    statement is executed, but this only serves to confuse the novice.  If
    they do NOT understand to start with, the above will do little to
    alleviate the confusion.
    
    My preference to "saying" the the above lines is:
    
    "x becomes five minus y"
    "x becomes three plus y"
    
    It is important to denote the concept of an action to these statements in
    a computer language.  Other languages use a different 'symbol' to denote
    the idea of 'assigning a value to a variable' or 'replacement statements'
    or whatever it was you learned to call them at your 1st computer teachers
    knee.  I think if you start pronouncing the 'equals sign' (=) in C as
    becomes.....you will have a LOT less trouble.  For those of you who feel
    that the statements ought to be pronounced:
    "x is replaced by five minus y" & "x is replaced by three plus y" I point
    out that: 
        a) "becomes" is an active verb "is replaced by" is passive.  Most
        people deal with active better than passive.
        b) "becomes" is easier to say (less syllables) than "is replaced by"
        
    2) In Algebra the 'variables' x & y changed.  We all remember the
    difficulties we had with the concept of something meaning one thing NOW
    and another a few minutes later.  I'm sure we all had someone in class
    who objected "We just found out that 'x' EQUALS five, NOW you're telling
    me it's three.  Make up your mind." and under their breath "What the hell
    is going on here. This doesn't make any sense.  This has NO relationship
    to reality.  Why are THEY trying to make me learn this nonsense anyway?"
    
    The person saying all of those things may even have been us.  If you're
    one of those people, please don't dispair.  As soon as we get the real
    meaning of these 'variables' down, it will all appear easy.  But first
    the 'bad' news.  In Algebra the 'variables' sort of stayed the same for
    the duration of the problem we were attempting to 'solve', in a computer
    the program, variables change often.  If a value were NOT going to change
    for the duration of a program we would call it a 'constant' (more about
    these later).  Confused?  I was the first time I heard all this.  The
    good news is:  YOU get to decide what 'value' a variable has.  YOU do NOT
    have to 'solve' the problem.
    
    Ok then, what is this thing called a 'variable' in the language C?  The
way I look at varibles is as a 'place' to put 'things'.  If you think of a
variable as being a 'box' into which you can put things, you'll begin to get
the picture.

    "Ok", you say, "How do I put a 3 in a box?"
    "Well", I say, "pretend you write the number 3 on a piece of paper, and
you put IT in the box."
    "Ok", you say again, "After I've filled this box with lots of paper, what
do I do, throw it away?  And besides if there are a bunch of peices of paper
in the box, how do I know which one is 'right'?"
    "You could write 'LATEST' in Large Friendly Letters across the top of the
'new' piece of paper." I reply with a smile.
    "BUT", I hear you cry, "How do I know WHICH piece of paper with 'LATEST'
written on it is the 'right' one?"
    "That was only a joke.  How about you throw away the old piece of paper
each time you want to put a new one in" I answer in a frantic attempt to calm
you down.
    "You mean that each 'variable' can hold only ONE piece of paper?  Seems
like a lot of trouble just to hold one piece of paper"

    Yup, that's the way it works.  Each 'variable' can hold only ONE thing at
a time.  Before you start hollering about the waste of trees on all this
paper (and the attendant costs of paying 'sanitary engineers' to remove and
_maybe_ recycle the stuff....not to mention the time and trouble to make SURE
that there is only one piece of paper in each box), let me assure you that
the computer does all of this (only 1 thing per variable, throws away the old
information, and does this all without removing vast sources of food from the
beavers).  You don't have to worry about it.  The computer also does all of
this at a speed which would make Hollerith's eyes bug out.

    "Well, if these 'boxes' only hold 1 piece of paper, and I'm going to be
using a LOT of them, the room is going to get rather messy." you say.
    "Have you ever seen a set of 'boxes' in the Post Office?" I ask. (I
certainly hope you have, because this analogy is all gonna fall down if you
haven't).  "Row upon row of boxes each with its own number, into which we can
place pieces of paper with 'things' written on them."

    The image of almost limitless numbers of boxes to hold 'things' is a
_very_ useful analogy, especially if we give 'addresses' to each box (that
is, number them from.... oh, say zero (0) to several million.  This means
that given the number of a box we can 'rapidly' find it, and either examine
what is written on the paper inside, or put a new piece inside (after 1st
ensuring that the box is empty...trowing away the old piece if there is one
there).

    "WAIT!!" I hear a despapate cry from the back of the classroom.  "You
expect ME to remember all these numbers?  It was so much easier when I only
had a couple of boxes, and could call them 'x' and 'y' or whatever.  How am I
going to find the boxes I want to use among _millions_ <long drawn out
groan>"?

    "Well we _could_ write 'x' or 'y' or even 'fahr' on a Post-It(tm) and
stick it on the edge of the box to identify it.  Hmmm, when I used to give
this 'lecture' Post-It's (tm) hadn't been invented...we used Scotch(tm) tape
and paper scraps.  Well, I guess it's ok, 3M will still get the money (can't
afford to get a BIG company like 3M upset with my lectures <grin>)".

    Yeah, I know that's a lot of trouble to stick up the notes, then go look
for them when you want to 'look at' a 'variable' but the computer actually
handles all of the details.  The C compilers (all compilers are alike in this
respect) allow YOU to give a NAME to a variable, and the _compiler_, in
conspiracy with the _linker_ and the _OS_, will manage to find the
appropriate 'box' for you.

                                NOTE
        For those of you who have been through this all before, I
        am NOT concerened, at this point, with the varying sizes of
        different 'things'.  The image I want to present here is 