From: Paul Prescod Date: 2003-03-21T11:40:22+09:00 Subject: Re: Strong advantages over Python Greg McIntyre wrote: >... > > > 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. Sounds like a description of Python to me. ;) > ... > 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. If that's your experience then you're entitled to it! I sometimes find the Python library messy but certainly no more so than Java or other languages I have used. Perhaps Ruby is the exception, I've only tinkered with it. > 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. >>> import os >>> print os.sep / >>> os.sep.join(["dir1", "dir2", "dir3"]) 'dir1/dir2/dir3' >>> print type(os.sep) > 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. Several versions of Python ago. This was changed in Sept 2000. http://www.python.org/doc/current/lib/string-methods.html http://www.python.org/1.6/ > 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). This is incorrect. Lambdas are syntactic sugar for function definitions. There is nothing you can do with lambdas that you could not do with regular functions. > ... 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). That much is true. IMHO it's pretty rarely needed in object oriented programming but it is nevertheless true that it is clunky in Python. > 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'm having trouble following this bit. It's true that you can't directly overwrite a variable in a surrounding context. I don't know that this has anything to do with assigning function names to variables or global variables or anything. The usual workaround is to mutate an object rather than overwriting a variable. def a(): state = {} def putin(x): state["something"] = x def getout(x): return state["something"] return putin, getout But every example I see of this seems contrived to me. You're trying to build a "thing" which has both mutable state and functional behaviour. Well, in OO languages we tend to call those things objects. class a: def putin(self, x): self.something = x def getout(self, x): return self.something > I'd appreciate it if the more Python-inclined could correct or confirm > all that. Hope that helps. Just out of curiousity, will there be anybody at this university describing the things Python can do better than Ruby? It sounds like the professor is not knowledgable enough to do that. Perhaps he wants you to present both sides? Paul Prescod