digitalmars.D.bugs - [Issue 3194] New: invariant should be checked at the beginning and end of protected functions
- d-bugmail puremagic.com (31/31) Jul 20 2009 http://d.puremagic.com/issues/show_bug.cgi?id=3194
- d-bugmail puremagic.com (12/12) Jun 11 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3194
- d-bugmail puremagic.com (33/35) Jun 22 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3194
- d-bugmail puremagic.com (12/12) Oct 09 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3194
http://d.puremagic.com/issues/show_bug.cgi?id=3194 Summary: invariant should be checked at the beginning and end of protected functions Product: D Version: unspecified Platform: Other OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: andrei metalanguage.com Consider: class A { invariant() { ... } public void f() { ... } protected void g() { ... } } Currently invariant is called at the beginning and end of each public function, the end of the constructor, and the beginning of the destructor. Scott Meyers pointed out to a quite known fact - protected is much closer to public than to private in terms of offering access control. This is because anyone can just inherit from a class and call protected methods, or even wrap them in public methods. Consequently, it looks like the invariant of a class must also hold upon entry and exit of all protected methods. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 20 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3194 yebblies <yebblies gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch CC| |yebblies gmail.com Patch for D2 https://github.com/D-Programming-Language/dmd/pull/112 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 11 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3194 Diego Canuhe <canuhedc gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |canuhedc gmail.com ---Patch for D2 https://github.com/D-Programming-Language/dmd/pull/112I disagree. Even while you can easily access protected methods of a class, they are intended for internal use, otherwise they'd be public. Consider: class A { abstract protected SomeType[] getData(); public void processData() { //do something that breaks the invariants foreach (SomeType element; getData()) { //do something... } //do something that restores the invariants } invariant() {...} } a class B derived from A implementing getData() shouldn't have to respect the invariants while entering/leaving getData(). Anything regarding getData()'s side-effects should be put in an out clause. BTW, abstract functions shouldn't require a body clause accompanying in and out clauses -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 22 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3194 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla digitalmars.com Resolution| |FIXED 12:54:14 PDT --- https://github.com/D-Programming-Language/dmd/commit/95c4a647d224962e6323cecf5ddff961ac38da99 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 09 2011