All right, all right! Interim decision regarding qualified Object methods

Jonathan M Davis jmdavisProg at gmx.com
Thu Jul 12 18:22:48 PDT 2012


On Friday, July 13, 2012 10:10:14 Mike Parker wrote:
> On 07/13/2012 10:04 AM, Mehrdad wrote:
> > On Thursday, 12 July 2012 at 19:38:03 UTC, Jonathan M Davis wrote:
> >> On the other hand, if you're dealing with your own class hierarchy,
> >> you can choose what you're going to mark as const or not
> > 
> > Say person X who develops a class A with a const member similar to
> > opEquals or whatever suits your fancy.
> > 
> > Say person Y is using person X's library (person X doesn't even _know_
> > person Y, let alone show him the source code), and finds that too
> > restricting. It's being "forced onto them".
> > 
> > 
> > 
> > Could you tell me how this situation is different from the above?
> > 
> > How is person Y supposed to solve this problem? Modify the declarations?
> > cast()?
> 
> Again, it's a matter of choice. You can always choose to use a
> particular library, alternative, or implement your own solution. How to
> you choose *not* to derive your classes from Object?

Exactly.

const, @safe, pure, nothrow, etc. all provide benefits and guarantees, but they 
also place certain restrictions on your code. In most cases, those 
restrictions are just fine, so there's great benefit in using them. In rarer 
cases, those restrictions are too much (e.g. you must have lazy loading in 
your object or you need to be able to have equality based on database 
queries), in which case you just avoid the attributes that are incompatible 
with the idiom or approach that you're using.

If a 3rd party library works with what you're trying to do and fulfill your 
needs, then you may use it. If it doesn't work with what you're trying to do, 
then you don't. It can be annoying if you'd really like to use a particular 
library and can't because of its design decisions, but that can happen 
completely separately from const, pure, etc. But with a 3rd party library, you 
generally have options - there are always other libraries, whereas with the 
language itself, if it has a particular restriction disallows what you're 
trying to do, then you're going to have to not use that language. There's big 
difference between a library and a the language itself.

- Jonathan M Davis


More information about the Digitalmars-d mailing list