Classes as namespaces?

Stephen Hansen apt.shansen at gmail.invalid
Sun Mar 28 06:31:16 CEST 2010


On 2010-03-26 07:49:02 -0700, kj said:

> What's the word on using "classes as namespaces"?  E.g.
> 
> class _cfg(object):
>     spam = 1
>     jambon = 3
>     huevos = 2
> 
> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos)
> 
> 
> Granted, this is not the "intended use" for classes, and therefore
> could be viewed as a misuse ("that's what dictionaries are for",
> etc.).  But other than this somewhat academic objection[*], I really
> can see no problem with using classes in this way.

On the contrary, this is the intended use of classes. Or at least, one 
of them. A class *is* a namespace, albeit one that you must address 
explicitly unlike the local and global namespaces which are usually 
implicit.

That said...

> [*] My own subjective dislike for the widespread practice of using
> triple quotes to comment out code is formally similar to this one
> ("the 'intended use' for triple-quoting is not to comment out code",
> etc.).  Here I find myself on the opposite side of the purist/pragmatic
> divide.  Hmmm.

What?!

Where do you get this "widespread practice"? You mentioned that before 
when you last posted about that and I forgot to comment. I've never 
seen it.

In the 110k lines of in-house code I maintain, we don't use it once; we 
have somewhere around 300k lines of third-party code from a wide range 
of sources, and although I haven't reviewed it all by any means, I 
regularly have to peek over it and I never seen triple quoted 
"comments".

Hell, I almost never see commented -code-. Code should only be 
commented while fiddling or debugging. Once fiddlng is done, dead code 
should be removed.

I'm sure it -happens- every once in awhile, but.. why? Who uses editors 
that can't block comment/uncomment anymore? :(

-- 
--S

... p.s: change the ".invalid" to ".com" in email address to reply privately.




More information about the Python-list mailing list