From: Rudolf Polzer Date: 2002-09-27T06:37:23+09:00 Subject: Ruby - common pitfalls? Is there a list of common pitfalls beginners in this language should watch out for? I noticed (I just started with Ruby and it has almost replaced Perl): - the if syntax. Pascal-style if is supported (and one is tempted to use it instead of the also supported C-style if since parantheses aren't easy to enter on most keyboards), but comparisons have to be written in C style. Therefore this happened to me more than once: if foo = nil then # ... end It's getting even worse because nil is named 'nil', like it is in Pascal. The C-style syntax is: if (foo == nil) # ... end and works perfectly. If only ( and ) were accessible without using the shift key... - accessing one character in a string. s[3] does not do what most programmers would expect: it returns a *number*. JavaScript is cleaner in this thing - there are both .charAt () and .charCodeAt (). IMHO s[n] should return the character as a string of length one, not the value - but now it's too late to change this. The current meaning is not bad, it's just unusual. s[3, 1] is to be used instead. - a %= b versus %=...=. A syntax highlighter gets into big trouble when seeing this construct. Nothing really seriuos, but I already had to insert "useless" comments to fix vim's highlighting - which is unable to correctly highlight if-then-end expressions. Perhaps it would help to deprecate %=...= as string separator (any other character could be used with less problems). BTW: what about this extension: a, b += c, d which would be equivalent to a += c b += d and perfectly accepts list arguments: *a += *b Maybe even *a = *b + *c would be possible? Or perhaps instead: a.zipWith! (b) do |x, y| x + y end # slightly resembling Haskell a = b.zipWith (c) do |x, y| x + y end which is a bit more verbose, but can be done with the current syntax. Another idea for the above thing: an ArithArray class that is nearly identical to the normal Array with one exception: the arithmetic and logical operators work element-wise with the original meaning (so even == would return a new array of true or false values). -- [mpg123d] Just playing: .../01 cruel angel's thesis - director's edit - -ayanami-.mp3 Shinu no wa iya. Shinu no wa iya. Shinu no wa iya. Shinu no wa iya. [Asuka in Neon Genesis Evangelion - english: "I don't want to die",