
Why does Clean Code suggest avoiding protected variables? - iProject
http://programmers.stackexchange.com/questions/162643/why-is-clean-code-suggesting-avoiding-protected-variables
======
csense
The Python language has been able to build many successful large-scale
projects without language-enforced private fields or functions. (There is a
convention to prefix internal functions and variables with "_" to indicate
"This isn't intended to be part of our public API, it's probably totally
undocumented so you'd better read the code before you start messing with it,
and it may change or go away in future releases." And double-underscores, but
I don't like them and don't use them.)

Ever since I started using Python, in Java I've started just making all my
member variables public and forgetting about accessor methods.

It actually works.

~~~
meaty
Works - yes. Works forever - probably not by which time you're in a world of
pain. Your accessors are part of the class's immutable contract with the
outside world. When you couple the class internals to the contract, hacks will
ensue en masse and your little party will fall flat on its face.

It's fine for trivial stuff, but if you work with others, this will cause uber
amounts of pain.

~~~
csense
> if you work with others, this will cause uber amounts of pain.

If this is true, why is it that there are plenty of large and successful
frameworks and libraries written in Python?

> hacks will ensue en masse

Having downstream projects that use it is a sign of health for a library. If
they're using the library in ways its creator never envisioned, so much the
better for everyone. That's innovation.

More than once, I've had to make a choice between partially re-implementing
part of a popular Java library's functionality, or shipping my own fork with
all the maintenance burden that entails, because in the official version a
field I want to access is private, or a class I want to subclass is final.

------
diego_moita
For some human activities there are problems simply too complicated to be
handled by science, mostly because it is very hard to build a rigorous and
viable methodology to investigate the problem. If these areas are important
and profitable you end up with an industry of pundits giving opinions
"supported" by rhetoric rather than an evidence impossible to gather. Politics
is the most obvious example, with its nauseating abundance of Glen Becks, Rush
Limbaughs and Michael Moores. Stock market "analysts", self help gurus,
psychic card readers, soothsayers are the more common varieties.

"Uncle Bob" (Clean Code's author) is the equivalent to those in the Software
Engineering field, a snake oil seller that will give you the placebo that
promises to fix problems that sometimes don't even exist or are of small
relevance.

------
andrewcooke
original link [http://programmers.stackexchange.com/questions/162643/why-
is...](http://programmers.stackexchange.com/questions/162643/why-is-clean-
code-suggesting-avoiding-protected-variables)

------
angersock
Having been bitten a couple of times by private/protected shadowing issues in
Java and C++, I default to protected unless I know for certain I want
something totally private.

------
meaty
Protected is fine if you understand it and use it where appropriate. My only
real use for it is to allow NHibernate proxies to read backing fields for our
entities.

