Case Insensitivity (was Language change and code breaks)

Tim Hochberg tim.hochberg at ieee.org
Thu Jul 19 22:00:59 CEST 2001


I expect there will always be people who come to python expecting it to be
case sensitive as well as those new programers who supposedly expect it to
be case insensitive. Making the language purely case insensitive,
particularly given its dynamic nature, seems like a recipe for disaster. On
the other hand, if this does turn out to be a real impediment to new
programers, a variation on case sensitivity -- prefereably activated by a
flag to the interpreter -- might be useful. I'm not sure what to call this
variation, except that it would flag as an error using a name that differed
from another only by case.

Hmmm. Since all variables with the same name would have the same case, I
guess we could call it 'case consistency' instead of 'case insensitivity.

Let's look at an example for why case sensitivity could be a problem. It's
common practice to use all caps to designate constants, so consider the
following code:

class Contrived:
   HAS_SPAM = 1
   HAS_EGGS = 2
   #....
   def has_spam(self):
      if self.flags & self.HAS_SPAM:
         return 1
      else:
         return 0

For pure case sensitivity this would fail rather mysteriously (with an
attribute error for HAS_SPAM, I believe). For the second type of case
insensitivity described above, this would instead fail during compilation
with an error something like:

CaseMismatchError: Case of 'has_spam' doesn't match previous usage (did you
mean 'HAS_SPAM').

With a carefully designed error message, I think it could be made obvious to
both beginner and expert alike where the error was and how to fix it. In
addition, since case consistent programs  would be a subset of case
sensitive programs, this could be implemented as a flag to the interpreter
that would cause the interpreter to behave this way so that beginners and
others who prefer case consistency could have it, while us sensitive folks
could continue using Python with its current case sensitivity.

There would, admittedly, be some trickiness in calling out to case sensitive
modules from from case consistent ones, but I don't think these would be
insurmountable.

sensitive-to-change-ly yours,

-tim





More information about the Python-list mailing list