Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 23rd, 2006, 3:53 AM   #11
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
I agree that Ruby's object model is better than Python's, but Ruby isn't without it's quirks. Optional parenthesis, optional return statements, the odd distinction between methods and blocks; these are just some of the things that make Ruby seem somewhat untidy and haphazard compared to Python.
Arevos is offline   Reply With Quote
Old Jun 24th, 2006, 5:41 AM   #12
Bitwise
Newbie
 
Bitwise's Avatar
 
Join Date: May 2005
Location: UK
Posts: 21
Rep Power: 0 Bitwise is on a distinguished road
Quote:
Originally Posted by Jessehk
I think that is also the reason I love Ruby. Everything is consistent. Classes and constants are capitalized with camel-case. Variable names and methods use lowercase and underscores. Everything works as expected.
I like Ruby but I'd have to disagree that everything works as expected. Constants, for example, are not constant.

e.g.

X = 10     # Here X is a constant
X = 11     # But this assignment is valid

Or, worse still, you can change a constant as a side-effect...

MYCONST = "hello "    #  a constant
myvar = "world"

myvar = MYCONST << myvar

# MYCONST now equals "hello world"

Other inconsistencies include the deliberate breaking of encapsulation. A method named instance_variable_set lets you poke new variables into objects 'from the outside'. The class library documents this method as: "...thereby frustrating the efforts of the class’s author to attempt to provide proper encapsulation."

Then there's the inconsistent use of brackets:

This works...
puts( (not( 1==1 )) )

This doesn't (it gives a 'parse error')...
puts( not( 1==1 ) )

Inconsitent use of boolean operators.
This works...
puts( true && true && !(true) )

This does not...
puts( true && true and !(true) )

There are many, many other inconsistencies in Ruby. As I said, I like the Ruby language. These days I do most of my programming in the Ruby language. However, I think its simplicity and elegance is frequently overstated. The language is full of 'gotchas' and pitfalls.

Incidentally, on the question of 'should I learn Ruby before Rails?' - I'd say: yes, absolutely. It is hard enough making sense of Rails even when you have a thorough knowledge of Ruby. Making sense of it without such a knowledge is impossible. You can get a long way in Rails by running scripts and tinkering with the output but you will never be able to create a proper, maintainable Rails application unless you have mastered Ruby.

If you are new to Ruby, perhaps I might suggest that you try out my own eBook (free) - The Little Book Of Ruby:

http://www.sapphiresteel.com/The-Little-Book-Of-Ruby

best wishes
Huw
__________________
Bitwise Magazine -serious computing :: www.bitwisemag.com
Bitwise is offline   Reply With Quote
Old Jun 25th, 2006, 1:25 AM   #13
Adak
Hobby Coder
 
Join Date: May 2006
Posts: 53
Rep Power: 0 Adak is an unknown quantity at this point
Bitwise, can you explain what the rationale was for making constants which could be changed?

That seems like such an obvious mistake. Must be more to it?

Adak
Adak is online now   Reply With Quote
Old Jun 25th, 2006, 6:23 AM   #14
nemesis
Programmer
 
nemesis's Avatar
 
Join Date: Aug 2005
Location: Bristol, England
Posts: 71
Rep Power: 3 nemesis is on a distinguished road
Send a message via MSN to nemesis
In the end ruby is just another language like python or C#, its all object oriented. There is ruby on rails which is meant to be good for dynamic web pages, but for most other stuff there is no advantage over using python or perl. It all depends on which syntax you like the best.
nemesis is offline   Reply With Quote
Old Jun 25th, 2006, 8:54 AM   #15
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
Quote:
Originally Posted by nemesis
In the end ruby is just another language like python or C#, its all object oriented. There is ruby on rails which is meant to be good for dynamic web pages, but for most other stuff there is no advantage over using python or perl. It all depends on which syntax you like the best.
I disagree. It's not just about the syntax, it's about the featureset as well. Ruby, for instance, has support for continuations and blocks, whilst Python does not. Perl has better closure scoping, as variable declaration can be made explicit via my. In Ruby, the object model is central to the language; in Perl, it's more of an add-on extra.

Many differences can be found in featureset, efficiency and philosophy. In terms of programming ethos, Python and Perl are diametrically opposed. And this is amongst languages that are relatively similar. Compare Ruby to Java or C# and the differences become so extensive that one really needs to learn both languages to fully understand the disparity involved.

Of course, there's a lot of stuff that's similar, but that shouldn't blind the student to what's different. Knowing how languages differ from each other is rather important. If you don't know the differences, how can you intelligently choose which language is best to solve a particular problem?
Arevos is offline   Reply With Quote
Old Jul 24th, 2006, 1:38 AM   #16
Lance
Programmer
 
Lance's Avatar
 
Join Date: Oct 2004
Location: Chicago, IL USA
Posts: 74
Rep Power: 4 Lance is on a distinguished road
Send a message via AIM to Lance
Quote:
Originally Posted by Bitwise
I like Ruby but I'd have to disagree that everything works as expected. Constants, for example, are not constant.

e.g.

X = 10     # Here X is a constant
X = 11     # But this assignment is valid

Or, worse still, you can change a constant as a side-effect...

MYCONST = "hello "    #  a constant
myvar = "world"

myvar = MYCONST << myvar

# MYCONST now equals "hello world"
True, but you can FREEZE an object so it is no longer changeable.

FOO = "Hello World"
FOO.freeze
FOO = "bar" # TypeError thrown for trying to change a FROZEN constant

Otherwise you're right. A constant isn't really "constant" because you can indeed change it. At least you get a warning for trying to change one.
__________________
/* LANCE */
C++;  /* this makes C bigger but returns the old value */
char *site = "slackwise.net",
     *home = "lance.slackwise.net",
     *pics = "flickr.com/photos/slackwise";
Lance is offline   Reply With Quote
Old Jul 31st, 2006, 5:19 PM   #17
Bitwise
Newbie
 
Bitwise's Avatar
 
Join Date: May 2005
Location: UK
Posts: 21
Rep Power: 0 Bitwise is on a distinguished road
Quote:
Originally Posted by Adak
Bitwise, can you explain what the rationale was for making constants which could be changed?
I wish I could. I personally can't see any logic in this.

I like Ruby a lot but there are things about the language that drive me up the wall. Although it comes very close to being 'pure OOP' it has a number of very un-OOP features such as badly broken encapsulation (data hiding is not properly implemented). I am also unconvinced by the necessity to have half a dozen ways of doing the same thing (how many loop structures does anyone really need???)

The trouble is that you can 'get away with' a lot of nasty coding in Ruby. I see many Ruby programs in which people create huge classes with methods containing vast amounts of code. I keep thinking that anyone who really wants to write elegant and maintainable programs in Ruby would do well to learn Smalltalk first. A typical method in Smalltalk would contain between 1 and 10 lines of code. A method of 20 lines would be considered to be fairly long...

Ruby can be a very neat and clear language. But it can equally be used to write extremely messy and ambiguous code. In my opinion, some features of the Ruby language (poor encapsulation, inconstant constants, too much syntax duplicating functionality, some ambiguous syntactical constructs) actually encourage poor coding style.

best wishes
Huw
__________________
Bitwise Magazine -serious computing :: www.bitwisemag.com
Bitwise is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC