![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#12 | |
|
Newbie
Join Date: May 2005
Location: UK
Posts: 21
Rep Power: 0
![]() |
Quote:
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 |
|
|
|
|
|
|
#13 |
|
Hobby Coder
Join Date: May 2006
Posts: 53
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#14 |
|
Programmer
|
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.
|
|
|
|
|
|
#15 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
Quote:
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? |
|
|
|
|
|
|
#16 | |
|
Programmer
|
Quote:
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"; |
|
|
|
|
|
|
#17 | |
|
Newbie
Join Date: May 2005
Location: UK
Posts: 21
Rep Power: 0
![]() |
Quote:
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 |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|