From: Ben Giddings Date: 2005-05-13T02:14:16+09:00 Subject: Re: {} vs begin/end [was Re: object loops and what they return] On Thursday 12 May 2005 10:32, Jim Weirich wrote: > I use to pitch my tent in the one line => braces camp. But every time my > one liner tent grew to more than one line, they made me repitch my tent > using begin/end tent stakes. That's when I moved to the return value => > brace camp. > > BTW, I do regularly hike up to the ternary operator camp as well, so I'll > see you there. So, am I the only one that sees the question "do I use braces or do/end" as being a problem with Ruby? One of the strengths Ruby has over Perl is that there may be more than one way to do things, but generally it feels like there's one way that'e easier. The easiest way turns often turns out to be the right way. As a result, most people's code ends up looking pretty similar. This duality of braces and do/end is a glaring example of a case where this isn't true. There's no inherent reason why someone should choose do/end or braces. It's all personal preference. As a result, people make up their own reasons for using one, or the other, or both but under different circumstances. For a while I always used braces because blocks really are different. You only really notice this difference when you're trying to run code in a debugger. When you do that, stepping to the "next line" takes you all over the place until eventually something calls 'yield' and you finally step into the block. Because of that, I used braces all the time to note that blocks were special. Now I sorta follow the convention that one-liners are braces, the rest are do-end, but I don't like it. The problem is that { a >= b } and { a => b } sure look pretty similar but one's a block the other is a hash. I know it's way too late for the Ruby 1.X series, but I'd like to see a change for Ruby 2 that reserved braces for hashes and blocks had to have do/end. Thoughts? Ben