Jules Jacobs wrote: > Hi, > > Which syntax do you like most? > # Ruby style > > if a == 10 > print a > end I prefer: print a if a == 10 > > 2. Rails' link_to > ----------------- > > link_to 'Show', :action => :show, :id => @post I prefer this one. It is the easiest to visual parse imo. > > 3. Classes > ---------- > > # Ruby > > class Foo > def method > print 'hi' > end > end I prefer this. > > 4. Loop > ------- > > 5.times i > print i > > 5.times do |i| > print i > end > > for 0, 5, i > print i > end For multi-line loops I prefer the do/end syntax if you are *not* using the return value. I prefer {} for one line loops unless you are using the return value. Examples: 5.times{ |i| print i } 5.times do |i| #do something here end > > 5. Map > ------ > > arr = [1, 2, 3] > > arr.map{|e| e * 2} > > arr.map do |e| > e * 2 > end If you are going to use the return value of 'map', I prefer to use {}. I you aren't going to use the return value and it is a one liner, I prefer to use {}. If you aren't going to use the return value and it is not a one liner then use the do/end block. > > arr.map(e, e * 2) As already pointed out it looks like your passing arguments. > > ;-) > > -------------- > > I am trying to imagine the 'perfect' scripting language (for me, at > least ;-)). Ruby is close, but I prefer a different syntax in some > cases. I find the indentation-based code-blocks nicer than > do...end-blocks. I don't think an indendation style should drive the syntax and meaning of code. This is one of the reasons I dont like Python. Paul's analogy of the motoroboat and the ocean is a great analogy imo. > > I also prefer this: > > arr.map(e, e * 2) > > or: > > # parentheses are optional > arr.map e, e * 2 > > to this: > > arr.map{|e| e * 2} I disagree, I think |e| makes it easy to visually parse what is going on. It also lets you bind the value you are passing in to a variable name that makes sense to that block of code. > > I'm not sure whether or not default variable names like this: > > arr.map(e * 2) > > are a good thing... > > What do YOU like, and why? Your map example is an easy example though. How would you consistently support things like? { :hash=>true }.each { ??? } [1,2,3,4,5].inject( 0 ) { ???? } Here I like the flexibility of ruby to name the variable I am going to bind the passed in value to. string.each_line{ |line| puts line.gsub /a/, '*' } files.each { |filename| ... } File.open 'file.txt', 'w' do |file| file.each{ |line| ???_what happens here_??? } end And as you get more code in your blocks I think it makes more sense to be able to provide a variable name that makes sense for the block of code you're executing. I think |varname| is an easy way to visually parse out that this value is getting passed in here. Commas are list separators. By giving them double meaning would make it confusing for a new user of your language. Just my 2 cents. Zach