www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why is the 'protected' attribute considered useless?

reply Chad Joan <chadjoan gmail.com> writes:
I've read more than once now that 'protected' is considered useless in 
D.  Why is this?
Jan 29 2013
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Tuesday, January 29, 2013 22:38:39 Chad Joan wrote:
 I've read more than once now that 'protected' is considered useless in
 D.  Why is this?
I've heard some people say it (though not many), but I have no idea why anyone would think that. You need protected if you ever want to override internal functionality. And in D, if you want to do NVI ( http://www.gotw.ca/publications/mill18.htm ), you'd use protected. So, I think that it's pretty clear that there are times when protected is very useful. - Jonathan M Davis
Jan 29 2013
prev sibling next sibling parent reply "simendsjo" <simendsjo gmail.com> writes:
On Wednesday, 30 January 2013 at 03:38:39 UTC, Chad Joan wrote:
 I've read more than once now that 'protected' is considered 
 useless in D.  Why is this?
I'm not sure what articles you are referring to, but a couple of points it might think of: * Anything protected can be made public by derived classes, thus any protected member is not much more "safe" than public. * private and protected in D works at module scope, not class scope. You can modify private and protected members from anywhere in the module.
Jan 30 2013
parent "Regan Heath" <regan netmail.co.nz> writes:
On Wed, 30 Jan 2013 09:20:54 -0000, simendsjo <simendsjo gmail.com> wrote:

 On Wednesday, 30 January 2013 at 03:38:39 UTC, Chad Joan wrote:
 I've read more than once now that 'protected' is considered useless in  
 D.  Why is this?
... * private and protected in D works at module scope, not class scope. You can modify private and protected members from anywhere in the module.
I think this is the most common reason ppl think protected is useless, because it has no effect inside the module scope.. but by the same logic private is as useless, so.. R -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Jan 30 2013
prev sibling next sibling parent "Don" <don nospam.com> writes:
On Wednesday, 30 January 2013 at 03:38:39 UTC, Chad Joan wrote:
 I've read more than once now that 'protected' is considered 
 useless in D.  Why is this?
I've never heard that before. Where have you read that? Several people, including me, have said that 'package' is useless -- could that be what you mean? (There are many discussions in the Java community about how useless it is in Java, D copied the same failed design). It's also true that 'protected' is in practice not very useful in D, as long as bug 314 remains unfixed. But I wouldn't describe it as useless.
Jan 30 2013
prev sibling next sibling parent "Dicebot" <m.strashun gmail.com> writes:
On Wednesday, 30 January 2013 at 03:38:39 UTC, Chad Joan wrote:
 I've read more than once now that 'protected' is considered 
 useless in D.  Why is this?
In my opinion this is because implementation inheritance is not idiomatic for D and lot of people may never encounter practical need to use one. Still needed when really needed though.
Jan 30 2013
prev sibling parent David <d dav1d.de> writes:
Am 30.01.2013 04:38, schrieb Chad Joan:
 I've read more than once now that 'protected' is considered useless in
 D.  Why is this?
Tbh, I would consider everything else other than public useless. It's part of the user to use things according to the documentation and there are conrnercases where someone wants/needs to do something which was not intended to do, like accessing an internal value (I had this problem with std.parallelism at one point). You don't have to force the user to do everything "correctly" (according to you), it's part of the user to use your library etc. with care and not limit his possibilities.
Jan 30 2013