From: Tomas Pospisek Date: 2008-11-09T05:08:29+09:00 Subject: [ruby-core:19748] [Feature #729] curly brackets" and "begin end" blocks should behave syntactically and semantically exactly the same Feature #729: curly brackets" and "begin end" blocks should behave syntactically and semantically exactly the same http://redmine.ruby-lang.org/issues/show/729 Author: Tomas Pospisek Status: Open, Priority: Normal Category: core (transported over from rubyforge #16111, as I still think this would be worth while...) Every now and then I run into a "principle of least surprise" violation wrt blocks in Ruby. The most primitive problem i have is this: why does the following work: # the code below is grouped together because it represents # a semantic whole: begin do_something and_then_something_else end but this here bails out with a syntax error: # the following code is grouped together because it represents # a semantic whole: { do_something and_then_something_else } In every other language I know that has curly braces as block delimiters, the above is alowed and _natural_. Except Ruby. The above code is a special case. I am not sure it can be fixed without breaking Ruby syntax as a whole. I _think_ it can. To me "curly brackets" and "begin end" should act semantically and syntactically exactly the same. I.e. all the following forms should IMHO be allowed and identical: if condition end if condition begin end if condition { } The same would apply to all other ruby control structures. Unfortunately it seems it is not be possible to fix the general case without breaking Ruby since Ruby expects that "condition" above could also in itself be a block since both: if { condition } end and if begin condition end end are allowed and make sense, but contradict my wish above, since allowing the above proposed change would actually make the syntax more ambiguous and make it _harder_ for the parser to help the programmer with syntax errors. ---------------------------------------- http://redmine.ruby-lang.org