Re: protected or private



Marcelo Pinto a écrit :
Bruno Desthuilliers escreveu:


Marcelo Pinto a écrit :

bruno at modulix wrote:

[snip]


Do so, and be sure a lot of programmers will hate you.

You should use 'private' *only* when you want to make sure a derived
class will not be able to access this given attribute.


I could not desagree more. Make everything private.

<troll>
Sir, Yes Sir !
And don't forget bondage, chains and the whip.
</troll>

Could you imagine a language with no access restrictors - only coding
conventions ?


You can think of access restrictors as code conventions reinforced by
the compiler.

No. I can think of access restrictors as an arbitrary and useless restriction enforced by the compiler/interpreter/whatever...

If you have a code convention that says that some members
of a class are not intended to be messed by anyone, then there is no
reason not to reinforce this restriction with some hard help.

Yes there is a reason: I do not pretend knowing in advance each and every possible use case for code I wrote, so I don't see any reason to make it harder than necessary for anyone to do whatever he wants to do with it.

.



Relevant Pages

  • Re: protected or private
    ... Make everything private. ... Sir, Yes Sir! ... Could you imagine a language with no access restrictors - only coding ... You can think of access restrictors as code conventions reinforced by ...
    (comp.object)
  • Re: protected or private
    ... Make everything private. ... Sir, Yes Sir! ... Could you imagine a language with no access restrictors - only coding conventions? ... These are the languages one typically "moves away" from in favor of languages which DO provide access restrictors, like C++, Java, C#, Ruby, Python, etc. ...
    (comp.object)
  • Re: protected or private
    ... Make everything private. ... Could you imagine a language with no access restrictors - only coding ... I meant OO languages ... Python does *not* provide access restrictors. ...
    (comp.object)
  • Re: protected or private
    ... Sir, Yes Sir! ... Could you imagine a language with no access restrictors - only coding ... reason not to reinforce this restriction with some hard help. ... restrictions are one of the most useful "tool" in helping reinforcing ...
    (comp.object)