January 27, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9408

           Summary: invariant should be non-const by default and settable
                    to const
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: andrej.mitrovich@gmail.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-26 21:08:35 PST ---
class C1
{
    int x;
    invariant() const
    {
        x = 1;   // not ok
    }
}

class C2
{
    int x;
    invariant()
    {
        x = 1;  // ok
    }
}

See also https://github.com/D-Programming-Language/dmd/pull/1073,
and discussion http://forum.dlang.org/thread/jvh87s%241gl6%241@digitalmars.com

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 27, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9408



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-26 21:45:00 PST ---
https://github.com/D-Programming-Language/dmd/pull/1560

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 03, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9408


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2013-02-03 11:20:58 PST ---
I think this change is a step backwards.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 03, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9408


bearophile_hugs@eml.cc changed:

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


--- Comment #3 from bearophile_hugs@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: -------
Top | Discussion index | About this forum | D home