How will we fix opEquals?

2011-02-10 Thread Don
Andrei once stated a worthy goal: as far as possible, const should be opt-in: it should be possible to code without requiring const on everything. opEquals() is in conflict with this, since it is a member function of Object. (1) If it is a const member function, then it will have a viral effe

Re: How will we fix opEquals?

2011-02-10 Thread Jonathan M Davis
On Thursday 10 February 2011 00:19:38 Don wrote: > Andrei once stated a worthy goal: as far as possible, const should be > opt-in: it should be possible to code without requiring const on > everything. > > opEquals() is in conflict with this, since it is a member function of > Object. > > (1) If

Re: How will we fix opEquals?

2011-02-10 Thread Peter Alexander
On 10/02/11 8:19 AM, Don wrote: Andrei once stated a worthy goal: as far as possible, const should be opt-in: it should be possible to code without requiring const on everything. opEquals() is in conflict with this, since it is a member function of Object. (1) If it is a const member function,

Re: How will we fix opEquals?

2011-02-10 Thread so
(1) If it is a const member function, then it will have a viral effect on all objects -- any function called by opEquals will have to be marked const. It doesn't look like we can solve this by switching the constness of an Object.function, unless we also state that every function in Object

Re: How will we fix opEquals?

2011-02-10 Thread so
Saying that no one should have to worry about const if they don't want to is a noble though, I suppose, but I don't think that it's entirely realistic. const is part of the language, and some things just plain have to be const to work. And given the prevalence of immutable with regards to thr

Re: How will we fix opEquals?

2011-02-10 Thread Jonathan M Davis
On Thursday 10 February 2011 01:26:14 so wrote: > > Saying that no one should have to worry about const if they don't want > > to is a > > noble though, I suppose, but I don't think that it's entirely realistic. > > const > > is part of the language, and some things just plain have to be const to >

Re: How will we fix opEquals?

2011-02-10 Thread Don
so wrote: (1) If it is a const member function, then it will have a viral effect on all objects -- any function called by opEquals will have to be marked const. It doesn't look like we can solve this by switching the constness of an Object.function, unless we also state that every function in

Re: How will we fix opEquals?

2011-02-10 Thread Jonathan M Davis
On Thursday 10 February 2011 01:36:56 Don wrote: > so wrote: > >> (1) If it is a const member function, then it will have a viral effect > >> on all objects -- any function called by opEquals will have to be > >> marked const. > > > > It doesn't look like we can solve this by switching the constne

Re: How will we fix opEquals?

2011-02-10 Thread so
Can you think of a use case where the calling function should know that opEquals() isn't truly const? I can't think of any. If we are going to this way, we need all four of them to be const i think.

Re: How will we fix opEquals?

2011-02-10 Thread so
On Thu, 10 Feb 2011 10:58:25 +0200, Peter Alexander wrote: On 10/02/11 8:19 AM, Don wrote: Andrei once stated a worthy goal: as far as possible, const should be opt-in: it should be possible to code without requiring const on everything. opEquals() is in conflict with this, since it is a me

Re: How will we fix opEquals?

2011-02-10 Thread Michel Fortin
On 2011-02-10 04:36:56 -0500, Don said: so wrote: (1) If it is a const member function, then it will have a viral effect on all objects -- any function called by opEquals will have to be marked const. It doesn't look like we can solve this by switching the constness of an Object.function,

Re: How will we fix opEquals?

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 03:37:58 -0500, Jonathan M Davis wrote: On Thursday 10 February 2011 00:19:38 Don wrote: Andrei once stated a worthy goal: as far as possible, const should be opt-in: it should be possible to code without requiring const on everything. opEquals() is in conflict with this

Re: How will we fix opEquals?

2011-02-10 Thread Jason House
Don Wrote: > Andrei once stated a worthy goal: as far as possible, const should be > opt-in: it should be possible to code without requiring const on everything. > > opEquals() is in conflict with this, since it is a member function of > Object. > > (1) If it is a const member function, then i

Re: How will we fix opEquals?

2011-02-10 Thread spir
On 02/10/2011 10:09 AM, so wrote: (1) If it is a const member function, then it will have a viral effect on all objects -- any function called by opEquals will have to be marked const. It doesn't look like we can solve this by switching the constness of an Object.function, Is this point very

Re: How will we fix opEquals?

2011-02-10 Thread spir
On 02/10/2011 10:26 AM, so wrote: Saying that no one should have to worry about const if they don't want to is a noble though, I suppose, but I don't think that it's entirely realistic. const is part of the language, and some things just plain have to be const to work. And given the prevalence of

Re: How will we fix opEquals?

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 09:15:36 -0500, Jason House wrote: Don Wrote: Andrei once stated a worthy goal: as far as possible, const should be opt-in: it should be possible to code without requiring const on everything. opEquals() is in conflict with this, since it is a member function of Obje

Re: How will we fix opEquals?

2011-02-10 Thread Andrei Alexandrescu
On 2/10/11 2:58 AM, Peter Alexander wrote: On 10/02/11 8:19 AM, Don wrote: Andrei once stated a worthy goal: as far as possible, const should be opt-in: it should be possible to code without requiring const on everything. opEquals() is in conflict with this, since it is a member function of Obj

Re: How will we fix opEquals?

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 10:19:50 -0500, Andrei Alexandrescu wrote: On 2/10/11 2:58 AM, Peter Alexander wrote: On 10/02/11 8:19 AM, Don wrote: Andrei once stated a worthy goal: as far as possible, const should be opt-in: it should be possible to code without requiring const on everything. opEqu

Re: How will we fix opEquals?

2011-02-10 Thread Jason House
Steven Schveighoffer Wrote: > On Thu, 10 Feb 2011 09:15:36 -0500, Jason House > wrote: > > > Don Wrote: > > > >> Andrei once stated a worthy goal: as far as possible, const should be > >> opt-in: it should be possible to code without requiring const on > >> everything. > >> > >> opEquals() i

Re: How will we fix opEquals?

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 12:24:02 -0500, Jason House wrote: Steven Schveighoffer Wrote: On Thu, 10 Feb 2011 09:15:36 -0500, Jason House wrote: > Don Wrote: > >> Andrei once stated a worthy goal: as far as possible, const should be >> opt-in: it should be possible to code without requiring cons

Re: How will we fix opEquals?

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 13:59:24 -0500, Steven Schveighoffer wrote: No but you can make things easier to avoid writing incorrect code. This kind of change invites mistakes, because it looks like you have to completely duplicate your logic, and forgetting to modify one and not the other happ

Re: How will we fix opEquals?

2011-02-10 Thread Don
Steven Schveighoffer wrote: On Thu, 10 Feb 2011 10:19:50 -0500, Andrei Alexandrescu wrote: On 2/10/11 2:58 AM, Peter Alexander wrote: On 10/02/11 8:19 AM, Don wrote: Andrei once stated a worthy goal: as far as possible, const should be opt-in: it should be possible to code without requiring

Re: How will we fix opEquals?

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 15:22:48 -0500, Don wrote: A tiny compromise which could be made, is to silently add 'const' to any class opEquals declaration, even if not present in the source. That way, simple use cases would still compile without complaint. (As long as only a single, precisely define

Re: How will we fix opEquals?

2011-02-10 Thread Jonathan M Davis
On Thursday 10 February 2011 12:22:48 Don wrote: > Steven Schveighoffer wrote: > > On Thu, 10 Feb 2011 10:19:50 -0500, Andrei Alexandrescu > > > > wrote: > >> On 2/10/11 2:58 AM, Peter Alexander wrote: > >>> On 10/02/11 8:19 AM, Don wrote: > Andrei once stated a worthy goal: as far as possib

Re: How will we fix opEquals?

2011-02-10 Thread Don
Steven Schveighoffer wrote: On Thu, 10 Feb 2011 15:22:48 -0500, Don wrote: A tiny compromise which could be made, is to silently add 'const' to any class opEquals declaration, even if not present in the source. That way, simple use cases would still compile without complaint. (As long as only

Re: How will we fix opEquals?

2011-02-10 Thread Andrei Alexandrescu
On 2/10/11 9:33 AM, Steven Schveighoffer wrote: On Thu, 10 Feb 2011 10:19:50 -0500, Andrei Alexandrescu wrote: On 2/10/11 2:58 AM, Peter Alexander wrote: On 10/02/11 8:19 AM, Don wrote: Andrei once stated a worthy goal: as far as possible, const should be opt-in: it should be possible to cod

Re: How will we fix opEquals?

2011-02-10 Thread Michel Fortin
On 2011-02-10 15:22:48 -0500, Don said: Steven Schveighoffer wrote: This doesn't work. If you only define one, then you will have problems with hidden function errors, and/or inconsistencies. For example, how does .opEquals(Object obj1, Object obj2) know which version to call? I think the

Re: How will we fix opEquals?

2011-02-10 Thread so
Has it been considered for constness or such constraints not to be inherited? (Rather plain functype signature.) Denis I asked something similar not more than a week ago, it is possible in theory i think but implementation is very problematic and requires a big shift in the meaning of const

Re: How will we fix opEquals?

2011-02-10 Thread Steven Schveighoffer
On Thu, 10 Feb 2011 16:34:57 -0500, Don wrote: Steven Schveighoffer wrote: On Thu, 10 Feb 2011 15:22:48 -0500, Don wrote: A tiny compromise which could be made, is to silently add 'const' to any class opEquals declaration, even if not present in the source. That way, simple use cases wou

Re: How will we fix opEquals?

2011-02-10 Thread Don
Michel Fortin wrote: On 2011-02-10 15:22:48 -0500, Don said: Steven Schveighoffer wrote: This doesn't work. If you only define one, then you will have problems with hidden function errors, and/or inconsistencies. For example, how does .opEquals(Object obj1, Object obj2) know which version

Re: How will we fix opEquals?

2011-02-10 Thread spir
On 02/11/2011 12:20 AM, Don wrote: I don't like this idea at all. If the problem is that it's too easy to hide the underlying function without noticing (no compile-time error), then fix how the language treats hidden functions (make it a compile-time error). If opEquals has this problem, other no

Re: How will we fix opEquals?

2011-02-10 Thread Graham St Jack
This isn't really true. If you make opEquals const, then anything opEquals calls must be const. Inevitably, you need to make a lot of your object const, which then goes viral to things that object uses, etc. On the other hand, I don't think opt-in const is that worthy a goal. Things that

Re: How will we fix opEquals?

2011-02-10 Thread Graham St Jack
Vote++ -- Graham St Jack

Re: How will we fix opEquals?

2011-02-10 Thread so
We _must_ have it there, so anyone overriding those functions _must_ use it for those functions. They could create non-const versions in addition to the const ones, It is the whole point, they can't. but they _must_ create the const versions. They're stuck. There's no way around it without b

Re: How will we fix opEquals?

2011-02-10 Thread Jonathan M Davis
On Thursday 10 February 2011 21:50:45 so wrote: > > We _must_ have it there, so anyone overriding those functions _must_ > > use it for those functions. They could create non-const versions in > > addition to > > the const ones, > > It is the whole point, they can't. Hmm. You're right (I just tri

Re: How will we fix opEquals?

2011-02-11 Thread spir
On 02/11/2011 07:13 AM, Jonathan M Davis wrote: We _must_ have it there, so anyone overriding those functions _must_ > > use it for those functions. They could create non-const versions in > > addition to > > the const ones, > > It is the whole point, they can't. Hmm. You're right (I jus

Re: How will we fix opEquals?

2011-02-11 Thread Jonathan M Davis
On Friday 11 February 2011 02:43:11 spir wrote: > On 02/11/2011 07:13 AM, Jonathan M Davis wrote: > >>> We _must_ have it there, so anyone overriding those functions _must_ > >>> > >>> > > use it for those functions. They could create non-const versions > >>> > > in addition to > >>> > > the

Re: How will we fix opEquals?

2011-02-23 Thread Bruno Medeiros
On 10/02/2011 09:36, Don wrote: so wrote: (1) If it is a const member function, then it will have a viral effect on all objects -- any function called by opEquals will have to be marked const. It doesn't look like we can solve this by switching the constness of an Object.function, unless we al

Re: How will we fix opEquals?

2011-02-23 Thread bearophile
Bruno Medeiros: > The good news is that I suspect the fields used for > opEquals/opCmp/opHash in any class are unlikely to be fields that are > computed lazily. It's just a guess though, anyone have examples otherwise? If I have a string type, I'd like to compute its hash value lazily, the firs

Re: How will we fix opEquals?

2011-02-25 Thread Bruno Medeiros
On 23/02/2011 17:50, bearophile wrote: Bruno Medeiros: The good news is that I suspect the fields used for opEquals/opCmp/opHash in any class are unlikely to be fields that are computed lazily. It's just a guess though, anyone have examples otherwise? If I have a string type, I'd like to comp