10 Unique Ruby Features
The 10, but 3 (implicit return values) and 8 (only nil+false are False) are negative features.
FYI here's the 10 and how they compare with Python:
- Objects everywhere! -- Python supports OO but not solely, and has strong reflection features regardless of objects or not
- Blocks -- Python's function objects and 'with' keyword and list comprehension provide almost the same net result.
- Implicit return value in methods -- Python doesn't do this (thankfully)
- In Ruby everything is open! -- Python's comparable (but see below)
- Missing unary operators in Ruby -- Python's comparable
- Ruby supports parallel assignment -- Python's comparable
- In Ruby strings are mutable -- Python strings are immutable, but operations are performed on them (unlike Java and StringBuffer/StringBuilder) so comparable in almost all ways (Ruby wins on a few exotic cases, Python wins on some of the common cases - slight edge to Python).
- True and false in Ruby -- Python has sane evaluations for True and False
- Native support for ranges and regular expressions -- Python's regular expressions are as functional as Ruby but lack some of the notational convenience. Python has nothing like Ruby's Ranges (a cool feature, though rarely used in my experience)
- Method indicators -- Python doesn't do this
On #4, Ruby provides access control via the usual public/protected/private keywords, but it's a lie as you can trivially access protected and private symbols (even unknowingly). Python eschews such false protections and follows the convention things-with-a-leading-underscore-are-not-'meant'-for-public-consumption. All in all, I prefer Python's approach on this one. Ruby's solution sounds good at first (especially if you have C++ or Java experience), but in practice the Python solution works and 'feels' better.
For those looking to tally up a score card:
- Tie
- Slight edge to Ruby
- Python
- Tie
- Tie
- Tie
- Tie. Ruby's mutable-and-immutable-string-methods are an unnecessary complexity in the common cases, but are slightly advantageous in some exotic scenarios. Overall, they're comparable.
- Python
- Slight edge to Ruby. Ranges are handy but not overly significant, and Ruby's regex notation is more convenient for simple comparisons but falls into the ugly-Perl-mess beyond that (x=~/\s*(\w+)\s*/ ; puts $1). If you use Ruby's non-Perl-isms (e.g. Match object) then it's no different from Python.
- Slight edge to Ruby. I personally like the ? and ! suffixes to indicate boolean and mutable methods, but in the end they're just convention; good symbol names matter more. Of course if I get to choose, I'd take both :-)
Python and Ruby are different, but have a lot of common properties.
And in the end, the library and frameworks are at least as important (or more so) than the language.