Am I the only one who would love these extentions? - Python 3.0 proposals (long)

T

Terry Reedy

Tim Jarman said:
Enum("RED", "GREEN", "BLUE") creates constants RED=1, GREEN=2, BLUE=3.
Enum(RED=1, GREEN=2, BLUE=4) creates constants RED=1, GREEN=2, BLUE=4.
Enum("RED", "GREEN", "BLUE", BLACK=0) creates BLACK=0, RED=1, GREEN=2,
....
I don't claim that this is the One True Answer but it works for me.

The apparent lack of there being One True Answer or even a close
approximation seems to be one of the barriers to a standard lib
module. Other people would rather that Enum("RED", "GREEN", "BLUE")
create constants RED='RED', GREEN='GREEN', BLUE='BLUE'. There have
been serious proposals on Python-Dev that the standard lib use
self-identifying constants that would at least print something more
meaningful than a number. On the other hand, some constants
(weekdays, months) do need to be ordered other than alphabetically.

Terry J. Reedy
 
A

Alex Martelli

Ron Adam wrote:
...
If an option for case insensitivity were implemented it would just be
a matter of doing a lower() function on all source code as a first
step in the compile process. Then case in the source code need not
matter, or you could choose to have it matter if that's what you want.
It probably isn't that simple. I haven't looked into the source code
far enough yet. Doing so would probably cause errors in existing
programs where names do use same spelling/different case for different

And all uses of standard Python modules such as random and fileinput,
which do exactly that sort of thing systematically.
Using a case correcting editor is one way of doing it that doesn't
change pythons core and lets the programmer choose the behavior they
want.

Nope, can't do. Consider:

now x and y are two VERY different things:
0.93572104869999828

....but how would a poor "case correcting editor" distinguish them...?

Such a smart editor might HELP a little by SUGGESTING a case-correction
when it appears unambiguous, even just for standard modules and the
functions therein. Maybe a menu-command for "suggest case corrections
if any" WOULD be helpful in IDLE, and offer good cost/benefit ratio as
a fun, not-too-terribly-hard project reducing human misery a bit...:).


Alex
 
R

Ronald Oussoren

A slighty different scheme would be to disallow names that differ only
in case. This would make it possible to talk about code ("the foo
function is buggy") without confusion ("which one, the one in capitals
or lower-case?"), without having having the confusing notion that 'FOO'
and 'foo' are the same. To me at least 'foo = FOO' looks like something
different than 'foo = foo'.

Ronald
 
A

Alex Martelli

Michele said:
...
But these are very rare cases, so probably I could live with an
enforced capitalization too.

You think it's rare, during refactoring, to change between types and
factory functions?! I suspect you may not have been maintaining and
enhancing code (in languages allowing interchange of the two things)
for long enough. Consider that *ALL* types in Python's builtins started
life as factory functions -- that's 100%... "very rare"?!-)

This is more a problem of inconsistent conventions. It is true that
it will disappear with case insensitivity enforced, but somewhat I

[[ probably mean "case sensivity enforced" ? ]]
don't feel it a reason strong enough.

Ruby seems to survive with warnings for capitalization inconsistent
with its favourite conventions, but then it doesn't let you "just call
the class" to instantiate it -- you have to call Theclass.new(23) or
the like. Ooops, was that TheClass.new(23) ...? How is the assumed
"enforcement" going to deal with THESE issues?-)

You are exaggerating a bit. Yes, you are right in your complaints,
but in my experience I never had headaches due to case sensitivity.

How am I "exaggerating" in claiming that the SAME module, zipfile,
spells "zipfile" differently in the module name itself, in class
zipfile.ZipFile, and in class zipfile.BadZipfile? Maybe you have a
photographic memory so that having seen each of these ONCE you are
never going to forget which ones uppercase exactly which letters, but
even back when my memory was outstanding (when I was younger) it was
always more "auditory" than "visual": I could easily recite by heart
long quotes from books I had read once, but never could recall the
details of punctuation (or capitalization, when non-systematic, as
it often was e.g. in 17th/18th century english) without painstaking
and painful explicit memorization effort.

Should a language cater mostly to the "crowd" (?) of people with
photographic memories, or shouldn't it rather help the productivity
of people whose memories aren't _quite_ that good and/or visual...?

You are still exaggerating. 99% of times uppercase constants denote
numbers or strings. I don't remember having ever seen an all uppercase
function, even if I am sure you do ;)

Maybe my defect is knowing the Python standard library too well? It's
got SEVERAL all-uppercase functions, Michele! Check out modules
difflib (functions IS_LINE_JUNK and IS_CHARACTER_JUNK), gzip
(functions U32 and LOWU32), stat (all the S_IMODE etc functions),
token (functions ISTERMINAL and ISNONTERMINAL)...!

Maybe the sum total IS 1% or so of the functions in the library, but
that's _STILL_ a silly, arbitrary memorization chore which I shouldn't
have had to undergo in the first place -- and I'm not even sure I
have in fact remembered all of them...

Yeah, having read-only attributes distinguished by some code convention
(underscores or capitalization) would be a possibility, but what if in
a future version of Python the read-only attribute becomes writable? I

Exactly: a silly distinction. So, let's NOT draw it in the first place.
am use you had this are argument in the back of you mind. Nevertheless,
notice that this is an argument against a too strict code convention,
not against case insensitivity.

You seem to argue that case sensitivity is good because it lets you
draw a distinction that, you've just shown, should NOT be drawn. It
seems to me that this is rather one of the reasons that make it BAD:).

oops again, I meant "shadowing" instead of 'overriding' but you understood


I often use lowercase for constants, for instance in mathematical
formulas:

a=1
b=2
y=a*x+b

Readability counts more than foolish consistency. Please, remember that
I am not advocating *enforcing* capitalization, even if I would welcome
a more consistent usage of capitalization in the standard library.
What I say is that case sensitivity is convenient, it gives me more
indentifiers for free.

It's anything BUT "for free", as I've been arguing: we pay quite a
price for it. Adding ONE character (a letter, assumed case-insensitive,
digit or underscore) gives you 37 times more identifiers; for identifiers
of length 6, drawing them from an alphabet of 63 rather than 37 chars
gives you just 24.37 times more identifiers -- and you aren't going to
use most of those extra possibilities unless you're TRYING to drive
readers of your code crazy, anyway.

For instance, I can define a matrix type, overload "*" and write the
multiplication of a matrix "A" times a vector "a" as

b=A*a

Much more readable to me, that something like

Please note that here you are suddenly and undocumentedly _switching
conventions on the fly_ regarding capitalization. One moment ago,
leading cap had to mean "type" and all caps had to mean "numeric
constant" (which in turn made a single-caracter capital identifier
ambiguous already...) -- now suddenly neither of these conventions
exists any more, since that uppercase A means 'matrix' instead of
'vector' (and a _number_, i.e. even lower dimensionality, would be
indicated *HOW*? Don't you EVER multiply your matrices by scalars?!
Or is it so crucial to distinguish matrices from vectors but totally
irrelevant to distinguish either from scalars?!).
b=a_matrix*a

or even

b=c*a # c is a matrix

Mathematical formulas are the first reason why I like case sensitivity.

My opinion is that, while _habit_ in mathematical formulas may surely
make one hanker for such case-sensitivity, the preference just does not
stand up to critical analysis, as above. You're trying to overload WAY
too many different and conflicting "conventions" onto a meager "one bit
[at most] per character" (about 0.87 bits I believe, in fact) of
"supplementary information" yielded by case-sensitivity.

<horrified> Hungarian notation is an abomination you cannot put on
the same foot with case sensitivity! </horrified>

They're both (as generally used) attempts to draw type-distinctions
by means of lexical conventions. Case sensitivity is worse because
it doesn't wreck its damage only at the START of an identifier -- it
percolates INSIDE the identifier, too, making it (absurdly) an error to
try and catch a "zipfile.BadZipFile" or instantiate a "zipfile.Zipfile".

Case preservation is an interesting concept which would solve some
of my objections against case insensitivity, but not all of them. We would
need more letters!

Use 6 instead of 5 letters -- quite sufficient to give you PLENTY
more identifiers to choose from.

Most paladins of case sensitivity would probably be horrified to see
that the main point in its "favour" now appears to be that it
encourages you to use shorter (e.g. 1-letter) identifiers (and thus
more cryptic ones) because it gives you more of them to choose from...!!!

For example, Scheme and Lisp are case insensitive, but they are richer
than Python in the character set of their identifiers: so they can
distinguish a class from an instance writing something like "c"
for the instance and "c*" or "c#" or "c-" etc. for the class. How would
you do that in Python? "c" for the class and "ac" for the instance? Not

I've tried (e.g. in Dylan) the concept of having punctuation freely
embeddable in identifiers and didn't particularly like it (I guess it
works better with a NON-infix-syntax language -- I don't recall it
feeling like a problem in either Forth or Scheme -- but in Dylan the
inability of writing a sum as
a+b
because that's an identifier, so you have to write
a + b
instead, _was_ rather uncomfortable to me [maybe I just didn't get
long-enough practice and experience with it]).
readable at all, IMHO. And think again to mathematical formulae, they
would really suffer from case insensitivity.

I disagree -- once you have to spell out e.g. pi, capital-sigma, etc,
in Ascii letters anyway, having to make sure you do so in letters that
are unambiguous in terms of capitalization differences is no big loss.
Personally, in terms of formulas, I've never found Fortran any less
readable than C, for example.

And no, I definitely don't want Unicode characters in identifiers --
that would ensure a LOT of new and diverse errors as people use the
wrong "decoration" (accent, circumflex, etc, etc) on letters. Plain
ascii's just great...!-)


Alex
 
A

Alex Martelli

Ron Adam wrote:
...
4: The editor or IDE matches what I enter to the names and then
substitutes the proper case of the name at some definitive point.
This ensures that the case is correct and the program compiles and
runs normally. If I choose a different editor then see #1 or #2. ...
correcting while editing. Number 4 is possible to do now, but I
don't know of any editors that currently do it. It would be a nice
option to include in one I think.

Yes, looks like a nice idea for a middling-difficulty project with
IDLE, and it would be useful even if made _particularly_ unintrusive
(spelling correction would be done only on specific request, and
only when feasible without ambiguity regarding e.g. standard library
modules and names therein -- a really minimal part of [4], yet it
would STILL save quite some trouble/hassle to those using it...).


Alex
 
T

Tim Hochberg

Alex said:
Michele Simionato wrote:
[SNIP]
For instance, I can define a matrix type, overload "*" and write the
multiplication of a matrix "A" times a vector "a" as

b=A*a

Much more readable to me, that something like


Please note that here you are suddenly and undocumentedly _switching
conventions on the fly_ regarding capitalization.

Non issue, relatively speaking. Context makes this clear.
One moment ago,
leading cap had to mean "type" and all caps had to mean "numeric
constant" (which in turn made a single-caracter capital identifier
ambiguous already...) -- now suddenly neither of these conventions
exists any more, since that uppercase A means 'matrix' instead of
'vector' (and a _number_, i.e. even lower dimensionality, would be
indicated *HOW*?

Number crunching with Python, by which I mean implementing big nasty
formulas from obscure journals. It's a hard game all the way around. The
problem is over constrained and making things case insensitive would
just make things worse.

One would like to keep your formulas as close as possible to their
sources. This helps both to get the formulate correct, but allows future
readers of the code to be referred to the relevant journal and have some
prospect of matching up code to article. This is impossible to do
exactly of course since python doesn't support arrows and overbars,
boldface and italic in identifiers. Using case sensitivity can help
here, although it certainly doesn't solve all problems. The convention
of capitalizing the matrices, lower-casing the vectors and writing out
the scalars (see below) is often effective.
Don't you EVER multiply your matrices by scalars?!

Scalars in my experience are frequently represented using Greek
characters, so they get written out and are therefore easy to
distinguish. They also tend to represent only a small portion of the
typical equation, so that fact that they are written out doesn't have
that large an effect. When the scalars are not represented using Greek,
you just do the best you can.
Or is it so crucial to distinguish matrices from vectors but totally
irrelevant to distinguish either from scalars?!).

Just because it's difficult to represent formulas well using ASCII is
not reason to make it more difficult, nor to throw up our hands and not
try to represent them as best we can.
My opinion is that, while _habit_ in mathematical formulas may surely
make one hanker for such case-sensitivity, the preference just does not
stand up to critical analysis, as above.

In theory, there is no difference between theory and practice. In
practice.... I've tried many ways over the years to represent equations
legibly using Python and my experience that case sensitivity, while
certainly no panacea, helps.

You're trying to overload WAY
too many different and conflicting "conventions" onto a meager "one bit
[at most] per character" (about 0.87 bits I believe, in fact) of
"supplementary information" yielded by case-sensitivity.

I believe it's much closer to 1 full bit for length-1 sequences since
numbers cannot start an identifier, decreasing relatively quickly to
0.87 (I'll take your word for the 0.87 being the asymptotic value.)

[SNIP]
Most paladins of case sensitivity would probably be horrified to see
that the main point in its "favour" now appears to be that it
encourages you to use shorter (e.g. 1-letter) identifiers (and thus
more cryptic ones) because it gives you more of them to choose from...!!!

I find this argument silly. I have all the freedom I need to make my
code illegible by using short identifiers without exploiting case. I'm
certain I could rewrite all my code to use two letter lowercase
identifiers and the lack of mixed case certainly wouldn't make it any
clearer.
I disagree -- once you have to spell out e.g. pi, capital-sigma, etc,
in Ascii letters anyway, having to make sure you do so in letters that
are unambiguous in terms of capitalization differences is no big loss.

Interestingly all of the math typesetting programs I've seen, including
LaTex and MathML us Sigma (or SIGMA) and sigma for upper and lower case
sigma respectively. None write it out.

[SNIP]


In the end, this is a tools issue. If people spent half the time working
on their favorite editor as discussing case-sensitivity, the problem
would be long solved. SciTe comes pretty close with its auto completion
stuff, but it doesn't order the completions appropriately. The correct
order would be to ignore both captitalization and underscores. Or,
perhaps, just non-leading underscores. I once fixed one of wxPython IDEs
to do this mostly right, but sadly I've forgotten which one. I suppose
it's time to dig into SciTe, but it's unfortunately not in Python.

Which brings me to something I can't understand about the great
capitalization debate. Why is 'runmethod' versus 'runMethod' confusing,
while 'runmethod' vs 'run_method' is not? To do a full job I'd think
you'd have to axe underscores as well. Far better to just improve the
tools.

-tim
 
M

Michele Simionato

Alex Martelli said:
You think it's rare, during refactoring, to change between types and
factory functions?! I suspect you may not have been maintaining and
enhancing code (in languages allowing interchange of the two things)
for long enough. Consider that *ALL* types in Python's builtins started
life as factory functions -- that's 100%... "very rare"?!-)

It is very rare in my own code, but I haven't maintained code written
by others, so I will accept your experience on this.
This is more a problem of inconsistent conventions. It is true that
it will disappear with case insensitivity enforced, but somewhat I

[[ probably mean "case sensivity enforced" ? ]]

No, this time I really meant case *insensitivity*: if case
insensitivity
was enforced, the issue with FCNTL,cStringIO, MimeWriter, etc. etc.
would
disappear and a normal memory would be enough to grasp everything.
How am I "exaggerating" in claiming that the SAME module, zipfile,
spells "zipfile" differently in the module name itself, in class
zipfile.ZipFile, and in class zipfile.BadZipfile? Maybe you have a
photographic memory so that having seen each of these ONCE you are
never going to forget which ones uppercase exactly which letters, but
even back when my memory was outstanding (when I was younger) it was
always more "auditory" than "visual": I could easily recite by heart
long quotes from books I had read once, but never could recall the
details of punctuation (or capitalization, when non-systematic, as
it often was e.g. in 17th/18th century english) without painstaking
and painful explicit memorization effort.

No, I don't have a photographics memory and sometimes (few times,
actually) I don't remember the right capitalization, but few seconds
with the on-line help (trying zipfile or ZipFile or BadZipfile, for
instance) are usually enough to solve the issue. So, as I said,
capitalization does not give big headaches to me. Also, I am
absolutely unconvinced that capitalization gives big headaches to you
(except as a point of principle, of course). I am not saying case
sensitivity is perfect, I am saying its disadvantages (in real life)
are not so serious as you claim. People has written tons of C, but I
am sure capitalization bugs are scarcely relevant as compared, for
instance, to pointer arithmetic bugs ;)
Should a language cater mostly to the "crowd" (?) of people with
photographic memories, or shouldn't it rather help the productivity
of people whose memories aren't _quite_ that good and/or visual...?

I don't have an auditive memory, nor a visual memory, but still I
manage
to survive with case sensitivity, so I guess everybody can do the same
....
Maybe my defect is knowing the Python standard library too well? It's
got SEVERAL all-uppercase functions, Michele! Check out modules
difflib (functions IS_LINE_JUNK and IS_CHARACTER_JUNK), gzip
(functions U32 and LOWU32), stat (all the S_IMODE etc functions),
token (functions ISTERMINAL and ISNONTERMINAL)...!

Ubi major, minor cessat ;)

I confess I never used these functions: not only their capitalization
is new to me, but even their names! Still, I am sure that knowing the
names I will be able to remember the capitalization: 100% of times
for all caps identifiers, 80% of times for camel case identifiers.
I do think this is an average performance.
Maybe the sum total IS 1% or so of the functions in the library, but
that's _STILL_ a silly, arbitrary memorization chore which I shouldn't
have had to undergo in the first place -- and I'm not even sure I
have in fact remembered all of them...

Even if you enforce case insensitivity, the library will still have
inconsistencies due to different code conventions: think to the use of
underscores to separate names, for instance. The standard library
index gives plenty of cases, i.e. "add_something" versus
"addsomething"
etc.
Please note that here you are suddenly and undocumentedly _switching
conventions on the fly_ regarding capitalization. One moment ago,
leading cap had to mean "type" and all caps had to mean "numeric
constant" (which in turn made a single-caracter capital identifier
ambiguous already...) -- now suddenly neither of these conventions
exists any more, since that uppercase A means 'matrix' instead of
'vector' (and a _number_, i.e. even lower dimensionality, would be
indicated *HOW*? Don't you EVER multiply your matrices by scalars?!
Or is it so crucial to distinguish matrices from vectors but totally
irrelevant to distinguish either from scalars?!).

That's rethoric and you know that. As I already said, readability is
more important than foolish consistency; also in the context a matrix
computations, how big is the possibility to misunderstand the
meaning of variables such as

A=Matrix(2,2); b=vector(2); s=scalar() ??
My opinion is that, while _habit_ in mathematical formulas may surely
make one hanker for such case-sensitivity, the preference just does not
stand up to critical analysis, as above. You're trying to overload WAY
too many different and conflicting "conventions" onto a meager "one bit
[at most] per character" (about 0.87 bits I believe, in fact) of
"supplementary information" yielded by case-sensitivity.

I strongly like operator overloading because of my mathematical
background. Mathematicians overloads the meaning of operators all
the time and never get confused, since the context is always made
well clear. Nevertheless, many programmers are against operator
overloading, because it can be abused. In my opinion the advantage
is worth the risk (the same for case sensitivity) but I do accept
that other may disagree. Insisting too much, we risk to enter in
a religious discussion, so it is better to stop here.
Most paladins of case sensitivity would probably be horrified to see
that the main point in its "favour" now appears to be that it
encourages you to use shorter (e.g. 1-letter) identifiers (and thus
more cryptic ones) because it gives you more of them to choose from...!!!

In mathematical formulas, at least, shorter identifiers are clearer,
not more cryptic; also, it is nice to import modules with syntaxes
such as ``import math as m``, using a single letter, which does not
clash with some other ``M`` (for instance the mass of an
object in a Physics program, or a pluggable metaclass in an object
oriented program, or anything else).
I've tried (e.g. in Dylan) the concept of having punctuation freely
embeddable in identifiers and didn't particularly like it (I guess it
works better with a NON-infix-syntax language -- I don't recall it
feeling like a problem in either Forth or Scheme -- but in Dylan the
inability of writing a sum as
a+b
because that's an identifier, so you have to write
a + b
instead, _was_ rather uncomfortable to me [maybe I just didn't get
long-enough practice and experience with it]).

I am against too much punctuation, that's one of the reason why
I do like case insensitivity, so you don't need extra identifiers:
did you miss my point or I am misreading you?
I disagree -- once you have to spell out e.g. pi, capital-sigma, etc,
in Ascii letters anyway, having to make sure you do so in letters that
are unambiguous in terms of capitalization differences is no big loss.
Personally, in terms of formulas, I've never found Fortran any less
readable than C, for example.

I don't like Fortran verbosity, but others could agree with you.
That's just a matter of personal preference.
And no, I definitely don't want Unicode characters in identifiers --
that would ensure a LOT of new and diverse errors as people use the
wrong "decoration" (accent, circumflex, etc, etc) on letters. Plain
ascii's just great...!-)

Who wants Unicode characters ?? I am not so foolish yet !!

Michele
 
R

Ron Adam

But "Bob" and "Barb" wouldn't be the same thing, even though they look
a little different...Americans saying "Bob" pronounce it so that I
think they're saying "Barb" (or perhaps "Baab"), so I think these two
(three) identifiers should be the same, to avoid confusion! Heh.


<smile> Ok, yes we have to draw a line somewhere when it comes o
similarities. I don't think editors are smart enough at this time to
distinguish similar meanings across differing languages, or differing
dialects of the same language.

At some point though, in the <far( future)>, it should be possible,
and it will be needed due to the likely popularity of voice input.
(along with good translation software too) This is another reason
that names should not be too similar. We would have to depreciate
terms that sound alike and do not have a clear meaning from the
context. Of course it may be awhile before that is needed. I would
prefer my computer not to stop me with interruptions to ask me which
similar sounding class I want to use. ;-)

I have a voice input program someone gave me a couple of years ago
I've never tried. Maybe I'll install it in the <near(future)> and see
what kind of problems it has entering programs.

_Ron Adam
 
R

Ron Adam

Ron Adam wrote:
...

And all uses of standard Python modules such as random and fileinput,
which do exactly that sort of thing systematically.

Also it would need to avoid lowering strings and literals too.

Nope, can't do. Consider:


now x and y are two VERY different things:

<random.Random object at 0x81aa9d4>

Is this very common, I tried to find other examples of this. Is
there another way to get a base class of an object? Is this different
for different modules, or is it a standard?

0.93572104869999828

...but how would a poor "case correcting editor" distinguish them...?

Something like this where 'word' is a possible name:

if word matches any name in both spelling and case:
pass # leave it alone
elif word matches a single name, but case is incorrect:
correct case
elif word matches several names spelled the same, but neither in
correct case:
give a hint
get choice from hint

Such a smart editor might HELP a little by SUGGESTING a case-correction
when it appears unambiguous, even just for standard modules and the
functions therein. Maybe a menu-command for "suggest case corrections
if any" WOULD be helpful in IDLE, and offer good cost/benefit ratio as
a fun, not-too-terribly-hard project reducing human misery a bit...:).


Alex

I think so, especially for people first starting out or switching
from another language.

I think there could different levels of correction/suggestion modes.

None == turn it off

Polite == suggest choices if the case doesn't match, but don't
actually correct anything.

Assertive == Correct when it's obvious to do so, and suggest when
there is more than one choice.


What one would choose would be dependant on how well they know python
and how accurate they type.


_Ron Adam
 
R

Ron Adam

Ron Adam wrote:
...
4: The editor or IDE matches what I enter to the names and then
substitutes the proper case of the name at some definitive point.
This ensures that the case is correct and the program compiles and
runs normally. If I choose a different editor then see #1 or #2. ...
correcting while editing. Number 4 is possible to do now, but I
don't know of any editors that currently do it. It would be a nice
option to include in one I think.

Yes, looks like a nice idea for a middling-difficulty project with
IDLE, and it would be useful even if made _particularly_ unintrusive
(spelling correction would be done only on specific request, and
only when feasible without ambiguity regarding e.g. standard library
modules and names therein -- a really minimal part of [4], yet it
would STILL save quite some trouble/hassle to those using it...).


Alex

Maybe someone will try it. I've only just started with Python about a
month ago. However I did pick up your 'Python in a Nutshell' last
night and have already read though the first 4 chapters. Great book
Alex!

I've programmed lightly in c, c++, java, several basics, and even a
little assembly. Took a course in fortran, although I don't remember
any of it. Also learned pascal once upon a time.

Python addresses many if not most of the complaints I've had with
those other languages. Most of which were either low level languages
that lacked high level functionality, or high level languages that
were difficult to extend. And then there are the visual stuff that
requires 3/4 of the code just to initialize everything. ack! What
surprises me most is why I haven't found Python sooner?

_Ron Adam
 
R

Ron Adam

A slighty different scheme would be to disallow names that differ only
in case. This would make it possible to talk about code ("the foo
function is buggy") without confusion ("which one, the one in capitals
or lower-case?"), without having having the confusing notion that 'FOO'
and 'foo' are the same. To me at least 'foo = FOO' looks like something
different than 'foo = foo'.

Ronald

I agree, I don't know how often it occurs in the libraries, and so
can't say how difficult it would be to change at this time. But I do
think it is a good thing not to use case as the only indicator of a
difference.

I think it should be discouraged as a bad or poor programming practice
in any case. In my opinion it more often than not makes code less
readable when we use case as the only difference between names.

_Ron Adam
 
R

Ron Adam

Such a smart editor might HELP a little by SUGGESTING a case-correction
when it appears unambiguous, even just for standard modules and the
functions therein. Maybe a menu-command for "suggest case corrections
if any" WOULD be helpful in IDLE, and offer good cost/benefit ratio as
a fun, not-too-terribly-hard project reducing human misery a bit...:).


Alex

It occurs to me that using a menu to suggest choices for name with
differing caps may actually encourage the use of differing caps. I
hope not. That is something to consider.

I wonder how difficult it would be to write a program that searches
the library and counts the number of instances like spelling with
differing case are used?

_Ron Adam
 
A

Alex Martelli

Ron Adam wrote:
...
I wonder how difficult it would be to write a program that searches
the library and counts the number of instances like spelling with
differing case are used?

You mean "used within the same namespace"? Not too hard, since the
key test is nothing more than something like:

o

so basically it boils down to finding all namespaces of interest.

Easy for modules, easy for classes, NOT easy for class-instances
as you'd really have to create the instances to check for such
cases as, e.g.:

class Foo(object):
def blab(self): return self.BLAB
def __init__(self, BLAB): self.BLAB = BLAB

So here's a q&d check for such module-level conflicts I just
cobbled together (avoiding obsolete modules):

import sys, glob, os.path, sets

avoid = sets.Set('''
FCNTL posixfile pre regsub statcache TERMIOS this tzparse xmllib
'''.split())

for where in sys.path:
modules = glob.glob(os.path.join(where, '*.py'))
modnams = [os.path.basename(m)[:-3] for m in modules]
for m in modnams:
if m in avoid: continue
try: modobj = __import__(m)
except ImportError: continue
dd = dir(modobj)
lowdd = [ n.lower() for n in dd ]
slowd = sets.Set(lowdd)
if len(dd) != len(slowd):
print '%s:'%m,
n = 0
for d in dd:
if lowdd.count(d.lower()) != 1:
print d,
n += 1
print

The hits in the top-level of the standard libraries are:

binhex: BinHex HexBin binhex hexbin
copy: Error error
popen2: Popen3 Popen4 popen3 popen4
pydoc: Doc doc
random: Random random
repr: Repr repr
sre_parse: SUBPATTERN SubPattern
sre: TEMPLATE template
tarfile: VERSION version
threading: _VERBOSE _Verbose
tokenize: COMMENT Comment NAME NUMBER Name Number STRING String string
xmlrpclib: Boolean boolean


there are more in lib-tk and Numeric, but not everybody will be
interested in those, I guess.


Alex
 
A

Anthony Briggs

People coming from (an exclusive diet of) case _sensitive_ (not, as you
say, INsensitive!)

Personally, I'm _case sensitive insensitive_. I can't bring myself to
be sensitive towards people who are case sensitive ;)

Ant
 
R

Ron Adam

Ron Adam wrote:
...
I wonder how difficult it would be to write a program that searches
the library and counts the number of instances like spelling with
differing case are used?

You mean "used within the same namespace"? Not too hard, since the
key test is nothing more than something like:

o

so basically it boils down to finding all namespaces of interest.

Easy for modules, easy for classes, NOT easy for class-instances
as you'd really have to create the instances to check for such
cases as, e.g.:

class Foo(object):
def blab(self): return self.BLAB
def __init__(self, BLAB): self.BLAB = BLAB

So here's a q&d check for such module-level conflicts I just
cobbled together (avoiding obsolete modules):

import sys, glob, os.path, sets

avoid = sets.Set('''
FCNTL posixfile pre regsub statcache TERMIOS this tzparse xmllib
'''.split())

for where in sys.path:
modules = glob.glob(os.path.join(where, '*.py'))
modnams = [os.path.basename(m)[:-3] for m in modules]
for m in modnams:
if m in avoid: continue
try: modobj = __import__(m)
except ImportError: continue
dd = dir(modobj)
lowdd = [ n.lower() for n in dd ]
slowd = sets.Set(lowdd)
if len(dd) != len(slowd):
print '%s:'%m,
n = 0
for d in dd:
if lowdd.count(d.lower()) != 1:
print d,
n += 1
print

The hits in the top-level of the standard libraries are:

binhex: BinHex HexBin binhex hexbin
copy: Error error
popen2: Popen3 Popen4 popen3 popen4
pydoc: Doc doc
random: Random random
repr: Repr repr
sre_parse: SUBPATTERN SubPattern
sre: TEMPLATE template
tarfile: VERSION version
threading: _VERBOSE _Verbose
tokenize: COMMENT Comment NAME NUMBER Name Number STRING String string
xmlrpclib: Boolean boolean


there are more in lib-tk and Numeric, but not everybody will be
interested in those, I guess.


Alex

Thanks Alex, I'll play around with this a bit.

It looks like the number of them is low enough to build in exceptions
for already existing instances, and it may be possible to have a
policy of avoiding it in the future.

In any case, this is helping understand how python works. I'm
finding it very interesting that so much of python is programmed in
python.

_Ron Adam
 
A

Alex Martelli

Ron Adam wrote:
...
Maybe someone will try it. I've only just started with Python about a
month ago. However I did pick up your 'Python in a Nutshell' last
night and have already read though the first 4 chapters. Great book
Alex!
Thanks!


I've programmed lightly in c, c++, java, several basics, and even a
little assembly. Took a course in fortran, although I don't remember
any of it. Also learned pascal once upon a time.

You do have just about the perfect background in term of target
audience for the Nutshell -- several varied, typical lower-level
languages, plus a smattering of Python. Though one doesn't NEED
as many different languages as you've used and studied, of course.

Python addresses many if not most of the complaints I've had with
those other languages. Most of which were either low level languages
that lacked high level functionality, or high level languages that
were difficult to extend. And then there are the visual stuff that
requires 3/4 of the code just to initialize everything. ack! What
surprises me most is why I haven't found Python sooner?

Good question; I asked it of myself just a few years ago, when I
finally did "find" it. I have no satisfactory answer, though.


Alex
 
B

Bengt Richter

Ron Adam wrote:
...
4: The editor or IDE matches what I enter to the names and then
substitutes the proper case of the name at some definitive point.
This ensures that the case is correct and the program compiles and
runs normally. If I choose a different editor then see #1 or #2. ...
correcting while editing. Number 4 is possible to do now, but I
don't know of any editors that currently do it. It would be a nice
option to include in one I think.

Yes, looks like a nice idea for a middling-difficulty project with
IDLE, and it would be useful even if made _particularly_ unintrusive
(spelling correction would be done only on specific request, and
only when feasible without ambiguity regarding e.g. standard library
modules and names therein -- a really minimal part of [4], yet it
would STILL save quite some trouble/hassle to those using it...).
You didn't mean to exclude presenting the choices when there _was_ ambiguity??

Following is a list of lib files that use the same name in differing case formats
(though not necessarily in the same name space -- this list does not distinguish
between e.g. global names and attribute/method names -- it's only looking for what
the tokenizer recognizes as names).

BTW, if all this were suddenly case-insensitive, there would be a fair amount of
work to do, I suspect. A few modules even have 3 variations. ;-)


d:\python23\lib\aifc.py:
SetParams * 2 setparams * 2
Error * 40 error * 3
Chunk * 3 chunk * 28

d:\python23\lib\audiodev.py:
SUNAUDIODEV * 3 sunaudiodev * 3
AL * 25 al * 11

d:\python23\lib\BaseHTTPServer.py:
Message * 1 message * 11

d:\python23\lib\Bastion.py:
BastionClass * 2 bastionclass * 2
RExec * 1 rexec * 2

d:\python23\lib\binhex.py:
HexBin * 2 hexbin * 2
Creator * 5 creator * 2
BinHex * 2 binhex * 2
Flags * 5 flags * 2
FName * 2 fname * 8
FInfo * 11 finfo * 19
LINELEN * 3 linelen * 4
Type * 6 type * 6

d:\python23\lib\cgitb.py:
NAME * 1 name * 38

d:\python23\lib\cmd.py:
Cmd * 1 cmd * 15
IDENTCHARS * 2 identchars * 2
PROMPT * 2 prompt * 3

d:\python23\lib\codecs.py:
Reader * 6 reader * 14
Writer * 6 writer * 8

d:\python23\lib\codeop.py:
Compile * 2 compile * 2

d:\python23\lib\Cookie.py:
K * 30 k * 6

d:\python23\lib\copy.py:
C * 2 c * 2
Error * 4 error * 1

d:\python23\lib\csv.py:
Dialect * 4 dialect * 9
M * 1 m * 4

d:\python23\lib\dis.py:
EXTENDED_ARG * 1 extended_arg * 4

d:\python23\lib\doctest.py:
Tester * 3 tester * 11

d:\python23\lib\filecmp.py:
BUFSIZE * 2 bufsize * 3

d:\python23\lib\ftplib.py:
FTP * 2 ftp * 9
Error * 6 error * 5
Netrc * 2 netrc * 2

d:\python23\lib\gettext.py:
True * 1 true * 2
Catalog * 1 catalog * 3
False * 3 false * 2

d:\python23\lib\gzip.py:
FNAME * 3 fname * 4
READ * 6 read * 17
WRITE * 6 write * 15

d:\python23\lib\httplib.py:
BUFSIZE * 2 bufsize * 4

d:\python23\lib\ihooks.py:
VERBOSE * 4 verbose * 14
Hooks * 2 hooks * 27

d:\python23\lib\imaplib.py:
Flags * 2 flags * 14
USER * 4 user * 8
Literal * 2 literal * 15
Debug * 4 debug * 14
HMAC * 1 hmac * 2

d:\python23\lib\imputil.py:
Importer * 3 importer * 5

d:\python23\lib\inspect.py:
INDENT * 1 indent * 11
NAME * 2 name * 22

d:\python23\lib\macpath.py:
File * 4 file * 2

d:\python23\lib\mhlib.py:
Error * 21 error * 23
MH * 2 mh * 13
MultiFile * 1 multifile * 2
Folder * 2 folder * 4
PATH * 2 path * 67

d:\python23\lib\mimetypes.py:
USAGE * 2 usage * 3

d:\python23\lib\mimify.py:
File * 5 file * 9
I * 9 i * 9

d:\python23\lib\optparse.py:
TYPES * 2 types * 7
Values * 2 values * 27
Option * 6 option * 67
ATTRS * 2 attrs * 8

d:\python23\lib\os.py:
PATH * 2 path * 24

d:\python23\lib\pdb.py:
Cmd * 3 cmd * 4
Bdb * 3 bdb * 11
Repr * 2 repr * 3

d:\python23\lib\pickle.py:
UNICODE * 4 unicode * 7
PUT * 3 put * 2
INT * 3 int * 4
MARK * 9 mark * 13
TRUE * 3 True * 2
LONG * 3 long * 3
REDUCE * 3 reduce * 11
PROTO * 3 proto * 16
FALSE * 3 False * 2
LIST * 3 list * 4
POP * 4 pop * 9
FLOAT * 3 float * 1
DICT * 3 dict * 4
NONE * 3 None * 42
GET * 3 get * 15
APPEND * 4 append * 37
OBJ * 3 obj * 120
INST * 3 inst * 5
TUPLE * 4 tuple * 3

d:\python23\lib\pickletools.py:
I * 55 i * 6

d:\python23\lib\pipes.py:
FILE * 2 file * 17

d:\python23\lib\platform.py:
System * 2 system * 51

d:\python23\lib\popen2.py:
Popen3 * 5 popen3 * 5
Popen4 * 3 popen4 * 3

d:\python23\lib\pre.py:
I * 1 i * 14
M * 1 m * 9

d:\python23\lib\profile.py:
Stats * 2 stats * 3

d:\python23\lib\pstats.py:
Cmd * 2 cmd * 3
Stats * 6 stats * 32

d:\python23\lib\pyclbr.py:
NAME * 5 name * 16
Class * 5 class * 2

d:\python23\lib\pydoc.py:
GUI * 2 gui * 3
Doc * 3 doc * 44
Scanner * 3 scanner * 9
Message * 5 message * 2
Entry * 1 entry * 10
Repr * 6 repr * 26
S * 2 s * 4
I * 2 i * 10
Tk * 1 tk * 1

d:\python23\lib\Queue.py:
Queue * 1 queue * 6
Empty * 3 empty * 1
Full * 3 full * 1

d:\python23\lib\random.py:
Random * 7 random * 47
VERSION * 6 version * 8
N * 17 n * 21

d:\python23\lib\repr.py:
Repr * 2 repr * 3

d:\python23\lib\rexec.py:
RExec * 2 rexec * 14
Hooks * 2 hooks * 6

d:\python23\lib\rfc822.py:
AddressList * 5 addresslist * 21

d:\python23\lib\robotparser.py:
Entry * 5 entry * 19

d:\python23\lib\sets.py:
Set * 1 set * 3

d:\python23\lib\shutil.py:
Error * 2 error * 1

d:\python23\lib\SimpleXMLRPCServer.py:
Fault * 4 fault * 5

d:\python23\lib\smtpd.py:
COMMAND * 5 command * 16
DATA * 3 data * 18
Options * 2 options * 15

d:\python23\lib\smtplib.py:
I * 1 i * 4
HMAC * 1 hmac * 2

d:\python23\lib\sre.py:
TEMPLATE * 1 template * 14
S * 1 s * 9
SUBPATTERN * 2 SubPattern * 2
Pattern * 1 pattern * 35
I * 1 i * 8
M * 1 m * 6
Scanner * 1 scanner * 3

d:\python23\lib\sre_compile.py:
LITERAL * 10 literal * 2
RANGE * 4 range * 5
IN * 2 in * 23
NEGATE * 3 negate * 3
CHARSET * 2 charset * 22
ASSERT * 1 assert * 2

d:\python23\lib\sre_constants.py:
IN * 3 in * 2

d:\python23\lib\sre_parse.py:
FLAGS * 4 flags * 11
LITERAL * 31 literal * 7
SUBPATTERN * 2 SubPattern * 5 subpattern * 25
Pattern * 2 pattern * 16
IN * 11 in * 42

d:\python23\lib\string.py:
L * 3 l * 3

d:\python23\lib\symtable.py:
Class * 2 class * 5

d:\python23\lib\tarfile.py:
VERSION * 2 version * 1
BUFSIZE * 4 bufsize * 13
TarFile * 4 tarfile * 18
TarInfo * 8 tarinfo * 229
TOREAD * 2 toread * 5

d:\python23\lib\telnetlib.py:
DEBUGLEVEL * 2 debuglevel * 9
SB * 2 sb * 9

d:\python23\lib\tempfile.py:
Random * 1 random * 1

d:\python23\lib\threading.py:
_VERBOSE * 2 _Verbose * 14
Lock * 4 lock * 9
Thread * 11 thread * 6

d:\python23\lib\timeit.py:
Timer * 2 timer * 8

d:\python23\lib\token.py:
NAME * 1 name * 2

d:\python23\lib\tokenize.py:
COMMENT * 4 Comment * 3
INDENT * 1 indent * 1
Token * 2 token * 23
NAME * 1 Name * 3
NUMBER * 1 Number * 3
STRING * 3 String * 2 string * 2
ContStr * 2 contstr * 10

d:\python23\lib\trace.py:
Trace * 2 trace * 11
Ignore * 2 ignore * 2

d:\python23\lib\unittest.py:
TestLoader * 3 testLoader * 5

d:\python23\lib\urllib.py:
FTP * 1 ftp * 13
I * 1 i * 31
IC * 1 ic * 4
Close * 1 close * 14

d:\python23\lib\urllib2.py:
H * 10 h * 20
I * 1 i * 23

d:\python23\lib\uu.py:
Error * 5 error * 1

d:\python23\lib\warnings.py:
I * 1 i * 3

d:\python23\lib\wave.py:
Chunk * 3 chunk * 22

d:\python23\lib\webbrowser.py:
Error * 2 error * 1

d:\python23\lib\xdrlib.py:
Error * 3 error * 2

d:\python23\lib\xmlrpclib.py:
Transport * 3 transport * 5
Parser * 1 parser * 16
Boolean * 6 boolean * 2
Server * 1 server * 3

d:\python23\lib\zipfile.py:
CRC * 16 crc * 2

d:\python23\lib\_strptime.py:
LC_TIME * 1 LC_time * 4


Regards,
Bengt Richter
 
G

Greg Ewing (using news.cis.dfn.de)

Douglas said:
I agree with Alex. Case sensitivity is evil! When color monitors
started becoming common, I began to worry that programming languages
would come to allow you to have blue variable names, and red and green
variables names, and they would all be different.

It's already happened:

http://www.colorforth.com/cf.html
 
D

Douglas Alan

I never understood why you advocate case insensitivity. I would
expect case insensitivity to be a source of bugs: for instance,
identifiers with similar names could be confused (es. myfunction
vs. myFunction): one would expect them to be different (at least
people coming from case insensitive languages) whereas they would be
the same.

When you use a case-insensitive language, you do not typically use
StudlyCaps at all, so you wouldn't ever write "myFunction". Instead,
you would write "my_function" or "my-function", depending on the
language. Then you might use "MY-FUNCTION" for ephasis. For
instance, you might write:

(defun MY-FUNCTION (x)
(if (= x 0)
1
'else
(* x (my-function (- x 1)))))


Here "MY-FUNCTION" in in upper case, just so it stands out more
easily, kind of like how editors now show your function names in red
where they are defined, only you could do this back in the day of
black and white screens.
Also, now I can write


def one(): return 1
and it is clear that the first name (ONE) refers to a constant
whereas the second name (one) refers to something which is not a
constant.

Personally, I hate this style, because I can't stand to have
constants shouting at me in upper case all of the time. Save the
shouting for when it's important, DAMNIT!

I prefer constants to be written as c_one, or something like that that
is less loud on my delicate ears^H^H^H^Heyes.

|>oug
 
P

Peter Hansen

Douglas said:
When you use a case-insensitive language, you do not typically use
StudlyCaps at all, so you wouldn't ever write "myFunction". Instead,
you would write "my_function" or "my-function", depending on the
language.

This is the second ludicrous thing I've seen you write today. The
first was when you claimed Fredrik Lundh was "dead wrong" about the
use of tuples vs. lists, when your own view is in direct contradiction
to a very widely used convention in the Python programming world,
and supported by the FAQ entry and Guido's own views.

When *I* have used case-insensitive languages, I have certainly used
various forms of capitalization to represent different types of
information, such as functions or constants. I am definitely not
alone in this approach, as I have learned it from reading others'
code.

*You* might not do so, but your opinions are clearly not held by
all other programmers, nor perhaps even the majority, so please
stop writing as though they are.

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top