What's better about Ruby than Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Martelli

    #16
    Re: What's better about Ruby than Python?

    Erik Max Francis wrote:
    [color=blue]
    > "Brandon J. Van Every" wrote:
    >[color=green]
    >> What's better about Ruby than Python? I'm sure there's something.
    >> What is it?[/color]
    >
    > Wouldn't it make much more sense to ask Ruby people this, rather than
    > Python people?[/color]

    Might, or might not, depending on one's purposes -- for example, if
    one's purposes include a "sociologic al study" of the Python community,
    then putting questions to that community is likely to prove more
    revealing of informaiton about it, than putting them elsewhere:-).

    Personally, I gladly took the opportunity to follow Dave Thomas'
    one-day Ruby tutorial at last OSCON. Below a thin veneer of syntax
    differences, I find Ruby and Python amazingly similar -- if I was
    computing the minimum spanning tree among just about any set of
    languages, I'm pretty sure Python and Ruby would be the first two
    leaves to coalesce into an intermediate node:-).

    Sure, I do get weary, in Ruby, of typing the silly "end" at the end
    of each block (rather than just unindenting) -- but then I do get
    to avoid typing the equally-silly ':' which Python requires at the
    _start_ of each block, so that's almost a wash:-). Other syntax
    differences such as '@foo' versus 'self.foo', or the higher significance
    of case in Ruby vs Python, are really just about as irrelevant to me.

    Others no doubt base their choice of programming languages on just
    such issues, and they generate the hottest debates -- but to me that's
    just an example of one of Parkinson's Laws in action (the amount on
    debate on an issue is inversely proportional to the issue's actual
    importance).

    One syntax difference that I do find important, and in Python's
    favour -- but other people will no doubt think just the reverse --
    is "how do you call a function which takes no parameters". In
    Python (like in C), to call a function you always apply the
    "call operator" -- trailing parentheses just after the object
    you're calling (inside those trailing parentheses go the args
    you're passing in the call -- if you're passing no args, then
    the parentheses are empty). This leaves the mere mention of
    any object, with no operator involved, as meaning just a
    reference to the object -- in any context, without special
    cases, exceptions, ad-hoc rules, and the like. In Ruby (like
    in Pascal), to call a function WITH arguments you pass the
    args (normally in parentheses, though that is not invariably
    the case) -- BUT if the function takes no args then simply
    mentioning the function implicitly calls it. This may meet
    the expectations of many people (at least, no doubt, those
    whose only previous experience of programming was with Pascal,
    or other languages with similar "implcit calling", such as
    Visual Basic) -- but to me, it means the mere mention of an
    object may EITHER mean a reference to the object, OR a call
    to the object, depending on the object's type -- and in those
    cases where I can't get a reference to the object by merely
    mentioning it I will need to use explicit "give me a reference
    to this, DON'T call it!" operators that aren't needed otherwise.
    I feel this impacts the "first-classness" of functions (or
    methods, or other callable objects) and the possibility of
    interchanging objects smoothly. Therefore, to me, this specific
    syntax difference is a serious black mark against Ruby -- but
    I do understand why others would thing otherwise, even though
    I could hardly disagree more vehemently with them:-).

    Below the syntax, we get into some important differences in
    elementary semantics -- for example, strings in Ruby are
    mutable objects (like in C++), while in Python they are not
    mutable (like in Java, or I believe C#). Again, people who
    judge primarily by what they're already familiar with may
    think this is a plus for Ruby (unless they're familiar with
    Java or C#, of course:-). Me, I think immutable strings are
    an excellent idea (and I'm not surprised that Java, independently
    I think, reinvented that idea which was already in Python), though
    I wouldn't mind having a "mutable string buffer" type as well
    (and ideally one with better ease-of-use than Java's own
    "string buffers"); and I don't give this judgment because of
    familiarity -- before studying Java, apart from functional
    programming languages where _all_ data are immutable, all the
    languages I knew had mutable strings -- yet when I first saw
    the immutable-string idea in Java (which I learned well before
    I learned Python), it immediately struck me as excellent, a
    very good fit for the reference-semantics of a higher level
    programming language (as opposed to the value-semantics that
    fit best with languages closer to the machine and farther from
    applications, such as C) with strings as a first-class, built-in
    (and pretty crucial) data type.

    Ruby does have some advantages in elementary semantics -- for
    example, the removal of Python's "lists vs tuples" exceedingly
    subtle distinction. But mostly the score (as I keep it, with
    simplicity a big plus and subtle, clever distinctions a notable
    minus) is against Ruby (e.g., having both closed and half-open
    intervals, with the notations a..b and a...b [anybody wants
    to claim that it's _obvious_ which is which?-)], is silly --
    IMHO, of course!). Again, people who consider having a lot of
    similar but subtly different things at the core of a language
    a PLUS, rather than a MINUS, will of course count these "the
    other way around" from how I count them:-).

    Don't be misled by these comparisons into thinking the two
    languages are _very_ different, mind you. They aren't. But
    if I'm asked to compare "capelli d'angelo" to "spaghettin i",
    after pointing out that these two kinds of pasta are just
    about undistinguishab le to anybody and interchangeable in any
    dish you might want to prepare, I would then inevitably have
    to move into microscopic examination of how the lengths and
    diameters imperceptibly differ, how the ends of the strands
    are tapered in one case and not in the other, and so on -- to
    try and explain why I, personally, would rather have capelli
    d'angelo as the pasta in any kind of broth, but would prefer
    spaghettini as the pastasciutta to go with suitable sauces for
    such long thin pasta forms (olive oil, minced garlic, minced
    red peppers, and finely ground anchovies, for example - but if
    you sliced the garlic and peppers instead of mincing them, then
    you should choose the sounder body of spaghetti rather than the
    thinner evanescence of spaghettini, and would be well advised
    to forego the achoview and add instead some fresh spring basil
    [or even -- I'm a heretic...! -- light mint...] leaves -- at
    the very last moment before serving the dish). Ooops, sorry,
    it shows that I'm traveling abroad and haven't had pasta for
    a while, I guess. But the analogy is still pretty good!-)

    So, back to Python and Ruby, we come to the two biggies (in
    terms of language proper -- leaving the libraries, and other
    important ancillaries such as tools and environments, how to
    embed/extend each language, etc, etc, out of it for now -- they
    wouldn't apply to all IMPLEMENTATIONS of each language anyway,
    e.g., Jython vs Classic Python being two implementations of
    the Python language!):

    1. Ruby's iterators and codeblocks vs Python's iterators
    and generators;

    2. Ruby's TOTAL, unbridled "dynamicity ", including the ability
    to "reopen" any existing class, including all built-in ones,
    and change its behavior at run-time -- vs Python's vast but
    _bounded_ dynamicity, which never changes the behavior of
    existing built-in classes and their instances.

    Personally, I consider [1] a wash (the differences are so
    deep that I could easily see people hating either approach
    and revering the other, but on MY personal scales the pluses
    and minuses just about even up); and [2] a crucial issue --
    one that makes Ruby much more suitable for "tinkering" , BUT
    Python equally more suitable for use in large production
    applications. It's funny, in a way, because both languages
    are so MUCH more dynamic than most others, that in the end
    the key difference between them from my POV should hinge on
    that -- that Ruby "goes to eleven" in this regard (the
    reference here is to "Spinal Tap", of course). In Ruby,
    there are no limits to my creativity -- if I decide that
    all string comparisons must become case-insensitive, _I CAN
    DO THAT_! I.e., I can dynamically alter the built-in string
    class so that
    a = "Hello World"
    b = "hello world"
    if a == b
    print "equal!\n"
    else
    print "different! \n"
    end
    WILL print "equal". In python, there is NO way I can do
    that. For the purposes of metaprogramming , implementing
    experimental frameworks, and the like, this amazing dynamic
    ability of Ruby is _extremely_ appealing. BUT -- if we're
    talking about large applications, developed by many people
    and maintained by even more, including all kinds of libraries
    from diverse sources, and needing to go into production in
    client sites... well, I don't WANT a language that is QUITE
    so dynamic, thank you very much. I loathe the very idea of
    some library unwittingly breaking other unrelated ones that
    rely on those strings being different -- that's the kind of
    deep and deeply hidden "channel", between pieces of code that
    LOOK separate and SHOULD BE separate, that spells d-e-a-t-h
    in large-scale programming. By letting any module affect the
    behavior of any other "covertly", the ability to mutate the
    semantics of built-in types is just a BAD idea for production
    application programming, just as it's cool for tinkering.

    If I had to use Ruby for such a large application, I would
    try to rely on coding-style restrictions, lots of tests (to
    be rerun whenever ANYTHING changes -- even what should be
    totally unrelated...), and the like, to prohibit use of this
    language feature. But NOT having the feature in the first
    place is even better, in my opinion -- just as Python itself
    would be an even better language for application programming
    if a certain number of built-ins could be "nailed down", so
    I KNEW that, e.g., len("ciao") is 4 (rather than having to
    worry subliminally about whether somebody's changed the
    binding of name 'len' in the __builtins__ module...). I do
    hope that eventually Python does "nail down" its built-ins.

    But the problem's minor, since rebinding built-ins is quite
    a deprecated as well as a rare practice in Python. In Ruby,
    it strikes me as major -- just like the _too powerful_ macro
    facilities of other languages (such as, say, Dylan) present
    similar risks in my own opinion (I do hope that Python never
    gets such a powerful macro system, no matter the allure of
    "letting people define their own domain-specific little
    languages embedded in the language itself" -- it would, IMHO,
    impair Python's wonderful usefulness for application
    programming, by presenting an "attractive nuisance" to the
    would-be tinkerer who lurks in every programmer's heart...).


    Alex

    Comment

    • Peter Hansen

      #17
      Re: What's better about Ruby than Python?

      "Brandon J. Van Every" wrote:[color=blue]
      >
      > What's better about Ruby than Python? I'm sure there's something. What is
      > it?
      >
      > This is not a troll.[/color]

      An observation: Brandon seems particularly incapable of posting anything
      that is *not* a troll.

      On the plus side, he didn't cross-post it...

      Please, someone, teach the guy about Google.

      -Peter "already in his killfile" Hansen

      Comment

      • Borcis

        #18
        Re: What's better about Ruby than Python?

        Alex Martelli wrote:[color=blue]
        > Me, I think immutable strings are
        > an excellent idea (and I'm not surprised that Java, independently
        > I think, reinvented that idea which was already in Python)[/color]

        IIRC Applesoft Basic on the Apple II had immutable strings,
        way back in the late seventies.

        Comment

        • Alex Martelli

          #19
          Re: What's better about Ruby than Python?

          Alexander Schmolck wrote:
          ...[color=blue]
          > I recall the following, roughly in order of importance (treat with
          > caution, it's some time that I looked at Ruby):
          >
          > 0. I it's possible to redefine classes at runtime without going bonkers
          > (instances automatically get updated to the new class definitions).[/color]

          This is generally feasible in Python, too -- but not with built-in types
          (e.g., you can't redefine what "+" means on integers, while in Ruby you
          could).
          [color=blue]
          > This, I think is by far python's greatest flaw, amongst other things it
          > greatly compromises its interactiveness , which is a key virtue. If
          > someone can explain to me how I'm wrong on this and python's behavior
          > really is sane, I'll be eternally grateful.[/color]

          I don't think I understand what you're saying. For example:
          [color=blue][color=green][color=darkred]
          >>> class X:[/color][/color][/color]
          .... def amethod(self): return 'just a method'
          ....[color=blue][color=green][color=darkred]
          >>> x=X()
          >>> x.amethod()[/color][/color][/color]
          'just a method'[color=blue][color=green][color=darkred]
          >>> def abettermethod(s elf): return 'ah, now THIS is better!'[/color][/color][/color]
          ....[color=blue][color=green][color=darkred]
          >>> X.amethod = abettermethod
          >>> x.amethod()[/color][/color][/color]
          'ah, now THIS is better!'[color=blue][color=green][color=darkred]
          >>>[/color][/color][/color]

          Isn't this "redefining classes at runtime // instances automatically
          get updated", too? If you want to redefine a bunch of entries in X,
          rather than just a few, X.__dict__.upda te(someotherdic t) -- or even,
          shudder, reassigning X.__dict__ altogether... -- may perhaps be
          preferable, but I personally like the explicitness of assignments
          for most cases of such (rare) tasks.


          Alex

          Comment

          • Alexander Schmolck

            #20
            Re: What's better about Ruby than Python?

            Alex Martelli <aleaxit@yahoo. com> writes:
            [color=blue]
            > (I do hope that Python never gets such a powerful macro system, no matter
            > the allure of "letting people define their own domain-specific little
            > languages embedded in the language itself" -- it would, IMHO, impair
            > Python's wonderful usefulness for application programming, by presenting an
            > "attractive nuisance" to the would-be tinkerer who lurks in every
            > programmer's heart...).[/color]

            I don't think a powerful but potentially dangerous feature poses much of a
            problem as long as there is little danger of inadvertently using it and little
            incentive to inappropriately use it (e.g. you could do all sorts of stupid
            things in python, like redefining __builtins__.le n, but generally there isn't
            much of an incentive to do so, so many of the reasons why e.g. Java
            programmers might think python an unsuitable language for larger projects
            don't really apply in practice. My feeling is this *not* true to the same
            extent for ruby, where similar things are both encouraged and, if I don't
            misremember, can happen inadvertently).

            Would you still have a problem with macros in python if utilizing them
            required some obvious and explicit mechanism (say a 'use_custom_syn tax'
            statement right at the beginning of a module that wants to use macros), so
            that their use could easily be controlled by e.g. project managers?

            'as

            Comment

            • John Roth

              #21
              Re: What's better about Ruby than Python?


              "Terry Reedy" <tjreedy@udel.e du> wrote in message
              news:b8GdnQTH7K aPa92iXTWJkg@co mcast.com...[color=blue]
              >
              > "John Roth" <newsgroups@jhr othjr.com> wrote in message
              > news:vk1c89jvdj epa4@news.super news.com...[color=green]
              > > 4. Shortcut syntax for writing self in a method body.[/color]
              >
              > If you declare the first param as 's', for instance, then your
              > shortcut is 's.', which is pretty minimal, and hardly enough, it seems
              > to me, to make much fuss over. I like having a clean visual
              > separation between local variables and instance attributes.[/color]

              This particular issue has been debated a number of times, and one
              of the answers that always comes up is the one you trot out.

              Just about everyone uses "self" for good reason: everyone else
              uses "self", so it communicates its meaning clearly. If everyone
              suddenly decided to use their own terms, program readability
              would go down across the board; unless, of course, the only
              programs you read are your own.

              This is why Ruby's solution is superior: "self" is a reserved word,
              and so is the special character shortcut. There is no question as
              to what is meant. It eliminates essentially futile arguements in the
              same way that Python's indentation eliminates arguements about
              the proper placement of braces.

              John Roth
              [color=blue]
              >
              > TJR
              >
              >[/color]


              Comment

              • Brandon J. Van Every

                #22
                Re: What's better about Ruby than Python?

                Sean 'Shaleh' Perry wrote:[color=blue]
                >
                > If you joined a Chevy car mailing list and asked "what is better
                > about Ford than Chevy?" would you expect to hear intelligent,
                > insightful responses? Perhaps you would receive good answers, perhaps
                > not. But if you never actually looked at a Ford how would you know?[/color]

                Let me make myself as clear as I can. I am not the slightest bit interested
                in yours or anyone else's philosophy of whether I should have asked the
                question, or what manner I should have asked it. I asked a very simple
                question, and in some cases was rewarded with very simple, helpful answers.
                Whereas this meta-debate is a complete waste of time.
                [color=blue]
                > BTW, my reason, like many here is Ruby looks like Perl and I prefer
                > Python's syntax and design approach. Not a very scientific reason,
                > about the same as saying "well, I like blue ones more than red ones".[/color]

                Thanks for the info. You seem to agree with the Ruby FAQ on this point,
                that the langauges have different design styles and people may prefer one or
                the other. IMO this isn't a "better" because I'm a pragmatist. My rating
                for stylism is "is it much less painful than C++ ?" If so then I don't
                care.

                --
                Cheers, www.3DProgrammer.com
                Brandon Van Every Seattle, WA

                20% of the world is real.
                80% is gobbledygook we make up inside our own heads.



                Comment

                • Brandon J. Van Every

                  #23
                  Re: What's better about Ruby than Python?

                  Andrew Dalke wrote:[color=blue]
                  >
                  > How many Ruby programmers (per capita) do you know talking about
                  > Python? Perhaps Python "has the potential to ...display Ruby"[/color]

                  I don't know many. Anecdotally, though, it's clear that Ruby has mindshare.
                  It's on the radar of everyone I've talked to who knows about Python.

                  Thanks for the statistics. It didn't address the subject line, but it was
                  interesting.

                  --
                  Cheers, www.3DProgrammer.com
                  Brandon Van Every Seattle, WA

                  20% of the world is real.
                  80% is gobbledygook we make up inside our own heads.

                  Comment

                  • Brandon J. Van Every

                    #24
                    Re: What's better about Ruby than Python?

                    dan wrote:[color=blue]
                    >
                    > Dude, what is it with you?
                    >
                    > Download Python, download Ruby, check them out for yourselves. Make
                    > up your own mind instead of depending on others (with whom you rarely
                    > agree anyway).[/color]

                    Why do you assume that I'm asking these questions in order to understand how
                    to program in either? I want to know what people's *perceptions* are.
                    Subscribe to marketing-python if you want to puzzle me out more.

                    --
                    Cheers, www.3DProgrammer.com
                    Brandon Van Every Seattle, WA

                    20% of the world is real.
                    80% is gobbledygook we make up inside our own heads.



                    Comment

                    • Brandon J. Van Every

                      #25
                      Re: What's better about Ruby than Python?

                      Alex Martelli wrote:[color=blue]
                      >
                      > Don't be misled by these comparisons into thinking the two
                      > languages are _very_ different, mind you. They aren't. But
                      > if I'm asked to compare "capelli d'angelo" to "spaghettin i",
                      > after pointing out that these two kinds of pasta are just
                      > about undistinguishab le to anybody and interchangeable in any
                      > dish you might want to prepare, I would then inevitably have
                      > to move into microscopic examination of how the lengths and
                      > diameters imperceptibly differ, how the ends of the strands
                      > are tapered in one case and not in the other, and so on -- to
                      > try and explain why I, personally, would rather have capelli
                      > d'angelo as the pasta in any kind of broth, but would prefer
                      > spaghettini as the pastasciutta to go with suitable sauces for
                      > such long thin pasta forms (olive oil, minced garlic, minced
                      > red peppers, and finely ground anchovies, for example - but if
                      > you sliced the garlic and peppers instead of mincing them, then
                      > you should choose the sounder body of spaghetti rather than the
                      > thinner evanescence of spaghettini, and would be well advised
                      > to forego the achoview and add instead some fresh spring basil
                      > [or even -- I'm a heretic...! -- light mint...] leaves -- at
                      > the very last moment before serving the dish).[/color]

                      What a wonderful runon sentence. You must be an A. A. Milne fan.
                      [color=blue]
                      > Ooops, sorry,
                      > it shows that I'm traveling abroad and haven't had pasta for
                      > a while, I guess. But the analogy is still pretty good!-)[/color]

                      What I take away from it, is Python and Ruby are far more similar than
                      different. So then one looks at industrial evolution - GUIs, tools,
                      community size, marketing, volunteer organization, mainstream commercial
                      use. Python is clearly much farther along than Ruby.
                      [color=blue]
                      > 2. Ruby's TOTAL, unbridled "dynamicity ", including the ability
                      > to "reopen" any existing class, including all built-in ones,
                      > and change its behavior at run-time -- vs Python's vast but
                      > _bounded_ dynamicity, which never changes the behavior of
                      > existing built-in classes and their instances.[/color]

                      Others have mentioned this. I imagine it would be a big ticket item for
                      some. I can't figure out why I'd care myself, but maybe as I get into my
                      diplomacy AI, I will.
                      [color=blue]
                      > BUT Python equally more suitable for use in large production
                      > applications.[/color]

                      Yes, this definitely matters from 10,000 miles up.

                      --
                      Cheers, www.3DProgrammer.com
                      Brandon Van Every Seattle, WA

                      20% of the world is real.
                      80% is gobbledygook we make up inside our own heads.

                      Comment

                      • Brandon J. Van Every

                        #26
                        Re: What's better about Ruby than Python?

                        Alexander Schmolck wrote:[color=blue]
                        >
                        > Would you still have a problem with macros in python if utilizing them
                        > required some obvious and explicit mechanism (say a
                        > 'use_custom_syn tax' statement right at the beginning of a module that
                        > wants to use macros), so that their use could easily be controlled by
                        > e.g. project managers?[/color]

                        Yes you would. In open source communities, you'd get different
                        philosophical camps, and people in one camp would embed 'use_custom_syn tax'
                        in some *.h file (yeah yeah I'm a C++ programmer) that all the other *.h
                        files use. When you grab that code, you're not really going to want to do
                        the work of making more specific 'use_custom_syn tax' directives, as it would
                        break in all sorts of subtle ways. So now the 'culture of feature'
                        supplants the culture of control. The same could happen in a big commerical
                        project, for that matter. Thus it may be wise not to allow this kind of
                        customization at all.

                        --
                        Cheers, www.3DProgrammer.com
                        Brandon Van Every Seattle, WA

                        20% of the world is real.
                        80% is gobbledygook we make up inside our own heads.

                        Comment

                        • Brandon J. Van Every

                          #27
                          Re: What's better about Ruby than Python?

                          John J. Lee wrote:[color=blue]
                          >
                          > The really major differences are: Perl has tons of library code
                          > (though Python has lots) and Perl has a pile of stuff you have to
                          > learn that brings no significant benefits. It'd be great to see more
                          > research on the impact of the nonsense-overhead that comes with Perl
                          > (and is absent from Python).[/color]

                          Don't leave out the possibility that cults of expertise can sustain careers
                          and book publishers.

                          --
                          Cheers, www.3DProgrammer.com
                          Brandon Van Every Seattle, WA

                          20% of the world is real.
                          80% is gobbledygook we make up inside our own heads.

                          Comment

                          • Borcis

                            #28
                            Re: What's better about Ruby than Python?

                            John Roth wrote:[color=blue]
                            >
                            > This is why Ruby's solution is superior: "self" is a reserved word,
                            > and so is the special character shortcut. There is no question as
                            > to what is meant. It eliminates essentially futile arguements in the
                            > same way that Python's indentation eliminates arguements about
                            > the proper placement of braces.
                            >[/color]

                            This sets a specific target to an obfuscated python context :

                            Illustrate the freedom that python gives you to replace the name
                            of "self" in methods by any identifier you want, with a piece of
                            code designed to put the collision between class variables and the
                            name actually used in the method source as a replacement to "self",
                            into a functional role as a part of the main loop.

                            Or something comparable :)



                            Comment

                            • Andrew Dalke

                              #29
                              Re: What's better about Ruby than Python?

                              Brandon J. Van Every:[color=blue]
                              > Why do you assume that I'm asking these questions in order to
                              > understand how to program in either?[/color]

                              When you said at the start of this thread:
                              [color=blue]
                              > I'm language shopping and I want people's answers.[/color]

                              You didn't say you were language window shopping.
                              [color=blue]
                              > I want to know what people's *perceptions* are.[/color]

                              Nothing said in the last few days from either your C# thread or
                              your Ruby thread has raised anything new, and a trivial Google
                              groups search would have given you not only information about
                              perception but the ability to gauge trends in that perception.

                              If you were serious about this, you would *start* by giving
                              the results of your analysis, along with points which you think
                              need further clarification and point out weak points in your
                              thinking. You should not make the assumption that people
                              will do this for you, and given your poor reasoning skills, it's
                              unlikely that even if people did that you would miss the answer.

                              Instead, you make people like me just more and more annoyed
                              about your posts.
                              [color=blue]
                              > Subscribe to marketing-python if you want to puzzle me out more.[/color]

                              Or not. Word on the net is that you've raised a whole bunch of
                              bluster there.

                              Andrew
                              dalke@dalkescie ntific.com


                              Comment

                              • Erik Max Francis

                                #30
                                Re: What's better about Ruby than Python?

                                "John J. Lee" wrote:
                                [color=blue]
                                > Much less than a few hours? You're obviously much faster on the
                                > uptake than me...[/color]

                                To read and usefully absorb the tutorial in only an hour? That seems
                                quite feasible for an experienced programmer.

                                --
                                Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
                                __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
                                / \ Principles have no real force except when one is well fed.
                                \__/ Mark Twain

                                Comment

                                Working...