I’m a ruby newbie, but an old hand at programming (30 years, more than
a dozen languages). I’m constantly running afoul of “elsif” - as a
native English speaker, my fingers really want to type “elseif”.
Usually the mistake shows up immediately, but not always. For
example, Ruby will parse the little test program given below without
generating an error message, but the output surprised me until I
tracked down my mistake. No error message is generated until you test
the power function with a negative exponent.
To me, that missing “e” is a human factors issue. I realize that
changing the syntax would break virtually all existing code, but would
it be possible to add “elseif” as an alternate syntax? Or am I making
a mountain out of a mole hill?
Hmm. don’t know much about the possibility of adding the
keyword elseif, but you may want to try ‘-w’ to ruby.
I changed the first line to #!/usr/bin/env ruby -w
to get:
else.rb:13: warning: elseif (…) interpreted as method call
else.rb:11: warning: useless use of / in void context
0: 1
1: 1
2: 1
3: 1
4: 1
5: 1
6: 1
7: 1
8: 1
9: 1
Jim
···
On Mon, Aug 19, 2002 at 07:24:38AM +0900, Paul J. Sanchez wrote:
I’m a ruby newbie, but an old hand at programming (30 years, more than
a dozen languages). I’m constantly running afoul of “elsif” - as a
native English speaker, my fingers really want to type “elseif”.
Usually the mistake shows up immediately, but not always. For
example, Ruby will parse the little test program given below without
generating an error message, but the output surprised me until I
tracked down my mistake. No error message is generated until you test
the power function with a negative exponent.
To me, that missing “e” is a human factors issue. I realize that
changing the syntax would break virtually all existing code, but would
it be possible to add “elseif” as an alternate syntax? Or am I making
a mountain out of a mole hill?
–
Jim Freeze
If only I had something clever to say for my comment…
~
Possibly not the solution you were looking for, but if you use an editor
with syntax highlighting, you will receive immediate visual feedback
while typing the ‘elseif’ (i.e. it won’t turn bright yellow or
whatever). This usually catches me with this typo.
-kyle
···
On Mon, Aug 19, 2002 at 07:24:38AM +0900, Paul J. Sanchez wrote:
To me, that missing “e” is a human factors issue. I realize that
changing the syntax would break virtually all existing code, but would
it be possible to add “elseif” as an alternate syntax? Or am I making
a mountain out of a mole hill?
To me, that missing “e” is a human factors issue. I realize that
changing the syntax would break virtually all existing code, but would
it be possible to add “elseif” as an alternate syntax?
Or add synonyms, and not break existing code.
Or am I making a mountain out of a mole hill?
I think it’s a valid point. I’ve tripped up on it myself.
Shell: elif. Tcl: elseif. Python: dunno.
Perl: elsif. Oooohhhh. I see.