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.
- && 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.
- 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()
- 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?
- 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.
- 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
···
----- Original Message -----
From: âDenys Usyninâ usynin@hep.upenn.edu