Ruby Book for People Who Aren't (Yet) Programmers

Hello,

I heard a little while back that there might be a Ruby book in the works for
people who don’t (yet) program. Anyone know who is working on this?

I ask because I have taught several people to program using Ruby as the
language. Some were adults; some kids as young as 8. Not all of my
experiences were successful :(, though some certainly were.

In any case, I learned from each one and would like to share what I found to
work, and what I found not to work.

One thing I did find, though, was the Ruby is the perfect language for
learning to program! (I have tought people C before, too… it was as
excruciating as I remembered it being when I first learned it. Ugh! My
first 8 hours (and 20 lines) of C programming consisted almost entirely of
me staring at the screen, saying “So what the **** do I do now??” After a
while, C became second-nature to me, and I blocked all of that out, but that
first program was misery incarnate.)

Chris

I agree. I think Ruby might be an IDEAL first language. The only
drawback would be if Ruby became categorized as a “beginner’s”
language like BASIC.

Wait a minute. There’s a second drawback. People who learn Ruby first
might start to expect other programming languages to be as expressive
and powerful :slight_smile:

···

On Tue, 3 Dec 2002 00:00:39 +0900, “Chris” nemo@hellotree.com wrote:

One thing I did find, though, was the Ruby is the perfect language for
learning to program!

Hi Chris,

My suggestion is that if you have something to share, share it! The best way
to do this, IMO, is write a page on the Wiki. This enables you to have
virtually your own web-page without the hassle of hosting or HTML coding. It
becomes a Ruby resource, and can later be used in other resources (like the
book you’re asking about). The important thing to do is write it down!

If you want to do this I’ll give you heaps of advice off-list.

Cheers,
Gavin

···

----- Original Message -----
From: “Chris” nemo@hellotree.com

Hello,

I heard a little while back that there might be a Ruby book in the works for
people who don’t (yet) program. Anyone know who is working on this?

I ask because I have taught several people to program using Ruby as the
language. Some were adults; some kids as young as 8. Not all of my
experiences were successful :(, though some certainly were.

In any case, I learned from each one and would like to share what I found to
work, and what I found not to work.

[…]

Chris

I’m still working on a “Ruby for the Nuby” book, but it won’t be out
anytime soon. The market for books is kind of weak right now and unless
a book has real promise of shipping in volume, it isn’t getting much of
a look in at contract time right now.

Before I realized that I did get a series of 7 “Ruby for the Nuby”
articles published on the InformIt site http://www.informit.com/ (free
registration required etc.)

I still intend to finish writing the book, but it is in the queue
behind more commercial projects (writing and otherwise).

Pete

···

On Monday, December 2, 2002, at 08:00 AM, Chris wrote:

I heard a little while back that there might be a Ruby book in the
works for
people who don’t (yet) program. Anyone know who is working on this?


Pete McBreen, McBreen.Consulting , Cochrane, AB

Author, “Software Craftsmanship The New Imperative”
Winner of 2002 SD Productivity Award

Author: “Questioning Extreme Programming”
Addison-Wesley (c) 2003

Oh, my, what have I begun? :slight_smile:

Well, as was requested, I started a wiki page at

http://www.rubygarden.org/ruby?LearningToProgramWithRuby

Perhaps we should move our discussion there? Definitely feel free to
reformat and edit what I wrote there… sorry if it’s ugly – it’s my first
wiki page.

And of course, add your 2 cents. At this rate, we’ll be millionaires in no
time. :slight_smile:

Chris

I don’t plan on spending much time learning any language other than
Ruby. Ruby is so wonderful because it puts real power in the hands of a
beginning programmer in a very immediate way.

For the past several years, while working full-time in another field, I
wanted to find a powerful and accessible programming language to create
tools that I want to have in my work. But until Ruby, it just took too
long to learn how to write a program that did something useful. I have
done “Hello, world!” and fahrenheit-celsius conversion programs in lots
of programming languages.

I bought a C++ book but found it almost impossible to read (I didn’t
really grasp the concept of an array because the first thing they told
you to do was to set the size of the array rather than telling you what
it was – I thought an array was another word for a square shaped
matrix).

The Java book I bought was almost as bad (I’ve mostly blocked it out,
but I have a vague recollection of reading that I had to choose public,
private or protected right away).

Applescript seemed promising (just stitch together the functionality of
all these desktop applications), but it was difficult for me to do
anything with it other than open applications.

I briefly looked at PHP, which is very messy.

In spite of the above, I didn’t think I was stupid (:-)) – just too
busy to properly learn this stuff.

And then I found Ruby. Ruby enables a person to do very productive
things with truly minimal overhead. You can do complicated things with
several hundred gigabytes of text files. You can create your own
powerful web applications. You can create that GUI program with the
customized features you want that no software company thinks to
provide. You can learn object orientation, gently. I could go on . . .,
but I’ll stop.

Thank you to matz and all of the people working on and in Ruby.

···

On Monday, December 2, 2002, at 01:09 PM, Tim Hunter wrote:

Wait a minute. There’s a second drawback. People who learn Ruby first
might start to expect other programming languages to be as expressive
and powerful :slight_smile:

Oh, my, what have I begun? :slight_smile:

Well, as was requested, I started a wiki page at

http://www.rubygarden.org/ruby?LearningToProgramWithRuby

I read your article. You have a lot of great insights. I’ll try to
implemente as much of it as I can. I’m finding that I’m receiving great
ideas much faster than I can type them in. :slight_smile:

Perhaps we should move our discussion there?

How? I’ve never used Wiki before. What exactly is wiki?

Daniel.

Heh, my mouth watered at the first email in the hopes of finding a book that
addresses me (the not yet programmer who wants to learn Ruby). I am
disappointed there isn’t a book yet, but I understand why and I look forward
to the fruits of these efforts. Anyone feel like tutoring me? :slight_smile:

Jason

···

----- Original Message -----
From: “Chris Pine” nemo@hellotree.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, December 03, 2002 12:39 PM
Subject: Re: Ruby Book for People Who Aren’t (Yet) Programmers

Oh, my, what have I begun? :slight_smile:

Well, as was requested, I started a wiki page at

http://www.rubygarden.org/ruby?LearningToProgramWithRuby

Perhaps we should move our discussion there? Definitely feel free to
reformat and edit what I wrote there… sorry if it’s ugly – it’s my
first
wiki page.

And of course, add your 2 cents. At this rate, we’ll be millionaires in
no
time. :slight_smile:

Chris


Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.422 / Virus Database: 237 - Release Date: 11/20/2002

How? I’ve never used Wiki before. What exactly is wiki?

···

----- Original Message -----

Perhaps we should move our discussion there?


Well, as I just found out (that was the first time I ever used wiki), it’s a
bunch of webpages that you (yes, you) can edit and add to. Go to the wiki
page, and at the bottom is a link which says “Edit text of this page”.
Click it and you’ll see all of the text I typed in (so you can see how the
formatting works).

Is there a typo on the page? Fix it for me!
Do you want to add something of your own? Go ahead and add it!

(I have no idea what is considered appropriate ettiquette for wiki, but you
can modify my page all you want.)

Also, anything you type of the format OneTwoThree is automatically made into
a link. If the page isn’t yet written, you will see a little ‘?’ after it.
Click it to create the page yourself.

Pretty nifty, eh? What will they think of next…

Chris

[Don’t know who wrote this]

Perhaps we should move our discussion there?

You can, but if too many people edit a Wiki page, well, it’s like too many
cooks cooking a broth. Someone has to take responsiblity for producing the
document.

All of ruby-talk is interested in this discussion, where “interest” means “has
an interest in” - as in, the more educational resources there are, the more
sophisticated ruby-talk becomes.

Cheers,
Gavin

I really like this idea. For reference, the link to the Wiki put up by
Chris Pine on this topic is below.

My thoughts on teaching 12 vs. “12”:

I would recommend teaching this by example. If you write down 12x2 and
ask a person what that is, they’ll answer 24. If you write a program
and ask it what "12"x2 is it will tell you: 1212. If you ask the
program what “12”+“2” is it will tell you 122. The number in quotes is
a string (an ordered collection of characters) and the number without
quotes is a number, which behaves like a number.

As a variation, to people, twelve times two is 24 and “twelve times
two” to a program is “twelve times two”, unless you tell the program to
do something different.

Why would you want to add or multiply a string object? In order to use
a string object in a program, you will want to use a variable as a
reference to that object. Then you might want to combine the strings
in different ways without knowing in advance what the strings are. For
example:

class Name
def initialize(first, last) # how to make a new Name object
@first_name=first
@last_name=last

could also write

@first_name, @last_name = first, last

but parallel assignment may not have been taught yet

end
def show_name
	puts "Your name is "+@first_name+" "+@last_name

could also write

puts “Your name is #{@first_name} #{@last_name}”

but that would negate the example

end

end

n=Name.new(“Michael”, “Jordan”)
n.show_name

This is a little out of order, because I didn’t start with unit testing
(but I’m still learning).

···

http://www.rubygarden.org/ruby?LearningToProgramWithRuby

Great idea on the 12 vs. ‘12’ problem, Mark!

I was thinking about it last night, and came up with something similar:

RUBY AS CALCULATOR

For a number of reasons, I don’t think irb is a good tool to start with, so
I’m only talking about ruby in .rb files. One of these reasons is that one
thing is easier to learn than two (or three, if you use the ‘-e’ switch as a
third was of running Ruby code), so I picked what I think is the simplest
and present it only.

So after they get Ruby installed, and assuming they know how to run commands
on the commandline and create/edit text files (not large assumptions)…

Type the following into a text file, and save it as “calc.rb”

print (1+2)

That’s it! Now run it like this (enter this into your commandline):

ruby calc.rb

You should see a ‘3’ printed on the screen for you. If you don’t, you seem
to have something wrong with your installation, or maybe you typed something
in wrong.

Then I would try to find all of the possible error messages I could and tell
them what probably went wrong and how they might be able to fix it.

So that’s how it starts. I would tell them to experiment with it some,
typing in whatever numbers they want. I’d describe the arithmetic
operations +, -, , /, and **. (That '’ means ‘multiply’ is not
necessarily obvious to a non-programmer.) Then I would say that a computer
treats numbers with a decimal point different from those without, and tell
them the names Integer and Float. Calculators like they are used to only
use numbers with decimal points, so if they want their program ‘calc.rb’ to
work exactly like a calculator, they should only use Floats. Usually,
though, people don’t use them very often, so we won’t talk much about them.

If you try something like (10 / 3), you will get 3 because the computer
rounds down to the next integer. This means that (-10 / 3) gives -4,
because -4 is less than -3.

So that’s numbers… but what about letters? Words? Text?

The word we use for groups of letters is String. Here are some strings:
‘Hello.’
‘Ruby rocks.’
‘5 is my favorite number… what’s yours?’
‘Snoopy says #%^?&*@!’
’ ‘
’’

(No double-quoted strings yet: One thing is easier to learn than two, so
stick with the simpler one.)

Instead of printing a number, let’s print a String…

Then talk about things like
’Hello’ + ‘Betty’
‘Hello ’ * 5
’1’ + ‘2’
‘1’ * 5

The punch-line: Ruby is a Calculator for numbers and letters, for Integers,
Floats, and Strings… and many other things, too.

So… that’s a pretty good start. Look at how we secretly introduced a
number of neat concepts without even talking about variables yet! We
introduced a few Classes without ever saying ‘Class’ or ‘Object’.

Personally, I think the more we can push off concepts like those (but
secretly slip them in), the easier it will be to learn. The reason for this
is that DOING OO programming is natural! This is simply how we tend to
think. However, LEARNING (and talking about) OO programming is unnatural!
So we should allow them to do it without having to “learn” about it. You
certainly don’t need to understand what objects are, and how the Fixnum
class derives from the Integer class, and the ‘+’ method, to understand that
(1+2) should be 3.

I think that a good tutorial, like a good program, follows certain rules:

  1. DRY (Don’t Repeat Yourself)

Well, you will want to repeat some things, surely. In a tutorial, I take
DRY to mean “One thing is easier to learn than two things.” If you can use
single or double quotes to create a String literal, so what? You aren’t
giving the learner more freedom; you are doubling the amount of work they
have to do to remember what’s going on.

  1. Orthogonality (Law of Demeter)

Keep lessons uncoupled. Understanding a concept can depend upon
understanding more fundamental concepts. However, we often confuse just
what those concepts are. Do you need to understand objects and methods to
concatenate String objects? Nope. Do you need to know what a variable is
to teach simple iterators?

5.times
print 'Hi!'
end

…or…

(1 + 2**2).times
print 'Hi!'
end

No, you don’t. I think this sort of ‘uncoupling’ of concepts is crucial to
making programming easy to learn.

  1. Motivate Each Lesson

Simply, make sure you have a compelling reason for introducing a new concept
before you actually do so. If this rule is followed, concepts just flow
together, because they make sense in relation to the whole.

The idea is certainly not to teach them “bad” (or procedural) Ruby
programming; the idea is to introduce them to the concepts of good Ruby
programming without introducing new and confusing terminology, and without
exposing them to too many things at once.

Here’s an interesting test for would-be tutors: try writing a few programs
using no variables. Literals (Integer, Float, String, Array, Hash) are
allowed. See how much you can do! After a while, you will be desperate for
variables.

The idea is to get to a point where the learner is writing relatively
complex (for having no variables) programs, and then to introduce
variables. Look how lovely they make the program, how simple everything
becomes, and how much more powerful. At this point you have a student who
already implicitly understands a fair amount of OO already, and variables
come easily. (Why introduce variables at the same time as you introduce
what you put in them??)

Here are things I would teach before variables:

  • The true and false objects.
  • Comparison methods: <, <=, ==, >=, >
  • Branching: if; else; end (case comes later)
  • The while loop and break.
  • The methods ‘puts’, ‘gets’, and ‘chomp’ (but not ‘chomp!’)

At this point a fairly complex program could be written, with an
input-handling loop and everything… but without a variable to catch what
’gets’ returns, it would be hard to do much with it. Now we introduce
variables and assignment. (This is the first time they see assignment.)

And so on…

BTW, I think the reason this whole approach works in Ruby and wouldn’t in
most languages is that Ruby is so clean and consistent; OO was built-in from
the start, so it doesn’t need to be ‘taught’ so much as ‘noticed’.

So, what do y’all think?

Chris

RUBY AS CALCULATOR

For a number of reasons, I don’t think irb is a good tool to start with, so
I’m only talking about ruby in .rb files. One of these reasons is that one
thing is easier to learn than two

On the other hand, it’s easier to experiment with irb. I see your point,
which is why I was thinking on not talking about files until way into the
tutorial (5th or 6th chapter). That way, I am still only teaching one
thing.

so I picked what I think is the simplest and present it only.

I think that irb is simplest. It does look just like a calculator.
Specially if you don’t introduce ‘print’ at first, like I plan to.

[snip]

So that’s how it starts. I would tell them to experiment with it some,
typing in whatever numbers they want. I’d describe the arithmetic
operations +, -, , /, and **. (That '’ means ‘multiply’ is not
necessarily obvious to a non-programmer.)

Yeah, even “/” was confusing to my youger brother.

I like the way you explain things in your tutorials. I’ll incorporate
some of that.

(No double-quoted strings yet: One thing is easier to learn than two, so
stick with the simpler one.)

Rather, I was planning on no single-quoted strings. They don’t need
to know that there’s anything special about them. Later I can introduce
variable substitution without having to introduce a new kind of quote.

Also, irb prints strings using double-quotes.

So… that’s a pretty good start. Look at how we secretly introduced a
number of neat concepts without even talking about variables yet! We
introduced a few Classes without ever saying ‘Class’ or ‘Object’.

I like that. I am still keen on irb. It looks even more like a
calculator.

Personally, I think the more we can push off concepts like those (but
secretly slip them in), the easier it will be to learn.

I agree. That’s why I wanted to postpone the explanation of objects until
after the student has used them a bit.

The reason for this is that DOING OO programming is natural! This is
simply how we tend to think. However, LEARNING (and talking about) OO
programming is unnatural!

Agreed. I’ve been trying to design the tutorial to dive straight into OO
without the student ever thinking anything of it.

  1. DRY (Don’t Repeat Yourself)

… “One thing is easier to learn than two things.” If you can use
single or double quotes to create a String literal, so what?..

Yup.

  1. Orthogonality (Law of Demeter)

Keep lessons uncoupled. Understanding a concept can depend upon
understanding more fundamental concepts. However, we often confuse just
what those concepts are. Do you need to understand objects and methods to
concatenate String objects? Nope.

I see your point, but I still want to explain that there is a difference
between a String, a Float and a Fixnum. Otherwise, their different
behaviour will be confusing.

This is why I feel that objects have to be mentioned. I’ll try to make it
casual. Hopefully the student won’t think much of it other than the fact
that Fixnums behave different from Strings.

The idea is to get to a point where the learner is writing relatively
complex (for having no variables) programs, and then to introduce
variables… (Why introduce variables at the same time as you
introduce what you put in them??)

Excellent point. How about this outline:

Chapter 1: Ruby as a Calculator - irb
Chapter 2: Objects [without variables]
Chapter 3: Recap on objects [see my earlier post]
Chapter 4: Conditionals
Chapter 5: Variables
Chapter 6: Printing
Chapter 7: Loops
[This chapter further justifies printing and variables]
Chapter 8: Putting it all together
[Writing the program to a file, and ‘gets’]

I’d like to delay variables until just before ‘gets’ like you suggested,
but how can you teach loops without variables?

Perhaps we can delay printing until after loops. But that would make
loops a bit harder to explain. I’d like to be able to show them:

for i in 0…9
puts i
end

This is the simplest way to explain a loop.

What do you think?

Cheers,
Daniel.

Well, I think I mostly disagree with everything you said that disagreed with
what I originally said. :slight_smile: (almost by definition :slight_smile: )

First off, I don’t think irb is a goot tool for beginners. I have thought a
lot about this, and originally I thought irb was the way to go. While there
are definitely some benefits to irb, though, ultimately I think there are
just too many problems with it.

One of the major benefits of irb is avoiding ‘print’… but why avoid
‘print’? It’s english! They already know ‘print’ (in some sense), so I say
teach that first.

The other major benefit of irb (seeing values of a program in progress) is
only a benefit when you have introduced the concepts of assignment,
variables, and return values.

So here’s why I’m against starting with irb:

5.times do
print 'hi ’
end

as opposed to

$ irb
irb(main):001:0> 5.times do
irb(main):002:1* print 'hi ’
irb(main):003:1> end
hi hi hi hi hi => 5

This is confusing! What’s with ‘main’? Or the counters: 0, then 1, then 1
again? Why is there a ‘>’ at the end of one line, and a ‘*’ at the end of
another? Why the ‘=> 5’ after the hi’s were printed? Sure, I know the
answers to these (well, most of them), but a new programmer won’t. What are
you going to tell them? Just ignore the extra stuff you don’t get?

No, I won’t do that. When a new programmer looks at this:

5.times do
print 'hi ’
end

they understand everything they see. That is important! You must inspire
confidence in the new programmer. I can’t stress that enough: Confidence
is crucial! I already have confidence in Ruby (and in programming in
general), so I can deal with irb’s extra symbolage. I know what to look
for, what to pick out.

Another reason you want to avoid irb: you want to avoid explicitly dealing
with return types. irb forces that issue much sooner.

Finally, I remember when I was learning Ruby. Simple text files were easy
to understand. I found irb confusing until I understood basic programming
in Ruby. Plain and simple. I doubt if anyone learned on irb first, and I
imagine most people found it harder to understand when they were nubies.

irb is a wonderful tool, and I love it, but I really don’t think it’s a
teaching tool, at least not right away.

···

----- Original Message -----
I think that irb is simplest.

Honestly, I just don’t see how you could say that. It seems clearly more
complicated; just look at it!


It does look just like a calculator.


No calculator I own! :slight_smile:


Rather, I was planning on no single-quoted strings. They don’t need
to know that there’s anything special about them. Later I can introduce
variable substitution without having to introduce a new kind of quote.

Yeah, I thought about this a lot, too. The way I see it, if they don’t know
that other languages use “” to denote strings, then they wouldn’t think of
‘’ as special at all. Really, the only difference is that “” has more
processing done on it, and that’s what I wanted to avoid: a new programmer
accidentally invoking an escape sequence. Remember, I have kids in mind
when I think about teaching Ruby, and kids love to do things like

print 999999999999999999999
print '!@#$^^
$(///#?<>,.][[;]’

I’m just trying to give them as few surprises as possible.

As far as variable substitution, why bother? I hardly ever use it myself.
Both from personal experience, and from people I have taught, it is much
easier to understand:

print ‘Hello, ‘+name+’! How are you?’

…than it is to understand:

print “Hello #{name}! How are you?”

I wasn’t planning on teaching variable substitution at all. Most people
figure out how to do the former by themselves, and I find it more readable,
anyway… especially if you have syntax coloring turned on, which often
screws up on the ‘#’.


Also, irb prints strings using double-quotes.


A good point, but only relevant if you are using irb. :slight_smile: If I was, you’re
right, double-quotes would be better. However, I see this as another reason
not to use irb.


Do you need to understand objects and methods to
concatenate String objects? Nope.

I see your point, but I still want to explain that there is a difference
between a String, a Float and a Fixnum.


If you notice, I mentioned String, Float and Integer right away. (No
Fixnum, because then you should really explain Bignum, too, and really those
are just implementation for Integer, anyway… plus, it sounds really
complicated: Fixnum??) I didn’t say they were classes, or even that they
were the official names… that’s just what I called them. The new
programmer will understand that ‘hello’ is a String and not an Integer; you
don’t have to tell them that it’s a ‘String object’. Just say it’s a
‘String’ (or even just ‘string’).

You don’t have to say the word object at all. You don’t have to say,
“Everything in Ruby is an object.” Why say anything at all about
“everything in Ruby”? Statements like that sound like “OK, I have to
remember that everything in Ruby is an object”. What does that even mean to
a new programmer? A nuby doesn’t understand what ‘things’ are in Ruby, so
telling them that every one of those ‘things’ is an ‘object’ (basically an
English synonym for ‘thing’) doesn’t have any semantic content (for the
nuby). In the absence of semantic content, the nuby must simply memorize
what you said.

I have experienced this in teaching ruby myself
Nuby - “What does ‘yield’ do?”
Me - “It calls the–”
Nuby - “–I know, I know! ‘It calls the associated block!’
But what does it DO??”

I’m not sure I’m explaining myself very well… :slight_smile: If not, I’m sorry. I
just think that we should piggy-back what we are teaching with what they
already know. A nuby knows what a number is, and what words are, so let’s
just leave at that.

I like saying:
“5 is an Integer.”

I don’t like saying:
“5 is an object.” (meaningless to a nuby)
“5 is an Integer object.”
“5 is an Integer, and all Integers are Objects.”
“5 is an instance of class Integer.” (not even true!)

Maybe that explains what I am trying to say better. :slight_smile:


I like the way you explain things in your tutorials. I’ll incorporate
some of that.

Oh, well thank you! (Though I’m not sure I’m doing such a good job now!)
Feel free to use whatever you find useful.


I’d like to delay variables until just before ‘gets’ like you suggested,
but how can you teach loops without variables?

[snip]

for i in 0…9
puts i
end

This is the simplest way to explain a loop.


A for loop!? No way… it uses variables AND ranges! (You are thinking
like a programmer, not a nuby. What does the word “for” have to do with
looping?)

No, here’s a great loop (which I put in my last post, too)

5.times do
print 'Hello, everyone! ’
end

I mean, my mom would understand what that means… it’s practically written
in English! No ranges, no variables, and we are using a method of the 5
object! (That is the sort of thing I want to slip in here and there: the
idea that everything is an object, with methods you can call, etc.)

Here’s what I consider to be one of the last programs before variables are
introduced, and it uses a different kind of loop:

puts ‘Type something, will ya? Then press “Enter”.’

while (true)
if (gets == ‘quit’)
break
else
puts ‘Type “quit” to quit!’
end
end

puts ‘Very good! Good-bye.’

So… thoughts?

Chris

Pet hate: long tutorials which use a read-eval-print-loop-thingie like irb.

Why? I make typos. It’s pretty frustrating to have to type the same lines
over and over again, each time making a typo in a different place. With
files you get a nice incremental progress, and as an added bonus you get to
keep the fruits of your labor as a personal reference.

I tend to like tutorials that start out with an interactive interpreter:
it’s a good way to quickly introduce some basic concepts in a language.
However, as soon as examples become longer than three lines, files shall it
be.

Sorry for ranting,

– Nikodemus

···

On Thu, 5 Dec 2002, Daniel Carrera wrote:

I think that irb is simplest. It does look just like a calculator.
Specially if you don’t introduce ‘print’ at first, like I plan to.

Chris Pine wrote:

$ irb
irb(main):001:0> 5.times do
irb(main):002:1* print 'hi ’
irb(main):003:1> end
hi hi hi hi hi => 5

This is confusing! What’s with ‘main’? Or the counters: 0, then 1, then 1
again? Why is there a ‘>’ at the end of one line, and a ‘*’ at the end of
another? Why the ‘=> 5’ after the hi’s were printed? Sure, I know the
answers to these (well, most of them), but a new programmer won’t. What are
you going to tell them? Just ignore the extra stuff you don’t get?

Try

irb --simple-prompt

Hi,

[…]

Finally, I remember when I was learning Ruby. Simple text files were easy
to understand. I found irb confusing until I understood basic programming
in Ruby. Plain and simple. I doubt if anyone learned on irb first, and I
imagine most people found it harder to understand when they were nubies.

I learned on IRB first… If it hadn’t existed I would have written it.
(A simplified version, albeit. :slight_smile: … It’s somewhat baffling to me
why, in learning a language, one would deliberately eschew something so
interactive that gives such immediate feedback like IRB.

I started out in BASIC (in 1980), and it was interactive. My next
language was Forth… highly interactive. From there onto C and C++,
and I was thoroughly irked by the lack of an interactive development
environment (profoundly different from a source level debugger.)
When I got to Perl, I was ecstatic, 'cause one of the first things I
realized I could write was:

perl -e “while(<>){$=eval;print qq’ => $ $@\n’}”

… which is like a mini “IRB” for Perl… Essentially the Ruby
equivalent of:

ruby -e “while gets; puts eval $_; end”

Then on to Smalltalk, where I was again in heaven with the interactive
development capabilities (kind of squared, in smalltalk :slight_smile:

Finally on to Ruby, where it’s prolly not too surprising how thrilled
I was to find IRB waiting for me…

So… I’m wondering if some of the disagreement (just jumping into
this thread here :slight_smile: might be somehow associated with personal
preference? Because as a beginner, in BASIC and Forth, I found the
interactivity of those languages highly appealing in learning to
program, and learning the language… Almost as appealing
[and indespensible] as I find IRB now.

So if I can presume some “nubys” out there think and experiment and
learn the way I do, I’d imagine IRB would be perfect for them as a
learning tool (perhaps, as has been noted, with --simple-prompt :).
…But, I don’t know what percentage of total nubys these people
represent.

Just pitchin in the $0.02…

Regards,

Bill

···

From: “Chris Pine” nemo@hellotree.com

Nikodemus Siivola tsiivola@cc.hut.fi writes:

···

On Thu, 5 Dec 2002, Daniel Carrera wrote:

I think that irb is simplest. It does look just like a calculator.
Specially if you don’t introduce ‘print’ at first, like I plan to.

Pet hate: long tutorials which use a read-eval-print-loop-thingie like irb.

Why? I make typos. It’s pretty frustrating to have to type the same lines
over and over again, each time making a typo in a different place. With
files you get a nice incremental progress, and as an added bonus you get to
keep the fruits of your labor as a personal reference.

irb uses readline, which means if you typo, you can just go back and
correct it, instead of typing it all in again from scratch. That’s
not to discount the value of having everything in a file you can refer
to later-- I tend to “learn” most of my tricks from programs where I
did it before, but forgot how, or realize now that I can do it better.

-=Eric

Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton

Just a brief note: When I was new to Ruby (even newer than I am now, that is), I haven't had any recent programming experience. It had been ten years since I last coded anything -- and even then I was only "fluent" in various Basic dialects (but had never "gotten" C/C++, and I still don't). I echo what Chris wrote about IRB being confusing -- it did exactly this to me and left me wondering what the heck I'm supposed to do. Typing in code bits (essentially "real scripts") and executing them seemed far more "intuitive" to me, and had better learning results. This is probably a very individual "thing", however, and perhaps cannot and should not be generalized.

I found Mark Slagell’s “Teach yourself Ruby in 21 days” to be a
valuable help in picking up the basics of Ruby (and OO scripting
languages in general). The author uses IRB only briefly, early on, to
teach some principles (variables, etc), and then quickly moves on to
presenting complete code. I think that anyone who strives to write or
develop a book for “People Who Aren’t (Yet) Programmers” should take a
glance at Mark’s works. This “nuby” most certainly would have given up
without this book. :slight_smile: (and I am glad that I did buy it despite its
awful title)

-M.

···

On Thu, 5 Dec 2002 04:20:08 +0900, “Chris Pine” nemo@hellotree.com wrote:

they understand everything they see. That is important! You must inspire
confidence in the new programmer. I can’t stress that enough: Confidence
is crucial!


To e-mail: use the initials of my name and add “at felinism dot com”.

Here’s what I consider to be one of the last programs before variables are
introduced, and it uses a different kind of loop:

puts ‘Type something, will ya? Then press “Enter”.’

while (true)
if (gets == ‘quit’)
break
else
puts ‘Type “quit” to quit!’
end
end

puts ‘Very good! Good-bye.’

So… thoughts?

Why not use loop do … end? I find it more natural than while(true) …