[Issue 9408] invariant should be non-const by default and settable to const

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 3 11:43:13 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9408


bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs at eml.cc


--- Comment #3 from bearophile_hugs at eml.cc 2013-02-03 11:43:10 PST ---
(In reply to comment #2)
> I think this change is a step backwards.

I think in this discussion there are two main sides:

Some people want to write D code right now, so they don't want to fight too
much with problems caused by const. And they like "freedom". Often this side is
also associated with the "worse is better" language design philosophy.

They other camp reads the texts written by the creator of the Eiffel language,
that explain what Contracts are and what they are meant to. For them a
precondition or an invariant should never modify the state of the struct/class.
And the language should enforce this, to avoid bugs. They accept less a bit
less convenience for stronger guarantees and "cleaner" code.
Mathematics-oriented people are often on this side.

D language has introduced const/invariant, but it's so strong that sometimes
you don't want or your can't use it. So sometimes D programmers don't want to
eat their own dog food.

I generally prefer a more "clean" style of coding, because from experience I
have seen that the amount of time wasted making a fussy type system happy, is
often paid later in less bugs, that otherwise waste far more of my time.

But in the end I sympathize with both camps, for different reasons. Both are
partially right. In the end a static analysis tool can just enforce all
invariants to be tagged with "const", so the end result is not too much
different.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list