From: dblack@... Date: 2005-12-08T11:34:36+09:00 Subject: Re: They say I write Ruby like Perl Hi -- On Thu, 8 Dec 2005, Steve Litt wrote: > Hi all, > > I wrote some hierarchy handling classes in Node.rb > (http://www.troubleshooters.com/projects/Node.rb/index.htm), and I've been > told I write Ruby in Perl style. In future software, what could I do to write > in a more Ruby-like fashion? > For style things (avoiding camelCase for methods and local variables, two-character indentation, etc.), you can look at (most of :-) the Ruby code in the standard library. Also there's a good style guide at: http://pub.cozmixng.org/~the-rwiki/rw-cgi.rb?cmd=view;name=RubyCodingConvention (not beyond dispute in every detail but very much in harmony with traditional Ruby style). Looking a bit at the code itself, I think there's a certain amount of verbosity that you could cut down on -- and still be nice and clear (which is an area where Ruby shines). For example, you have this: def counttabs(s) answer = s.index(/[^\t]/) answer = 0 if not answer return answer end which could be: def counttabs(s) s.index(/[^\t]/) || 0 end (I'm not sure about the name -- it's not actually counting tabs -- but I'll leave that to you :-) Of course there's no imperative to make things as short as they can be -- but one thing I like about Ruby is that one's code tends to get more concise *and* to get more clear, as one works on a project. David -- David A. Black dblack@wobblini.net "Ruby for Rails", forthcoming from Manning Publications, April 2006!