News for hackers. Stuff that matters.
Re:Ruby is beautiful (but I'm moving to Python) by ashleyw on Monday November 29, 2010 @06:23AM (#1949971)
Well, I was comparing it to something like Java. Though Python still scores far lower on my readability scale. It's seems like it's halfway to being minified, the lines are chock-a-block.

Also, this is a better version in Ruby:

    file = File.open('customers.txt')

    customers = {}
    file.each_line do |line|
      name, age = line.split(",")
      customers[age.to_i] ||= []
      customers[age.to_i] << name
    end

    grouped = customers.sort_by{|age, names| names.count}.reverse

    grouped.first(3).each do |age, customers|
      puts "#{age} years old: #{customers.count} customers"
    end

…not sure what I was thinking before, it was late.
Re:Ruby is beautiful (but I'm moving to Python) by anthonyb on Monday November 29, 2010 @05:39PM (#1952117)
> Python still scores far lower on my readability scale. It's seems like it's halfway to being minified, the lines are chock-a-block.

That's likely because you're not used to reading Python. For me, Ruby seems unreadable - you have all these weird << and ||= assignments, {||} blocks, etc. I don't parse those as well, because I don't program much Ruby. I'm sure if I did, it'd make a lot more 'intuitive' sense - ditto for you and Python's list comprehensions.

Re:Ruby is beautiful (but I'm moving to Python) by nwmcsween on Wednesday December 01, 2010 @12:29AM (#1956943)
<< and >> are rudimentary it's almost always exactly the same as unix dated from 1970's redirection. e.g: $ echo 'crap' >> somefile.txt. ||= reads as 'or equal', simple.
Re:Ruby is beautiful (but I'm moving to Python) by anthonyb on Monday December 06, 2010 @12:31AM (#1974063)
Yeah, I know what they do - eg. ||= being a Ruby idiom for 'set if this currently evaluates as false'. The point is that because I don't often program in Ruby, it's less readable (for me). Similarly, if you're not used to list comprehensions they'll seem opaque - but I use them all the time, and find them far more readable than equivalent expressions using map/filter.

That said, I do find the more "squiggly" languages (Perl, Ruby, C) to be less readable than the equivalent Scheme or Python, and I suspect that it's because there are fewer weird characters, so it's closer to English.