----- Original Message -----
From: "Denys Usynin" <usynin / hep.upenn.edu>


>
> > But you've piqued my curiosity: tell me, what did you find
> > surprising about Ruby?  Where "surprising" is defined as
> > "you thought it worked one way" and then discovered that it did not,
> > or that it worked that way some of the time and some other way
> > the rest of the time?
>
> well things that surprised me will probably be considered obvious by
> you. as I said its only a matter of the background and maybe of the
> thinking style.
> But here are just a few examples I had to struggle with:

And they're good points.

> 1. && and || are not the same as "and" and "or". The difference
> is subtle, but why weren't these made completely synonymous in the first
> place?

Totally agree.

> 2. File.open( "myfile" ) { |file| puts "block..." }  will automatically
> close it. I keep trying to close it in the end of block. I may see how
> it seems very intuitive to some people but I am used to C.

That's the Ruby way.  Isn't is great?  You can close it yourself if you like:

f = File.open(...)
do_something(f)
f.close()

> 3. myString.each { } processes lines not bytes. Why?

It's a common operation.  Strings are not arrays of charaters.  They never
were, in any language, and never will be.  (My reasoning, C doesn't have
strings, only arrays of characters).  Of course you know to use
myString.each_byte { }; and how long did it take you to find that out using ri?

> 4. myBlock = Proc.new { puts "myBlock..." }
> then I intuitively expect to be able to do this:    5.times myBlock
> but it won't work

Do you expect the following code to work?

  5.times Proc.new { puts "myBlock..." }

No, neither did I.  5.times &myblock should work, and it's consistent with the
general syntax for procs.

> 5. Forgiving syntax leaves lots of room to fool yourself. Classical
> example: x = y +z
> It is VERY counter-intuitive to me that this tries to call method y with
> paramter +z instead of adding the two numbers together

Good point.  Consider it an enforcement of good style ;)

> I could go on. Anyway, my point is, as with every language you can't
> just blindly rely on your intuition in Ruby, you have to remember how to
> do some(many?) things. And just as with every other language, once you
> have a feel for it, you can do a lot of things just by pure intuition.
> Ruby may have less things to remember than C++ but it doesn't change the
> big picture.

As others have pointed out, C++ does not fit the rule "And just as with every
other language, once you have a feel for it, you can do a lot of things just by
pure intuition."

It does change the big picture: the surprises in Ruby mostly come at a high
level; the devil is not so much in the detail.

Also, no language is *just* a language.  There are environmental concerns.
Having the sandpit (aka "irb") to play in makes learning the language soooo
much easier.  You ameliorate the surprises before you put them in your code.

Again, you have good points, and it's interesting to hear the POV of someone
from what seems to be a different language background (from the norm).

Cheers,
Gavin