caught in the import web again

Rick Johnson rantingrickjohnson at gmail.com
Mon Nov 17 21:17:13 EST 2014


On Monday, November 17, 2014 4:46:05 PM UTC-6, Steven D'Aprano wrote:
> [...]
> Python is not Java, nor Perl, and if you're putting every
> class into its own file, you are doing it wrong.

Stop making these gross generalizations. Just because Java
*REQUIRES* that you only have one class per file does not
mean that having one class per file is *BAD*, or *WRONG* --
quite the contrary! You might as well join the endless hordes
that parrot off such ridiculous bile as:

    * All republicans are racists!

or:

    * All democrats are whiners!

or:

    * All politicians are filthy nasty liars!

...that last one might be true though!

There are times when i have only one class in a file, but
there are other times when i have multiple classes per file

    BUT NOT MANY TIMES!
    
    AND NOT MANY CLASSES!

The number of classes per file is a very subjective matter
indeed, but in my opinion, the number should be kept as low
as possible, because, as the number of lines in a file
increases, your mental grasp of the contents decreases. I
don't care who you *THINK* you are, but your mental focus is
*NOT* infinite!

One of the problems inherent in "large file editing" is the
fact that since you are dealing with multiple namespaces,
there is great possibilities of different namespaces re-using
the same symbols. So for instance, if your searching in
"class A" for "symbolX", and "symbolX" also exists in "class
M", you're going to find yourself 1000 lines away from the
scope you intended to search, and now you have to trog back
up to your original spot!

    BOY I LOVE TROGGING!

YES, YES, i know some of you have fancy editing tools with
"scoped search" abilities, but even *IF* you use such a
tool, you still must define the scope in some way --by
selecting a block of text or choosing from a predefined set
of scopes-- but in any event, you're just doing "new work"
(scoped search rules) to avoid doing "old work" (flipping
between windows), and although there is arguably no net gain
or loss between the two techniques *DIRECTLY*, the person
trying to wrangle a large file is more likely to loose
focus.

    IT'S NOT A ZERO SUM GAME, SO *YOU* LOOSE!
    
The "one class per file rule" handles the "scoped search"
*IMPLICITLY* for me. When i'm in a file that contains only
one class, i know that i could never acidentally edit the
wrong symbol in *ANOTHER* class, and I don't need to define a
search area, no, all i need to do to "search", is to, well, 
*SEARCH*. 

    WHAT A NOVEL IDEA!

Combining multiple classes into a single file is like
combining multiple drinking glasses into a single unit.
Imagine a wine glass, a beer mug, and a soda can joined with
a tight fitting rubber-band -- sure, you can carry the "unit"
comfortably with one hand, and you might impress your drunk
friends at the local pub with your new "beverage dispenser",
however, try drinking from the beer mug without getting
drenched with wine or sticky soda.

And even if you *DID* manage to drink the beer without
spilling the other two in the process, you would have to
expend so much *EXTRA* mental focus during the process that
you've undermined the usefulness of the combination.
Most times, the simplest solution is the best.

    JUST DRINK FROM ONE GLASS AT A TIME YOU IDIOT!




More information about the Python-list mailing list