mystilleef wrote, making me somewhat tired of his/her repeated inability
to get what's being said [sigh]:This makes it somewhat obvious that you don't appear to fully understand
the concept of coupling as applied to software systems.
If you implement an accessor to change a class's instances' states,
surely something has to call that accessor. You seem to be implying that
such calls can only be made from within other methods of the same
object, which (if true, which it isn't) would tend to leave each class
in a vacuum where nothing else can affect its instances.
Of *course* objects are subject to external influences: since you like
the concept of coupling, how else could different components be coupled
at all?
Say that to game/simulation developers.
This is a complete non-sequitur as you don't say why game developers
specifically benefit from the reduced coupling that you allege the
provision of accessor methods introduces.
Tight coupling would be (for example) where you provided the argument to
a method by storing it in a global variable rather than passing it as an
argument. From a coupling point of view it makes no difference whether
you call an accessor method or (in Python) read or write a referenced
object's attributes directly. You still have to know the required API:
whether you call a method (in which case you have to know its name) or
read/write an attribute (in which case you have to know its name ...)
makes no essential difference.
It appears you have seen the term "content coupling" as defined, for
example, in
http://en.wikipedia.org/wiki/Coupling_(computer_science)
and taken that to mean that any knowledge at all of another object's
internals will lead to over-tight coupling and hence low cohesion. The
Python point of view is somewhat different, and says that since both
methods and data items are attributes of instances there is little
difference (except in efficiency) between accessing data via a method
(inefficient) and accessing data directly through the attribute
containing that data (efficient).
It has already been pointed out to you several times that once you have
written your code to access attributes you can introduce properties
without changing the client (accessing) code should further isolation or
additional computation be required.
What book are we talking about?
Well you should know, you're the one who wants to hang on to it. So
please enlighten us, what is this source of knowledge that appears to
contradict sound computer science?
Whereas you appear to feel that there can be no possibility if a crash
because someone calls thing.is_active(True), and yet you repeatedly fail
to demonstrate the difference. Which is why this thread has been so
mind-numbingly long. As is pointed out AGAIN here:
You use accessors when you need to control access to a data attribute.
That's not advocacy, that's common sense.
Perhaps so, but you still refuse to explain why it's better, when all
you need to do is read or write the value of an instance's attribute, to
define accessor methods to do it, introducing unnecessary (in Python)
overhead in the process.Am I the only one here who has lost track of this "'tis/'tisn't" stuff?
Because you don't want third parties illegimately tampering with an
object's internal data and thus crashing your system?
In which case you write correct software and provide it with a thorough
set of tests to allow you to modify it without worrying too much about
breakage. Attribute access is part of an object's API just like method
calls are.
You seem to think that every ill in software design can be legislated
away by strangling design freedom with specific rules. I am afraid that
experience will teach you this is far from the case: go look at the way
that the "bondage" languages that use static typing (like Java and C++)
still fail to impose the required typing discipline on a determinedly
incompetent user.
As has already been said, the Python philosophy is to provide the
features that "consenting adults" (i.e. programmers who know what they
are doing) can use most effectively to produce complex software systems
to reasonable deadlines. Unfortunately not all the knowledge required to
do this is readily available in books; the rest must come from experience.
regards
Steve