From: Daniel Carrera Date: 2002-12-05T00:59:38+09:00 Subject: Re: Ruby Book for People Who Aren't (Yet) Programmers Okay, there have been a lot of good ideas here. Now, I'll try to put it all together. 1) IRB ====== There has been some discussion on whether we should use irb. I think I came up with a good idea: Chapter 1: Interactive Ruby Start uring irb right away. Don't introduce /puts/ or writing files. Just use Ruby as a calculator. Chapter 2: Objects Essentially what I have now, but all done in irb and without /puts/. Chapter 3: Printing A small chapter to introduce /puts/. Give examples such as: puts "#{num1} + #{num2} = #{num1 + #num2}" Also introduce the difference between 'return value' and 'side effect'. Chapter 4: Flow Control Essentially what I have now. Still using irb. Chapter 5: Putting it all together. Show the student how to put all this in a file and run it as a single program. This is a good excuse for adding more excercises and examples to make the concepts of the previous chapters settle 2) Class vs type ================ I totally agree with saying 'class' instead of 'type'. We can introduce the 'Object#class' method so people can experiment. Thanks for bringing up this point. 3) Description of Objects ========================= On the one hand we want to give a correct description of objects. We want to avoid a 'but you said...' later on. On the other, we want to engage the student early on and not make things too complicated. Here is my idea: Chapter 2: Objects This is what I currently have: 1. I define objects as units of data storage with a class and a value. 2. I go over the Fixnum's, Float's and String's and their methods. 3. Point out that methods are type-dependent. *After* I've done this, I could do this: Section: Recap We have already learned some characteristics of objects: * Value: Most objects will contain data, such as numbers or text strings. Later on we'll see objects with more complex data. * Methods: Objects define /methods/, which are ways that programs can interoperate with the object. In a sense, the value 'what object knows', and a method is something the object can do. For instance the object 3 knows what comes after it, (the /next/ method). * Class: Objects always belong to a class, like /Fixnum/, /Float/ and /String/. The class is what determines which methods are available, and what kind of data the object holds. For instance, a /Fixnum/ always holds a whole number and it has a /next/ method. [I think that these briefer descriptions are enough because the students have already seen these in practice. ] In addition to this, objects have an ID which identifies the object uniquely to Ruby. [ I like the idea of introducing the object ID, but only briefly. Having the ID lets me demonstrate the difference between 12 and "12" better. What do you think? Introduce Object#class, Object#id, Object#display and Object#methods. 1.- Let the student play with these. 2.- Illustrate the difference between objects and variables. 3.- Use '.id' to illustrate the difference between 12 and "12". Use other methods to illustrate this difference. ] [Here we include Martin's diagram] Questions: Perhaps this should be a separate chapter instead of a section? What should I call it? How about "Exploring Ruby"? 4) Having a non-programmer handy ================================ I have a 14-year-old and a 13-year-old brother I can ask. :-) I agree that we should work on the tutorial before we start showing it to programmers-to-be. 5) Fixnum vs Integer ==================== Fixnum and Bignum are both subclasses of the class Integer. So technically we can use either term. Question: Should I use the term 'Fixnum' or 'Integer'? Pro Integer: People already know what the word 'integer' means. Pro Fixnum: When you type '3.class' it says 'Fixnum'. I think I'm partial towards Fixnum. Cheers, Daniel