Perhaps you should introduce IRB right at the beginning, so that people
can play with more immediate examples.That’s a very good idea. I’ll do that.
You’ll need to introduce the idea of a return value very early on,
though. Potentially a source of confusion.
One suggestion - have an ‘Objects’ section before ‘Variables’ - start
with defining an object (don’t introduce the term ‘object oriented
programming’, or classes - just make it seem like an object is the
natural unit of data storage), and then segue into variables.I see your point. Ruby is a pure object-oriented language, so we might as
well use OO terminology. I sort of began doing that. For instance, I
began unsing the word ‘method’ right away instead of talking about
‘functions’ and then object orientation.Now, a problem I have with this that I want to get the reader doing
something as soon as possible. It is important to engage the student.
True. There’s not much you can do with just objects.
How about this?:
I can rewrite the “Variables” chapter to introduce objects right away.
I’d change the title to “Objects”. Something like this (my comments are
in [brackets]):<<EOH
ObjectsWhat is an object?
An /object/ is the fundamental unit of data storage in Ruby.
Objects have a /type/ (the type of data stored in them) and a /value/
(the data itself). Some examples include:Value Type
5 Fixnum3.14 Float
“Hello” StringWhat is a variable?
A /variable/ is a name that Ruby can associate with a particular
object. For example:city = “Toronto”
Here Ruby associates a String object (with value “Toronto”) with
the name (variable) /city/.Think of it as Ruby making two tables. One with objects and another
with names for them. Then think of Ruby attaching a rope between
/city/ and the object “Toronto”. Whenever Ruby encounters /city/, it
will follow the string and arrive at this object.
Looks good to me. At this point a diagram would be useful, illustrating
- an object
- a variable pointing to an object
- several variables pointing to the same object
- a variable being unhooked from one object and redirected to another
I’ll work something up tomorrow and put it on the web.
What do you think about introducing the concept of an object ID at this
point? It would make clear the distinction between the object itself
(uniquely identified by its id), the data, types and methods (all of
which are various attributes of the object) and the variables that
happen to refer to it. Also, there’s the handy Object#id method so that
the student can interactively explore the way Ruby assigns IDs to
objects.
Printing variables [should I call this ‘printing objects’?]
[ Same as now ]
I’d say ‘printing objects’
Object types
We are going to look at the three most important object types:
/Fixnum/ (integers), /Float/ (decimals), /String/ (strings).
Ah - good catch. I was using Integer when I should have said Fixnum.
Maybe some more real-world analogies? Though actually I’m never sure
whether those create more confusion than they clear up.
martin
···
Daniel Carrera dcarrera@math.umd.edu wrote:
 And we do have to introduce at least the
 And we do have to introduce at least the