Looking for a good introduction to object oriented programming with Python
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Tue Aug 7 22:14:01 EDT 2012
On Tue, 07 Aug 2012 17:07:59 -0700, alex23 wrote:
>> I'm pretty sure that people could talk about good coding design before
>> the Gof4. As you say, they didn't invent the patterns. So people
>> obviously wrote code, and talked about algorithms, without the Gof4
>> terminology.
>
> So what did people call Singletons before the pattern was named? If I
> was talking about "global uniques" and you were talking about "single
> instantiation", would we even recognise we were discussing the same
> thing?
But are we? If we're comparing code written in two languages, we don't
even know if "global" means the same -- it could be global to a single
module, or global to the entire program.
Singletons encompass many different behaviours under a single name. If I
delete the single instance, and recreate it, will it necessarily have the
same state? Calling it a singleton doesn't answer that question. We still
have to agree on what behaviour this particular singleton has.
NoneType raises an error if you try to create a second instance. bool
just returns one of the two singletons (doubletons?) again.
py> type(None)()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'NoneType' instances
py> type(False)() is False
True
And modules are singletons, even though there is no upper limit to the
number of distinct module objects you can get. So if I tell you that X is
a singleton, you don't even know something as fundamental as whether or
not X is the only instance of its type.
> The Go4 book was as much about the approach of naming and documenting
> patterns as describing the patterns they saw. It was just an attempt at
> formally approaching what we were previously doing anyway.
>
>> I don't think that "Memento Pattern" is any more clear than "save and
>> restore".
>
> And I don't think that everyone making up their own terminology helps
> with the _communicativeness_ of code.
Are you saying that Go4 shouldn't have made up their own terminology?
"Save and restore" is plain English which predates "Memento Pattern". I
was writing code in the 1980s like:
save := something;
do_stuff_to(something);
something := save; {restore old value}
which is the Memento pattern in non-OOP Pascal.
>> And the ever-finer distinctions between variations on patterns. Without
>> looking them up, what are the difference between Default Visitor,
>> Extrinsic Visitor, Acyclic Visitor, Hierarchical Visitor, Null Object
>> And Visitor, and regular old Visitor patterns? -- and no, I did not
>> make any of them up.
>
> Why wouldn't I look them up?
You claim that named Patterns simplify and clarify communication. If you
have to look the terms up, they aren't simplifying and clarifying
communication, they are obfuscating it.
The time I save in writing "Foo Visitor" is lost a dozen times over for
every one of my readers who has to look it up to find out what I mean.
And if somebody else uses "Foo Visitor" to mean something different to
what I mean, we now have a communication mismatch. The finer the
distinction between Foo and Bar Visitor, the more likely that people will
misunderstand or fail to see the distinction, and the less useful the
terminology gets.
There is a point of diminishing returns in terminology, where finer
distinctions lead to less clarity rather than more, and in my opinion
that point was already passed when Go4 wrote their book, and it's just
got worse since.
--
Steven
More information about the Python-list
mailing list