thehotelambush
> you can import the rational class via a simple from fractions import Fraction
Sure, you can write a library for anything and by now Python has libraries for most everything. But it still makes a difference to have things in the core language, plus a nice syntax for them.
> why would you want to use lambdas if you have generator expressions?
This is a case of making up for odd semantic choices with special syntax, which then becomes an unnecessarily fixed-in-stone part of the language. Range objects in Ruby are actually like slice objects in Python. But Ruby separates the syntax for ranges from the get-item method, since there are plenty of other places where you would want to use ranges (then you can iterate and map over them, etc.).
Ruby uses blocks to implement things like an each method that fulfills the same function as Python's for statement. (Ruby has a for statement but it is hardly ever used.) In Ruby your example would be
countries.split(',').map &:strip
which is obviously more concise and no less readable. Compare with
countries.split(',').each &:foo
where foo is some side-effectful method.
IMO such a small change in behavior should result in a similarly small change in how the program is written.
-no distinction between expression and statement (everything has a value)
-lambdas can thus contain any expression
-much bigger range of built-in methods and classes (all permutations of a list, removing duplicates from a list, Rational class, Regexp class, Range class, etc.)
-more flexible syntax and "control operators" like each_with_index
-almost zero distinction between built-in classes and methods and user-written ones: you can open up Hash (dict) or Array (list) and extend it straightforwardly.
Downsides are:
-generally uglier and more ambiguous syntax
-distinction between functions and methods (b/c "all you can do is send a message") leads to a lot of unnecessary duplication of concepts
-so-called "blocks" which are really just a hack to avoid writing the word "lambda" a bunch of times (maybe if the more concise Ruby 1.9 syntax for lambdas had existed earlier blocks wouldn't have been implemented). I think they are based on the idea that most HOFs only require one functional argument, and they encourage functional programming, but they (along with the last bullet point) discourage the general case. They provide some of the functionality of macros.
-you can't define a class inside a method (still haven't quite figured out the reasoning behind this one).
In general Ruby is definitely more powerful than Python, but in its higher ambitions suffers more obviously from clashes between functional and OO programming. Python's dogmatic insistence on "readability" makes it feel like an old grandma in comparison to Ruby.