From: Jean-Hugues ROBERT Date: 2004-04-24T05:28:15+09:00 Subject: Re: Creating bang methods About ++ ... At 03:48 24/04/2004 +0900, you wrote: >Just like +=, ++ can not be defined as a method on an object. but + can be redefined and ++ could as well. As a matter of fact one may argue that even ++pre and ++post could be redefined (but I am certainly not going to advocate for that). >But you are correct that there is no /technical/ reason preventing ++a >from being treated an abbreviation for a=a+1. I suspect that there *are* technical reasons. I would have to dig in the lexer/parser code to figure out what they are I suppose. >However, one must balance the advantages against the disadvantages. Does >the convenience make up for the complexity of yet more special syntax. >Does it fit well with the rest of the language? (for example: += works >well with strings, what should ++ do with strings? What should ++ do with >time values: increment by an hour, a minute, a second, a day?). ++ is a nice idiom. I remember how happy I was when I eventually figured it out while learning C. Remember: strcpy( char* dest, char *src ) { while *dest++ = *src++ } Much the same nostalgia with a->b shorthand for (*a).b ! That one will be in ruby 2 somehow: key: value for :key => value L'histoire est un �ternel recommencement. history is an eternal rebeggining (sorry for that) >In this matter of balance, everyone will weigh the sides differently. So >far, Matz has decided that the convenience of saving one character doesn't >balance the extra complexity involved. So be it. Many people agree, some >people dont'. I can live with that (and I'm glad it is Matz deciding and >not me!). So do I :-) Jean-Hugues