From: Michael Ulm Date: 2006-03-28T22:57:06+09:00 Subject: Re: Why do some methods names which replace the content in place doesn't have the "!" sign? Peter Hickman wrote: > Robert Dober wrote: > >> Please define "dangerous", I do not have the most remote idea what >> might be >> dangerous, apart of modifying state, which is "modifying instance >> variable". >> > > Dangerous is any function that modifies the caller. Thus > fred.gsub(/[aeiou]/, '*') does not modify fred, it returns a new object > that is the result of gsub(/[aeiou]/, '*') being applied to fred. > However fred.gsub!(/[aeiou]/, '*') both returns a new object that is the > result of gsub(/[aeiou]/, '*') being applied to fred *AND* modifies > fred. You are mistaken. Consider a = [1, 2, 3] a.delete(3) a # => [1, 2] > >> * 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. It would if you knew C++. This is actually one of the more useful features of C++. If a method is declared 'const', the compiler ensures that it does not modify the instance variables of the object (unless you use really deep magic). This can be quite useful when debugging. > >> * The second reason is that this is only the surface of the iceberg >> It will be a revolutonary concept, think about classes. >> Only classes with names ending in "!" can be subclassed. >> Or classes not ending with "!" will become unmodifiable as >> Java::String or >> python::string >> There are for sure much more ideas, and much better ideas, that will >> spring >> into the mind of >> much more informed people than your humble servant. >> >> > > Ruby is a dynamic language, thus you can change classes. In fact is it a > very powerful concept (revolutionary even). If you want B&D then go > ahead 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 > without the language getting in the way. 100% agreed. > >> * 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. > > I hope the condescending tone here was an accident. You too don't know everything (see above), and you too make mistakes (see above). Regards, Michael -- Michael Ulm R&D Team ISIS Information Systems Austria tel: +43 2236 27551-219, fax: +43 2236 21081 e-mail: michael.ulm@isis-papyrus.com Visit our Website: www.isis-papyrus.com --------------------------------------------------------------- This e-mail is only intended for the recipient and not legally binding. Unauthorised use, publication, reproduction or disclosure of the content of this e-mail is not permitted. This email has been checked for known viruses, but ISIS accepts no responsibility for malicious or inappropriate content. ---------------------------------------------------------------