|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#46
|
||||
|
||||
|
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 Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#47
|
||||
|
||||
|
Quote:
and you thought hell was going to freeze ![]()
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev |
|
#48
|
||||
|
||||
|
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. |
|
#49
|
|||
|
|||
|
Quote:
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
__________________
-- I'll provide you with reference points; if they dont work, refer to something else. If you process text, this might make your life a little easier. |
|
#50
|
||||
|
||||
|
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
__________________
~James [Not currently seeking freelance work] Like philosophy or interested in spirituality? Philosophorum. Game Dev Experts Forums Foresight Linux - Because your desktop should be cool! Linux FAQ FedoraFAQ UbuntuGuide |
|
#51
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Ruby Or Python |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|