From: Gavin Sinclair Date: 2002-12-04T09:33:33+09:00 Subject: Re: Ruby Book for People Who Aren't (Yet) Programmers From: "Martin DeMello" > Daniel Carrera wrote: > >> 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. > I don't think that's too much trouble, actually. The reader should have no problem with an operation producing a result. I think it's nice that irb is a calculator: > 3 + 4 7 > "Hello" "Hello" > puts "Hello" "Hello" nil Hang on! What's that "nil"? Well, your operation - puts "Hello" - produces a result, just like >3 + 7<. That result is *nil* (i.e. nothing). The "Hello" you see is a side-effect of the operation. Summarising: > 3 + 4 7 <--- result > "Hello" "Hello" <--- result > puts "Hello" "Hello" <--- side-effect nil <--- result EOF It's important to ground people in the language of "expressions". That is, >3 + 4< is hardly an *operation*, it's an *expression*. Well, >puts "Hello"< may *look* like an operation, and there's no harm in considering it as such, but it too is an expression. Everything you do in Ruby has a result. Some things also have side-effects. Cheers, Gavin