On Oct 4, 2006, at 3:39 PM, Kevin Olemoh wrote: > Hello I have been using ruby off and on for a few months and I have > been having a great time with the language but a few things bother > me about the syntax of the language itself. The two glaring issues > are: > > 1. The syntax errors generated by the following code: > > a.each > do > #stuff > end > > for reasons I do not understand ruby demands that, that line be > written as: > a.each do > #stuff > end Blocks are part of the syntax of a method call (do/end or {}) Blocks are optional. Newlines terminate statements. The net result of those three things is that: a.each is considered a syntactically valid and complete statement. Leaving Ruby to try to interpret do #stuff end as the next statement, which fails. If Ruby executes 'a.each' (without the block) you'll get a runtime exception. It is correct syntax, but 'each' insists that it be called with a block. You could of course give a hint to the parser that you want to continue the statement: a.each \ do #stuff end but escaping the newline in this case doesn't improve the readability (IMHO). > 2. What is with the elseif syntax specifically why is it elsif > instead of elseif when ruby already has an else keyword? I can't > count how many times I got errors because I decided to type elseif > instead of elsif while doing something with an if statement. I can > name at least two popular languages that use elseif not to mention > the fact that if English is your first language you will probably > spell out else without even realizing it since that is the correct > way to spell the word in English. Yes I know its a minor thing > but if no one voices their gripes how do people know something > might need a bit of tweaking? :) I doubt a survey of languages would come up with any sort of consistency for the keyword in this case, so you are basically asking why doesn't Ruby use the same syntax for the particular languages that you are familiar with, which seems like a somewhat arbitrary expectation and one that could never be satisfied for everyone. I'm not a parsing/grammar expert, but I also suspect there is some benefit to keywords not being prefixes of other keywords so that 'else' and 'elseif' create more parsing issues than 'else' and 'elsif'. I'm sure someone else could elaborate on that thought. Gary Wright