From: Peter Hickman Date: 2006-03-28T23:51:05+09:00 Subject: Re: Why do some methods names which replace the content in place doesn't have the "!" sign? Gregory Seidman wrote: > On Tue, Mar 28, 2006 at 10:23:21PM +0900, Peter Hickman wrote: > } Robert Dober wrote: > [...] > } Methods have nothing to do with "read only" and "write" access. I don't > } know where you got this concept from but it is clearly confusing you, > } discard the concept, it is hindering your understanding of what Ruby is > } actually doing. > } > } >* The first and most important reason is a practical one How great for > } >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 should > } >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 of > const instances of objects which only allow const methods to be called on > them. I'm not claiming that Ruby should necessarily support such a thing, > but I can certainly understand the desire for it. > I do program is C++ but, as I've said in another reply, I fail to see how this is supposed to be of benefit in a dynamic language such as Ruby and also how would you propose to implement it? > } >* The third reason is that I always felt unsure of !,? and = at the end > } >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", why > } >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 the > } 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 for > } years. That was the revolutionary concept and you seem to have missed it > } completely. > > 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 meaning, > and almost all ruby code adheres to the convention well. > I always though of the ! as being a way of not having to come up with yet another name for the same method. Image you have gsub and decide to create the dangerous version, what do you call it that is easy to remember, that wont be confused with gsub but will be associated with gsub and can be applied to all similar dangerous versions. Sticking ! on the end seems to be the sensible solution but I would not advocate adding it to pop, delete and shift. There would be !s all over the place which would make the code harder to read and there isn't a non dangerous version of pop, delete and shift anyway. I was not being insulting, I honestly think that the poster does not understand the issues. To understand a language you have to learn to use it, once you do you get passed such superficial issues, such as the use of ! on the end of a method name, they tend to become forgotten like the lack of a prefix / postfix increment / decrement operator that people coming from C++ and Java seem to stumble over as if it was a major issue. Sure Lisp has lots of brackets and you have to indent things in Python but once you learn the language these are no longer issues. When people have problems with Lisp brackets, Python indents or Ruby !s they haven't even got as far as the syntax of the language let alone gained an understanding of the heart of the language. Therefore I tend to be abrupt with such people that then have the temerity to *fix* the problems that is nothing more than their lack of experience.