www.digitalmars.com         C & C++   DMDScript  

D - Operator overloading

reply Matthias Becker <Matthias_member pathlink.com> writes:
I'm sure this was discussed before, but I haven't been on this group for a long
time. So could somebody explain me, why names are used instead of the C++ like
operator foo? To me it's much more intuitiv to write "operator +=" instead of
"addass".
Nov 05 2003
next sibling parent reply Ant <Ant_member pathlink.com> writes:
In article <bob3sq$2n8p$1 digitaldaemon.com>, Matthias Becker says...
I'm sure this was discussed before, but I haven't been on this group for a long
time. So could somebody explain me, why names are used instead of the C++ like
operator foo? To me it's much more intuitiv to write "operator +=" instead of
"addass".

I have the same question. Ant
Nov 05 2003
parent reply "Charles Sanders" <sanders-consulting comcast.net> writes:
I agree on this one also, just some ideas but if not operator foo something
like

__+=__ () { }
__++__ () { }

A little pythonesque ?

C

"Ant" <Ant_member pathlink.com> wrote in message
news:bob4r4$2oo1$1 digitaldaemon.com...
 In article <bob3sq$2n8p$1 digitaldaemon.com>, Matthias Becker says...
I'm sure this was discussed before, but I haven't been on this group for


time. So could somebody explain me, why names are used instead of the C++


operator foo? To me it's much more intuitiv to write "operator +="


"addass".

I have the same question. Ant

Nov 05 2003
next sibling parent reply Ant <Ant_member pathlink.com> writes:
In article <bobc3l$2rt$1 digitaldaemon.com>, Charles Sanders says...
I agree on this one also, just some ideas but if not operator foo something
like

__+=__ () { }
__++__ () { }

A little pythonesque ?

I think I like it. (never though I would say that about "_") Can we do: alias addass __+=__; or someting like that? Ant
Nov 05 2003
parent "Charles Sanders" <sanders-consulting comcast.net> writes:
Good thinking, the alias doesnt like operators though :(.

C

"Ant" <Ant_member pathlink.com> wrote in message
news:bobdkv$56l$1 digitaldaemon.com...
 In article <bobc3l$2rt$1 digitaldaemon.com>, Charles Sanders says...
I agree on this one also, just some ideas but if not operator foo


like

__+=__ () { }
__++__ () { }

A little pythonesque ?

I think I like it. (never though I would say that about "_") Can we do: alias addass __+=__; or someting like that? Ant

Nov 05 2003
prev sibling parent Elias Martenson <elias-m algonet.se> writes:
Charles Sanders wrote:

 I agree on this one also, just some ideas but if not operator foo something
 like
 
 __+=__ () { }
 __++__ () { }
 
 A little pythonesque ?

Wouldn't this be terribly hard on the parser? Is't __ a legal symbol today? Wouldn't the parser have to scan 2 or 3 tokens ahead in order to determine if the initial __ is part of an expression or an overloading method? That would in turn break LALR? Granted, I never looked at the D parser so I could be just talking crap here. :-) Elias
Nov 06 2003
prev sibling next sibling parent "Carlos Santander B." <carlos8294 msn.com> writes:
"Matthias Becker" <Matthias_member pathlink.com> wrote in message
news:bob3sq$2n8p$1 digitaldaemon.com...
| I'm sure this was discussed before, but I haven't been on this group for a
long
| time. So could somebody explain me, why names are used instead of the C++
like
| operator foo? To me it's much more intuitiv to write "operator +=" instead
of
| "addass".
|
|

Over a year ago (about june-august 2002) there was a votation about this,
and that was the winning convention.

覧覧覧覧覧覧覧覧覧覧覧覧
Carlos Santander
"Matthias Becker" <Matthias_member pathlink.com> wrote in message
news:bob3sq$2n8p$1 digitaldaemon.com...
| I'm sure this was discussed before, but I haven't been on this group for a
long
| time. So could somebody explain me, why names are used instead of the C++
like
| operator foo? To me it's much more intuitiv to write "operator +=" instead
of
| "addass".
|
|

Over a year ago (about june-august 2002) there was a votation about this,
and that was the winning convention.

覧覧覧覧覧覧覧覧覧覧覧覧
Carlos Santander
Nov 05 2003
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Matthias Becker" <Matthias_member pathlink.com> wrote in message
news:bob3sq$2n8p$1 digitaldaemon.com...
 I'm sure this was discussed before, but I haven't been on this group for a

 time. So could somebody explain me, why names are used instead of the C++

 operator foo? To me it's much more intuitiv to write "operator +=" instead

 "addass".

The reason is because of the ability to write the reverse operator overloads, and to make the overloads easilly greppable.
Nov 05 2003
parent reply Matthias Spycher <matthias coware.com> writes:
I've been lurking here for a year or more, enjoying the fact that this project
is progressing steadily. Keep up the good work, Walter and everyone else.

As for operator overloading, I like the naming convention, but I think all names
should be prefixed with op, as in opCall to make it clear we are dealing with
operators. Names like add are actually quite common, e.g. in collection classes.

Matthias


In article <bobi49$cde$1 digitaldaemon.com>, Walter says...
"Matthias Becker" <Matthias_member pathlink.com> wrote in message
news:bob3sq$2n8p$1 digitaldaemon.com...
 I'm sure this was discussed before, but I haven't been on this group for a

 time. So could somebody explain me, why names are used instead of the C++

 operator foo? To me it's much more intuitiv to write "operator +=" instead

 "addass".

The reason is because of the ability to write the reverse operator overloads, and to make the overloads easilly greppable.

Nov 05 2003
next sibling parent "Charles Sanders" <sanders-consulting comcast.net> writes:
This sounds good ( prefixing with op ), I just dont like the word ass
everywhere in my code.

C

"Matthias Spycher" <matthias coware.com> wrote in message
news:bobmno$jge$1 digitaldaemon.com...
 I've been lurking here for a year or more, enjoying the fact that this

 is progressing steadily. Keep up the good work, Walter and everyone else.

 As for operator overloading, I like the naming convention, but I think all

 should be prefixed with op, as in opCall to make it clear we are dealing

 operators. Names like add are actually quite common, e.g. in collection

 Matthias


 In article <bobi49$cde$1 digitaldaemon.com>, Walter says...
"Matthias Becker" <Matthias_member pathlink.com> wrote in message
news:bob3sq$2n8p$1 digitaldaemon.com...
 I'm sure this was discussed before, but I haven't been on this group



long
 time. So could somebody explain me, why names are used instead of the



like
 operator foo? To me it's much more intuitiv to write "operator +="



of
 "addass".

The reason is because of the ability to write the reverse operator overloads, and to make the overloads easilly greppable.


Nov 05 2003
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Matthias Spycher" <matthias coware.com> wrote in message
news:bobmno$jge$1 digitaldaemon.com...
 I've been lurking here for a year or more, enjoying the fact that this

 is progressing steadily. Keep up the good work, Walter and everyone else.

Thanks!
 As for operator overloading, I like the naming convention, but I think all

 should be prefixed with op, as in opCall to make it clear we are dealing

 operators. Names like add are actually quite common, e.g. in collection

You're right, I've been intending to do this, but I hate upsetting existing code.
Nov 05 2003
parent reply "Sean L. Palmer" <palmer.sean verizon.net> writes:
Better to upset it earlier, than later, unless by doing it too early you end
up causing multiple changes instead of just one.

Nobody is doing any mission-critical stuff in D yet anyway, so breaking code
at this phase is not a big deal.  Better to get the language right, than to
be backward compatible with an initial concept that turns out not to work
well in practice.

IOW, don't be afraid to break stuff.

Sean

"Walter" <walter digitalmars.com> wrote in message
news:bochg5$1rtc$3 digitaldaemon.com...
 "Matthias Spycher" <matthias coware.com> wrote in message
 news:bobmno$jge$1 digitaldaemon.com...
 I've been lurking here for a year or more, enjoying the fact that this

 is progressing steadily. Keep up the good work, Walter and everyone


 Thanks!

 As for operator overloading, I like the naming convention, but I think


 names
 should be prefixed with op, as in opCall to make it clear we are dealing

 operators. Names like add are actually quite common, e.g. in collection

You're right, I've been intending to do this, but I hate upsetting

 code.

Nov 05 2003
next sibling parent reply "Matthew Wilson" <matthew-hat -stlsoft-dot.-org> writes:
Agreed.

btw, what's IOW? :)

"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:bockub$2103$1 digitaldaemon.com...
 Better to upset it earlier, than later, unless by doing it too early you

 up causing multiple changes instead of just one.

 Nobody is doing any mission-critical stuff in D yet anyway, so breaking

 at this phase is not a big deal.  Better to get the language right, than

 be backward compatible with an initial concept that turns out not to work
 well in practice.

 IOW, don't be afraid to break stuff.

 Sean

 "Walter" <walter digitalmars.com> wrote in message
 news:bochg5$1rtc$3 digitaldaemon.com...
 "Matthias Spycher" <matthias coware.com> wrote in message
 news:bobmno$jge$1 digitaldaemon.com...
 I've been lurking here for a year or more, enjoying the fact that this

 is progressing steadily. Keep up the good work, Walter and everyone


 Thanks!

 As for operator overloading, I like the naming convention, but I think


 names
 should be prefixed with op, as in opCall to make it clear we are



 with
 operators. Names like add are actually quite common, e.g. in



 classes.

 You're right, I've been intending to do this, but I hate upsetting

 code.


Nov 05 2003
parent "Charles Sanders" <sanders-consulting comcast.net> writes:
In Other Words.  Thirded!

"Matthew Wilson" <matthew-hat -stlsoft-dot.-org> wrote in message
news:boclem$21vv$1 digitaldaemon.com...
 Agreed.

 btw, what's IOW? :)

 "Sean L. Palmer" <palmer.sean verizon.net> wrote in message
 news:bockub$2103$1 digitaldaemon.com...
 Better to upset it earlier, than later, unless by doing it too early you

 up causing multiple changes instead of just one.

 Nobody is doing any mission-critical stuff in D yet anyway, so breaking

 at this phase is not a big deal.  Better to get the language right, than

 be backward compatible with an initial concept that turns out not to


 well in practice.

 IOW, don't be afraid to break stuff.

 Sean

 "Walter" <walter digitalmars.com> wrote in message
 news:bochg5$1rtc$3 digitaldaemon.com...
 "Matthias Spycher" <matthias coware.com> wrote in message
 news:bobmno$jge$1 digitaldaemon.com...
 I've been lurking here for a year or more, enjoying the fact that




 project
 is progressing steadily. Keep up the good work, Walter and everyone


 Thanks!

 As for operator overloading, I like the naming convention, but I




 all
 names
 should be prefixed with op, as in opCall to make it clear we are



 with
 operators. Names like add are actually quite common, e.g. in



 classes.

 You're right, I've been intending to do this, but I hate upsetting

 code.



Nov 05 2003
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:bockub$2103$1 digitaldaemon.com...
 Better to upset it earlier, than later, unless by doing it too early you

 up causing multiple changes instead of just one.

 Nobody is doing any mission-critical stuff in D yet anyway, so breaking

 at this phase is not a big deal.  Better to get the language right, than

 be backward compatible with an initial concept that turns out not to work
 well in practice.

 IOW, don't be afraid to break stuff.

Ok, I guess it will be in the next version. I really do hate breaking things.
Nov 05 2003
parent reply "Luna Kid" <lunakid neuropolis.org> writes:
 "Sean L. Palmer" <palmer.sean verizon.net> wrote in message
 news:bockub$2103$1 digitaldaemon.com...
 Better to upset it earlier, than later, unless by doing it too early you

 up causing multiple changes instead of just one.

 Nobody is doing any mission-critical stuff in D yet anyway, so breaking

 at this phase is not a big deal.  Better to get the language right, than

 be backward compatible with an initial concept that turns out not to work
 well in practice.

 IOW, don't be afraid to break stuff.

Ok, I guess it will be in the next version. I really do hate breaking things.

Please, never hesitate about this under 1.00 ;) I guess the D users, who are supposed to be on the losing side when this happens, would unanimously vote for "please break our experimental code!" rather than "please freeze little annoyances and limit our future production code/style!". Cheers, Sz.
Nov 06 2003
parent "Matthew Wilson" <dmd synesis.com.au> writes:
Absolutely. Break now is *always* better than crap later

"Luna Kid" <lunakid neuropolis.org> wrote in message
news:bodgvp$a4l$1 digitaldaemon.com...
 "Sean L. Palmer" <palmer.sean verizon.net> wrote in message
 news:bockub$2103$1 digitaldaemon.com...
 Better to upset it earlier, than later, unless by doing it too early



 end
 up causing multiple changes instead of just one.

 Nobody is doing any mission-critical stuff in D yet anyway, so



 code
 at this phase is not a big deal.  Better to get the language right,



 to
 be backward compatible with an initial concept that turns out not to



 well in practice.

 IOW, don't be afraid to break stuff.

Ok, I guess it will be in the next version. I really do hate breaking things.

Please, never hesitate about this under 1.00 ;) I guess the D users, who are supposed to be on the losing side when this happens, would unanimously vote for "please break our experimental code!" rather than "please freeze little annoyances and limit our future production code/style!". Cheers, Sz.

Nov 06 2003