From: Greg McIntyre Date: 2003-03-21T10:00:03+09:00 Subject: Re: Strong advantages over Python Good list. Amalgamated with http://www.ruby-lang.org/en/whats.html, it should make a concise enough list of advantages. Travis Whitton wrote: > o Super easy to extend with C modules Yup. Although with SWIG... > o The power of mixing in Enumerable > o Simplicity of mixins vs multiple inheritance Debatable but okay. I would think about this point differently. Ruby has a simple object model - objects are a bunch of variables and methods, and Ruby gives you the means to add/subtract/edit them with a lot of power. > o A builtin class library small enough to memorize but powerful enough > to do basically anything you want This is something I love about Ruby over Python. I hate the Python library reference -- it's *so* hard to find what you want to do using it. Whereas on the off chance you actually need to look something up while programming Ruby (as most things work by Ruby reading your mind), you generally know exactly where to look for it. So yes, that's an important practical difference, IMO. > o Total syntactic consistency(everything is an object) > 5.times {|num| ...} > "foo".reverse > o Stronger typing(everything has a specific type) > 1.type => Fixnum Some examples of the benefits of pure OOP. I use "have a nice day".split a fair bit, but Python can do that too so it makes it less enjoyable. ;) ['dir1', 'dir2', 'filename'].join(File::Separator) might be a better example. This also relates to the fact that you generally know where to look for a particular method in Ruby. In Python, join is a function defined in the string module. How I was supposed to know that without popping up the huuuge index page of the library reference and searching for 'join', I don't know. > o Truly private data instead of name mangling Yes! There can be some excellent examples of this too. > o No equivalent of a do ... while statement Ah! I didn't know that. How... Eiffelish. > o self.myvar vs @myvar Not necessarily an advantage... > o No closures in Python? Okay. I'm no Python expert, but... Python 2.2 is a bit better. They're still not the same however. AFAIK you use lambdas in Python to create closures (assigning the lambdas to variables and calling them later on). But lambdas expect 'expressions' not 'statements' meaning you can only do a very limited number of things in your Python closure. Also, you cannot assign to a variable which is in a closure's context but outside its direct scope (e.g. something assigned just above a Ruby block). There are dirty tricks to get around it but they're difficult and ugly. Hrm... there might be some other differences too. In Python you can assign function names to variables and then call them through those variables, however AFAIK this relies on separate function definitions and global variables in order to achieve the same level of context manipulation possible with a Ruby block, so it certainly isn't as clean and easy. I'd appreciate it if the more Python-inclined could correct or confirm all that. -- Greg McIntyre greg@puyo.cjb.net http://puyo.cjb.net