Another newbie question

Steve Holden steve at holdenweb.com
Sun Dec 11 05:38:26 EST 2005


Paul Rubin wrote:
> Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> 
>>The fact that sys is a module and not a class is a red herring. If the
>>"Law" of Demeter makes sense for classes, it makes just as much sense for
>>modules as well -- it is about reducing coupling between pieces of code,
>>not something specific to classes. 
> 
> 
> I don't see that.  If a source line refers to some module you can get
> instantly to the module's code.  But you can't tell where any given
> class instance comes from.  That's one of the usual criticisms of OOP,
> that the flow of control is obscured compared with pure procedural
> programming.
> 
> 
>>One dot good, two dots bad.
> 
> 
> Easy to fix.  Instead of sys.stdout.write(...) say
> 
>   from sys import stdout
> 
> from then on you can use stdout.write(...) instead of sys.stdout.write.

The fact that you are prepared to argue for one of two mechanisms rather 
than the other based simply on the syntax of two semantically equivalent 
references is unworthy of someone who knows as much about programming as 
you appear to do.

The "Law" of Demeter isn't about *how* you access objects, it's about 
what interfaces to objects you can "legally" manipulate without undue 
instability across refactoring. In other words, it's about semantics, 
not syntax. And it's led a lot of Java programmers down a path that 
makes their programs less, not more, readable.

Python's ability to let the programmer decide how much encapsulation is 
worthwhile is one of its beauties, not a wart.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list