On Tue, Mar 28, 2006 at 10:23:21PM +0900, Peter H. wrote:
} Robert D. wrote:
} Methods have nothing to do with “read only” and “write” access. I
} know where you got this concept from but it is clearly confusing you,
} discard the concept, it is hindering your understanding of what Ruby
} actually doing.
} >* The first and most important reason is a practical one How great
} >debugging and maintenance of code, you will never have to examine
} >methods not ending with ! if you are searching for the reason of some
} >strange value. Look at a C++ developper, she will never have to look
} >into methods declared with “const”, and do you really think Ruby
} >be outclassed by C++? And it would be much better than in C++ because
} >the information is conveyed at declaration and at usage.
} This doesn’t make the slightest bit of sense to me.
Have you programmed in C++? There is a great deal of value to the idea
const instances of objects which only allow const methods to be called
them. I’m not claiming that Ruby should necessarily support such a
but I can certainly understand the desire for it.
} >* The second reason is that this is only the surface of the iceberg
} >will be a revolutonary concept, think about classes. Only classes
} >names ending in “!” can be subclassed. Or classes not ending with “!”
} >will become unmodifiable as Java::String or python::string There are
} >sure much more ideas, and much better ideas, that will spring into
} >mind of much more informed people than your humble servant.
} Ruby is a dynamic language, thus you can change classes. In fact is it
} very powerful concept (revolutionary even). If you want B&D then go
} and use Java (by the way you can modify unmodifiable Java Strings) but
} the reason that people like Ruby is that they can get things done
} the language getting in the way.
I’m inclined to agree with this. In addition, if you really need a
that can’t be changed you can freeze it; preventing subclassing can be
by making the class’s inherited method throw an exception. It’s
but probably undesirable. Note that there is absolutely nothing
revolutionary about Ruby, except possibly some of the software being
written in it. Ruby is an excellent implementation of a lot of good
programming language ideas (reflection/introspection, message sending,
anonymous blocks, OOP, mixins, dynamic typing, etc.), but there is
genuinely new about it.
} >* The third reason is that I always felt unsure of !,? and = at the
} >of method names Try to use this method class Bad; def a=; puts “very
} >bad”; end; end So “!”, “?” do not have the same kind of impact than
} >not too much orthogonal, is it?
} >Enforcement (late but never theless ) of “=” is already “rubyish”,
} >should “!” (or “?”, please see below) not be?
} I was going to answer this and your other points but frankly I get the
} impression that you don’t know enough about programming to understand
} answers. A lot of the converts to Ruby are programmers with many years
} experience who found, like myself, that they could get the job done in
} Ruby much easier than the various languages that they had been using
} years. That was the revolutionary concept and you seem to have missed
There is no reason to be insulting. It is not unreasonable to expect
various non-alphanumeric characters at the end of a method name to mean
something to the parser, particularly when one of them (equals) actually
does. Furthermore, the question mark has a pretty clear semantic
and almost all ruby code adheres to the convention well.
The bang (!), however, is used inconsistently. Its primary value seems
be distinguishing between methods that produce the same result, but the
without the bang produces the result in a returned copy whereas the
with the bang modifies the receiver to take on the resulting value
returning itself. Other uses muddy the waters, including the distinction
between save() and save!() in ActiveRecord models. So we call it
“dangerous” and define this vaguely to mean whatever the API author
considers dangerous. I consider the availability of the bang as an
character in a method name a noble, but largely failed, experiment.