From: bbiker Date: 2007-05-22T00:40:04+09:00 Subject: Re: How to adopt "Python Style" indentation for Ruby On May 21, 3:32 am, Brian Candler wrote: > On Mon, May 21, 2007 at 03:53:25PM +0900, Giles Bowkett wrote: > > What would it take to write a Ruby pre-processor which parsed Ruby > > written in a Pythonic style and turned it into actual valid Ruby? Or > > even a Ruby library like Xavier's Perl example, which allows you to > > code Ruby as if it were Python after just requiring the library? The > > original post's main argument was that indentation is a stable, > > consistent shorthand for Ruby's end statements. If all you're looking > > to do is use tabs as syntactic sugar, then it should be pretty easy to > > just write something which knows how to translate a sequence of tabs > > in and tabs out into a series of end statements at the end. > > Actually, I'd happily settle for something simpler: a pretty-printer which > just reads (normal) Ruby and re-outputs it with standard indentation. > > This would immediately solve the problem of "where did I miss out an 'end' > statement?" - you'd just pipe it into this utility and inspect. In the past > I've had to resort to binary chops to solve this: copy source.rb to x.rb and > remove chunks of method definitions until I find the offending one. This is > painful. > > As an alternative: the existing Ruby parser could be modified to spit out a > warning whenever it sees non-standard nesting, e.g. "end at line doesn't > align with start of block/method at line ". It only need do this for an > 'end' which is at the start of a line. > > Regards, > > Brian. I use Arachono Ruby IDE. Its editor has a feature whereby I can select a number of lines to comment out or uncomment the lines. This makes finding the missing end fairly easier. I find python indentation much harder to read. For my use, I rather stick with the "end"s.