From: Ryan Paul Date: 2004-05-13T01:38:54+09:00 Subject: Re: in search of a compelling reason to use ruby.... On Mon, 10 May 2004 10:42:02 +0000, Ryan Paul wrote: > i'm a python programmer, and I have recently been hearing a lot about > ruby. A lot of python people seem to think ruby is in some way inferior, > but I have yet to find any significant differences between the languages. > The only differences I have found so far have been superficial syntactic > things. The only real significant difference I have detected, is the > absence of a module system in ruby. > > I would like to be able to make an objective and educated comparison. Ruby > seems to have a relatively small, but intensely devoted following. > Software that inspires such fervent support from a small community usually > possesses tremendous power that most people are just too dense to discern > (eg: ocaml, and BeOS). Consequently, I figured it would be worth my time > to find out what it is that the fanatics find appealing. > > I am looking for: > - examples of tangible features that ruby has, which python doesnt. > - examples of scenarios where some facet of, or property specific to > ruby contributed to the simplification or improvement of a programming > project. > - facets of the language which may not necessarily be useful, but are > notably creative/innovative. > > Additionally, I realize that there is more to a language than its syntax > and functionality. As a result, I am also interested in hearing about > facets of the ruby community and ruby ideology, and anything else that > ruby programmers feel contribute to their affinity for the language. > > I have a feeling that most of the things that make ruby worth using can > also be found in python. From the perspective a python programmer who has > taken only a precursory glance at ruby, it looks like ruby suggests a > functional style, while python suggests an imperative style. It also looks > like ruby may be better suited for quick shell scripts, whereas python is > better suited for bigger programs. I realize that I probably suffer from > misconceptions, and i'm looking forward to having them corrected. > > I sincerely hope nobody finds any of my comments offensive, I dont mean > them as criticisms of ruby. I intentionally withhold criticisms until I am > better versed in the benefits! > > Thanks in advance! > -- SegPhault Some general conclusions: I've learned quite a bit more ruby, and i've ported a bit of python code by hand for exercise, and I think I can now safely make some useful generalizations about the differences between the two languages. Python is simple and consistent, it promotes uniform style between programs and programmers. Python also works very hard to prevent the programmer from doing something that might make the language inconsistent, and it's design often enforces a clear, and concise imperative design. Syntactic shortcuts and things like native regular expressions are sacrificed to ensure maximum maintainability and readability. Ruby is flexible and syntactically mutable. It allows programmers to alter the behavior of the language itself in contexts where it may be beneficial to do so. It promotes self extension and alteration, and it introduces a lot of additional (largely optional) complexity that imbues the language with the capacity to be, at times, rather arcane. In many cases, ruby provides convenient syntactic shortcuts to automate things that would have to be done manually in python. Ruby idioms dont feel as instantly intuitive as python idioms, but they seem a great deal more natural. I would definitely say that learning ruby is a greater challenge than learning python. I would describe several facets of ruby as 'mind altering'. Ruby's OO is significantly better than python's. Ruby promotes (and practically implies) good OO techniques and methodology. This is mostly a result of Ruby's practice of making all instance variables private, and the use of a rather elegant means of customizing variable access. A few examples: Blocks are a rather simple concept, but they are, initially, extremely hard to understand, simply because there is nothing else like them. Python does not provide any profoundly novel or innovative syntactic constructs, so it easy for any object oriented programmer to grasp. The axiomatic syntactic classes in python (lists, strings, integers) are completely and totally immutable. Python does NOT allow you to change or extend these classes in any way. This is done to ensure utter uniformity, but it cripples the programmer immensely. Guido Van Rossum, in one of his essays, says that python could easily support this feature, but he intentionally chose to disallow it to ensure that programmers wouldn't accidentally break each others libraries, or the python base libraries for that matter. Programming around ideology like that is like trying to carve a sculpture with safety scissors. In python, we have map, filter, and list comprehensions, all of which can be used to manipulate lists in very general ways. In order to do certain things, python users have to stack multiple functions into map statements. Generally, this is actually pretty simple to do, and makes things somewhat intuitive. In ruby, there are a multitude of rather oddly named array functions that have very specific behaviors, most of which can be used with blocks to concisely describe extremely sophisticated operations. In conclusion, I feel that python, because of its steadfast consistency, might be more appropriate for corporate applications, but for power scripters, who need power and flexibility, nothing beats ruby. I'd like to know if ruby supports something like C++ namespaces, because something like that would probably vastly decrease the destructive potential of inconsistency, without killing its usefulness. I've suggested such a feature several times in the python world, but nobody seemed to see the benefit. --SegPhault