Thread: Ruby Or Python

Page 4 of 4 First ... 234
  • Jump to page:
    #46
  1. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    One thing that I don't like about ruby currently (Matz says vaguely that this *MAY* be fixed in ruby 2.0, but he can't decide the best way) is how the block argument variables work. Take netytan's example here:
    Code:
    array = ['fee', 'fie', 'fo', 'fum']
    array.each {|i| puts i }
    puts
    puts i
    Running this produces:
    Code:
    fee
    fie
    fo
    fum
    
    -:4: undefined local variable or method `i' for main:Object (NameError)
    Note that 'i' has gone out of scope correctly outside the loop and thus there is a NameError. In iterative language terms, it acts as though 'i' is merely a n argument parameter to an anonymous function. Now observe what happens if we have i declared previously.
    Code:
    i = 5
    array = ['fee', 'fie', 'fo', 'fum']
    array.each {|i| puts i }
    puts
    puts i
    Running this produces:
    Code:
    fee
    fie
    fo
    fum
    
    fum
    Note that now 'i' inside the each uses the variable outside it and unexpectedly changes the value (from 5 to 'fum'). Hence, it is very unwise to name your variables as i, j, x etc. since a block may change its value by accident.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  2. #47
  3. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Originally Posted by SimonGreenhill
    I'm enjoying this discussion folks, & I'm glad to see it hasn't turned into a "my language is cooler than yours" argument, which, lets face it, are entirely pointless ( use the right tool for the job, right? ).
    --Simon
    and you thought hell was going to freeze
  4. #48
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Wow she's a nice bug waiting to happen. I'm assuming this behaviour is what Matz is going to fix rather than the syntax? Personally I like the syntax for blocks so I wouldn't like that to change but this 'i thing isn't good.

    I suppose the reason it's gone like this for so long is that generally things are encapsulated within the classes and modules . That and generally don't get names so generically in the main scope I should hope but i'll look out for it as I use the language more .

    Thanks for the info Scopi,

    Mark.
    programming language development: www.netytan.com Hula

  6. #49
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Constant Limbo
    Posts
    989
    Rep Power
    363
    Originally Posted by Dietrich
    Code:
    ...
    list1 = ['fee', 'fi', 'fo', 'fum']
    print list1  # ['fee', 'fi', 'fo', 'fum']
    ...
    Code:
    ...
    array1 = ['fee', 'fi', 'fo', 'fum']
    ...
    """
    fee
    fi
    fo
    fum
    """
    Not that it hasn't already been addressed, but fyi
    Code:
    list = ['fee', 'fie', 'fo', 'fum']
    => ["fee", "fie", "fo", "fum"]
    
    p list
    ["fee", "fie", "fo", "fum"]
    => nil

    Comments on this post

    • netytan agrees : 'p is handy, I for one didn't know of it thanks :).
    • Dietrich agrees : Thanks for the p thing
    True happiness is not getting what you want, it's wanting what you've already got.

    My Blog
  8. #50
  9. fork while true;
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2005
    Location
    England, UK
    Posts
    5,538
    Rep Power
    1051
    I'm personally heading more down the python road now. There's a lot of nice stuff in ruby, it's a lovely language... However, there's not really all that much difference in python coding styles, which is great, since if everyone is using the same coding style, there are no arguments about code.

    Python may have annoyed me a few times in the past, and they may have deprecated the 'find' module, but on the whole, i'm starting to prefer it over ruby in some ways. Documentation is a key thing here, and the way third party extensions work makes it much easier to subclass in python
  10. #51
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Think we've crossed over and are going down the opposite road LP . Python is a great language and one I'll always enjoy using but it just feels too restrictive as of late.

    I guess there are two ways to look at the structure Python imposes on its users at the beginning I thought it was a good thing. After 3-4 years though I don't know, it's just less fun. I can't express things in my way I have to do it in Pythons way.

    Ruby though feels more like Lisp and makes it much easier to express things if you ask me. It also lets u program naturally in a functional style, which I think is a big advantage. It's not as simple or elegant as Scheme in my opinion but just works.

    To be quite honest thats my only reason for choosing Ruby over Python; it's a better Lisp .

    The lack of documentation doesn't bother me as much as perhaps it should because if I have any questions I'll just ask someone in the know .

    As you said there's not much in it. Advice to anyone trying to make this decision: use both and pick the one that feels the most natural.

    To be fair there really isn't much point in comparing them, you just have to give it a go.

    Later,

    Mark.
    programming language development: www.netytan.com Hula

Page 4 of 4 First ... 234
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo