Yet Another Case Question

rzed Dick.Zantow at lexisnexis.com
Mon Feb 24 16:01:05 CET 2003


Alex Martelli wrote:
> rzed wrote:
>    ...
>> important to some of us. Three conventions come to mind: the use of
>> ALLCAPS for constants; the use of InitialCaps for class names; and
>> the use of initialLowerCase for instance and method names.
>    ...
>> benefit is that it enforces a common coding convention.
>
> Case sensitivity does NOT enforce the common coding convention
> you seem to like so much.  Don't you think math.pi IS a constant?
> Yet it's not in ALLCAPS, isn't it?  What about class async_chat
> in module asynchat?  Isn't it a class?  So where are its
> InitialCaps? And what about function AudioDev in module audiodev --
> it's a function, yet, where is its initialLowerCase...?  We can go
> on finding examples for hours even just withing the Python standard
> library, so what "enforcement" are you TALKING about?!
>

I didn't mean that it was only possible to honor the convention. I
meant that a constant defined in all caps would have to be referred to
in all caps in a case-sensitive language. It is only a *convention*
that constants be named with all-cap names, not a law. My point was
that if BAZ is a constant meaning 'frobbish', then trying to refer to
it as baz would fail now; but it would succeed perfectly well in a
case-insensitive language, which suggests to me that I would be likely
to find it typed both ways in various people's code. I don't consider
that a benefit, really. Others might.

You bring up situations from existing code, and point out that it's
necessary to remember the capitalization used for a given module or
constant or whatever. That's true enough. But it's also true that the
name itself has to be memorized. If I'm going to refer to math.pi, I
have to know that it exists in the first place. Where do I find out
that it exists? In the docs, where it is spelled out, in its
particular case.

I don't see that it's a lot harder to remember that spelling than it
would be if case didn't matter, and in actuality, I don't see it as
any harder to remember. If it's something I use a lot, I'll learn the
case pretty quickly. If I seldom use it, I maybe won't, but I won't
necessarily learn the name, either. (Okay, I can handle 'pi' but I'm
speaking of the generality here.) It's the same with parameter
signatures -- I may have to look them up from time to time, until I
learn them.

You are right when you point out that various conventions are used;
not everyone in all code uses the convention I described. And I
understand your point about case, really. It's just that case
conventions *are* useful to those of us who use them, and the one I
describe *are* common. Take case recognition away and you have to
replace case difference with name difference. People are quite
creative when it comes to making up names. I don't find the various
naming conventions any easier to remember than capitalization
conventions, but maybe that's just me.

Dealing with other people's code is never automatic, and
case-insensitivity is not a silver bullet that will fix that
situation. Ultimately, it all comes down to, as you say, compulsive
doc-reading.

--
rzed






More information about the Python-list mailing list