A
Antoon Pardon
As I said they are public themselves for someone.
Isn't that contradictory: "Public for someone" I always
thought "public" meant accessible to virtually anyone.
Not to only someone.
As I said they are public themselves for someone.
I saw this "don't need it" pattern in discussions about the ternary
"if..else" expression and about "except/finally on the same block
level".
Now Python has both.
Actually it is very useful to be able to
distinguish
between inside and outside. This is obvious for real world things e.g.
your
TV. Nobody likes to open the rear cover to switch the channel. Similar
arguments apply to software objects. "data hiding" is a harsh name, I
would
call it "telling what matters". The need for this becomes
indispensable in
really big software packages like the Eclipse framework with approx.
100000
classes. If you cannot tell the difference between inside and outside
you
are lost.
Please don't sell a missing feature as a philosophy. Say you don't
need/want
it. But don't call it philosophy.
It's *your* *decision* which uses will be available. Your explanation
appears
to me as a fear to decide.
Littering your class definition with dozens of underscores is exactly
the
line noise we love to criticize in Perl.
Nearly every introduction to OOP? Please don't tell me that
encapsulation
does not mean "enforced restriction". If the language has no syntactic
support for encapsulation then it does not have encapsulation.
I am also bothered a bit by the seeming inconsistency of the rules for
the single underscore. When used at file scope, they make the variable
or function invisible outside the module, but when used at class
scope, the "underscored" variables or functions are still fully
visible. For those who claim that the client should be left to decide
what to use, why is the client prohibited from using underscored
variables at file scope?
NickC said:if/else was added solely because people kept coming up with ways of
embedding a pseudo conditional inside expressions and writing buggy
code in the process. All it really saves you in practice is a bit of
vertical whitespace, so, no, you still don't need it - but if you
insist on doing it, at least there's now an easy way to do it
correctly.
What is it about leading underscores that bothers me? To me, they are
like a small pebble in your shoe while you are on a hike. Yes, you can
live with it, and it does no harm, but you still want to get rid of it.
True. It's extremely suited to what we do though.Minor difficulties
like this are vastly outweighed by advantages. The difficulties are
real though.
We need to *use* those names to display the spreadsheet once the
calculation has finished (and their code has run).
Splitting more of the functionality out is probably part of the best
solution.
Guido has been known to change his mind, which is an admirabele quality,
but it does show that at some point he rejected a good idea or accepted
a bad idea.
Come on, it's more than vertical whitespace, it's extraneous variables
and sometimes even extraneous functions and function call overhead.
And Python is supposed to be unbureaucratic. People kept looking for
ways to write conditional expressions instead of spewing the logic
across multiple statements for a reason: the code is often cleaner
that way.
if/else was added solely because people kept coming up with ways of
embedding a pseudo conditional inside expressions and writing buggy
code in the process. All it really saves you in practice is a bit of
vertical whitespace, so, no, you still don't need it - but if you
insist on doing it, at least there's now an easy way to do it
correctly.
Gosh, and here I thought treating programmers as non-idiots was
actually one of the guiding philosophies in the discussion on python-
dev.
Those unit tests should *not*, though, exercise anything but the
public API, otherwise they're breaking encapsulation. Their assertion
should continue to be just as true after a refactoring of the internal
components as before.
With leading underscores, you can see *at the point of dereference*
that the code is accessing private data.
But the leading underscore doesn't tell you whether it is your own
private date, which you can use a you see fit, or those of someone
else, which you have to be very carefull with.
Well how is that different from public accessor and mutators of
private variables?
Ben Finney said:By definition, "private" functions are not part of the publicly
documented behaviour of the unit. Any behaviour exhibited by some
private component is seen externally as a behaviour of some public
component.
With leading underscores, you can see *at the point of dereference*
that the code is accessing private data. With a "this is private"
keyword you have no idea whether you're accessing private or public
data, because the two namespaces get conflated together.
That is true. But with the "priv" keyword you'll discover quickly
enough that you are trying to access private data (as soon as you run
the program). And even if a "priv" keyword is added, you are still
free to use the leading underscore convention if you wish.
The idea of being able to discern properties of an object by its name
alone is something that is not normally done in programming in
general. Yes, of course you should choose identifiers to be
descriptive of what they represent in the real world, but you don't
use names like "intCount," "floatWeight," or "MyClassMyObject" would
you? Why not? That would tell you the type of the object at the "point
of dereferencing," wouldn't it?
Then don't document it, or separate internal documentation (which is
never to pass through the wall) and public documentation (which your
users use). Nobody would (apart from your dev team and anyone told by
your dev team, which means you may fire the person for "lack of
discipline") know that there is such a thing and in consequence
wouldn't use it.
Don't tell your user not to use something, just don't tell them that
it exists and they won't use it.
Isn't that contradictory: "Public for someone" I always
thought "public" meant accessible to virtually anyone.
Not to only someone.
Ben said:Then what you're really testing is the interactions of the "push the
button" function with its external interface: you're asserting that
the "push the red button" function actually uses the result from "pick
a random city" as its target.
Thus, the "pick a random city" function is being defined by you as
*interface* for the "push the button" function. Interfaces do need to
be unit tested.
This is done by having the unit test substitute a test double for the
"pick a random city" function, rigging that double so that its
behaviour is deterministic, and asserting that the "push the button"
function uses that deterministically-generated result.
It's at this point, of course, that the "pick a random city" function
has come rather close to being public API. The designer needs to have
a fairly good reason not to simply expose the "pick a random city"
function in the API.
Note that the only thing I'm saying one shouldn't do is unit test the
private function *directly*, since the design decision has been made
that it's not part of the API. The *behaviour* of the function, as
exposed via the "push the button" piblic API, should certainly be unit
tested.
Any behaviour of that function that's *not* exhibited through the
behaviour of some public API should *not* be unit tested, and should
in fact be removed during refactoring -- which will not break the unit
test suite since no unit tests depend on it.
Alternatively, as above, the design decision can be made that, in
fact, this function *is* part of the public API since external things
are depending on it directly. Then it needs full direct unit test
coverage.
Ben Finney said:Then what you're really testing is the interactions of the "push the
button" function with its external interface: you're asserting that
the "push the red button" function actually uses the result from "pick
a random city" as its target.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.