Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old March 28th, 2006, 11:56 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 51 m 47 sec
Reputation Power: 797
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

Reply With Quote
  #47  
Old March 28th, 2006, 12:01 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonder.
Posts: 5,543 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 1 Day 22 h 42 m 5 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook
Quote:
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

Reply With Quote
  #48  
Old March 28th, 2006, 12:22 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #49  
Old March 28th, 2006, 03:19 PM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 591 L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 13 h 59 m 46 sec
Reputation Power: 100
Send a message via AIM to L7Sqr
Quote:
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
__________________
-- 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.

Reply With Quote
  #50  
Old March 29th, 2006, 07:12 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 23 m 58 sec
Reputation Power: 1008
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

Reply With Quote
  #51  
Old March 29th, 2006, 10:05 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Ruby Or Python


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway