Case insensitivity

Tom Bryan tbryan at python.net
Sat Jul 21 12:47:10 CEST 2001


Sheila King wrote:

> In an attempt to address the "why" of this problem, I have posted the
> following article to two mailing lists to which I belong, for AP
> Computer Science teachers:
....
>> Those of us who programmed in Pascal, certainly recall the
>> case-insensitivity of that programming language. And now that we are
>> programming in C++, and moving to Java in another couple of years, we
>> are programming in a case-sensitive language. Python is currently a
>> case-sensitive language.

I'm not sure how much of a difference this makes, but there is another (to 
me) important difference.  Python is an interpreted language, and name 
errors are not caught until runtime.  That is, in Java, the following class 
gives me an error at compile time

public class Test {
        public static void main( String args[] ) {
                int var = 0;
                if (false) {
                        System.out.println( "We don't run this code: " + Var );
                } else {
                        System.out.println( "This code is run " + var );
                }
        }
}

$ javac Test.java
Test.java:8: error:Variable "Var" is not defined in current context

Whereas the equivalent Python doesn't give me *any* error at run time.
if __name__ == '__main__':
    var = 0
    if 0:
        print "We don't run this code: " + str( Var )
    else:
        print "This code is run " + str( var )

$ python test.py
This code is run 0

Thus, whether simple errors like this are detected in Python depend 
in part on whether the programmer tests every possible path of 
execution.  Of course, case-insensitivity doesn't really "fix" this 
problem.  I more often have problems like mixing var and bar.  Perhaps 
it would be nicer if Python had a switch that gave errors for names that 
are used that don't exist at compile time.  I know that it's possible to 
create names in Python at runtime, but for those programs that don't use 
such features, this type of guarantee might be nice.

The "should it be a tool solution or a language solution" could then 
rage over this new issue. 

---Tom




More information about the Python-list mailing list