From: rantingrick on 22 Jun 2010 21:54 On Jun 22, 7:56 pm, Gregory Ewing <greg.ew...(a)canterbury.ac.nz> wrote: > Thomas Jollans wrote: > > "Everything is an object" in both languages, or so they say. > > That's really a meaningless statement, because it depends on > what you count as a "thing". But there is at least one thing > that is an object in Python but not in Ruby. There are no > stand-alone functions in Ruby, or callable objects in general. > The only way to invoke code is to call a method of some > object. Although i will admit the chaining of methods compared to the nesting of built in functions seems more linear-ly natural as in this case... RUBY: ['one', 'two', 'three'].map{|x| x.capitalize}.join(',') PYTHON ','.join(map(string.capitalize, ['one','two', 'three'])) ','.join(map(lambda x:x.title(), ['one','two', 'three'])) ....but i digress > This can be confusing to someone coming from Python, because > you can write what *look* deceptively like top-level function > definitions. But they actually become methods of class Object, > which is inherited by everything, and thus become implicitly > available in any other method. Yes i call that "Ruby's Global Nightmare" and the folks over at SketchUp are learning day by day how this nightmare is going to undermine the Ruby API. Not only that, but since the API is for scripting it seems more natural to use Pythonic namespaces so you can write simple scripts very easily with one or two functions or complete packages spanning multiple modules without fear of name clashes (ever tried debugging that! 8^O). Of course you can create a module with Ruby (see next comment) > You can ignore the difference until you start trying to > use modules. Ruby has something it calls a "module", but it's > really more like a mixin class. If you try to think of it and > use it like a Python module, you'll get very confused and > frustrated and pull out large chunks of hair. At least I > did until I figured out what was really going on behind the > scenes. I always found it so odd that Ruby uses a special syntax for modules and not just copy the beautiful solution Python has pioneered. Matz, you already copied SOOO much, are you really trying to save face, because it's far too late for that my friend! > Having used both, I find the way that Python handles namespaces > to be greatly preferable. This may be partly because I'm more > familiar with it, but I think there are ways in which it's > objectively simpler and more useful for organising code. Python's way is better. There is no way to argue against it. Globals are bad, redundant end statements are bad, TIMTOWTDI is bad, module declarations are bad, not having docstrings is bad, allowing method calls without parenthesis is bad, using punctuation in identifiers is bad, bad keyword naming choices are bad, need i go on...? I would say check out Ruby if no more than just out of curiosity. You will find the map far more useful, and the linear chaining of methods more natural, but after that there really ain't much more to like! ...although i am sure the word "closure" is coming up *real* soon!
From: MRAB on 22 Jun 2010 22:31 rantingrick wrote: > On Jun 22, 7:56 pm, Gregory Ewing <greg.ew...(a)canterbury.ac.nz> wrote: >> Thomas Jollans wrote: >>> "Everything is an object" in both languages, or so they say. >> That's really a meaningless statement, because it depends on >> what you count as a "thing". But there is at least one thing >> that is an object in Python but not in Ruby. There are no >> stand-alone functions in Ruby, or callable objects in general. >> The only way to invoke code is to call a method of some >> object. > > Although i will admit the chaining of methods compared to the nesting > of built in functions seems more linear-ly natural as in this case... > > RUBY: > ['one', 'two', 'three'].map{|x| x.capitalize}.join(',') > > PYTHON > ','.join(map(string.capitalize, ['one','two', 'three'])) ','.join(x.capitalize() for x in ['one','two', 'three']) > ','.join(map(lambda x:x.title(), ['one','two', 'three'])) > > ...but i digress > >> This can be confusing to someone coming from Python, because >> you can write what *look* deceptively like top-level function >> definitions. But they actually become methods of class Object, >> which is inherited by everything, and thus become implicitly >> available in any other method. > > Yes i call that "Ruby's Global Nightmare" and the folks over at > SketchUp are learning day by day how this nightmare is going to > undermine the Ruby API. Not only that, but since the API is for > scripting it seems more natural to use Pythonic namespaces so you can > write simple scripts very easily with one or two functions or complete > packages spanning multiple modules without fear of name clashes (ever > tried debugging that! 8^O). Of course you can create a module with > Ruby (see next comment) > [snip] Napoleon once said "Never interrupt your enemy when he is making a mistake."! :-)
From: rantingrick on 22 Jun 2010 23:25 On Jun 22, 9:31 pm, MRAB <pyt...(a)mrabarnett.plus.com> wrote: > [snip] > Napoleon once said "Never interrupt your enemy when he is making a > mistake."! :-) And how exactly does your example express itself in a more "syntactically-correct" "linear-flow" than the two code snippets i provided earlier, hmmm? PS: Oh yes i do know about generators and *even* list comprehensions. They are some of my favorite Python syntactic sugars. But heck there are so many tasty sugars in Python i guess the only thing a Python noob should really worry about is premature tooth decay! ;-)
From: David Cournapeau on 23 Jun 2010 01:00 On Tue, Jun 22, 2010 at 5:58 PM, Josef Tupag <joseftupag(a)gmail.com> wrote: > I've been programming (when I do program) mainly in Perl for the last 10 > years or so. But I've been itching to learn a new language for a while now, > and the two near the top of the list are Ruby and Python. > > I figure that Ruby would be easy to learn because of its similarity to Perl > (I'm told). But I also figure that Python would be easy to learn because of > its simplicity. And when it comes to webby stuff, I can use Rails with Ruby > and Django with Python. I think it does not matter much. It matters much more that you know one of them really well rather than both of them so so. There are some stuff in python without any equivalent in ruby AFAIK, things like numpy/scipy. I am sure the contrary is true as well, but I don't enough about ruby to have an informed opinion. cheers, David
From: Stephen Hansen on 23 Jun 2010 01:51
On 6/22/10 10:39 PM, Dennis Lee Bieber wrote: > On Tue, 22 Jun 2010 15:55:51 -0700, Stephen Hansen > <me+list/python(a)ixokai.io> declaimed the following in > gmane.comp.python.general: > >> I second Forth. Learning and using that was -- slightly painful, but > > Just pick up any advanced HP programmable calculator... RPL is a > close substitute <G> That's just a start. The reverse and stack-oriented nature of the language makes you have to start thinking in an interesting way, and sure, a RPL/stack-calculator can get that for you. But then going on and doing real programming with it, making your own words (functions), ... its fun. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ |