Case Sensitivity and Learnability
Tres Seaver
tseaver at starbase.neosoft.com
Fri Jan 28 22:26:15 EST 2000
Thinking about the notion of case sensitivity as a barrier to CP4E, as
advocated quite glibly at IPC8, I typed up this module on the plane to
explore the consequences of allowing/encouraging users to enter case-
mangled code, especially in non-interactive uses (I think that distinc-
tion may be important, because readability is almost insignificatn in
an interactive session).
# begin randomCase.py
""" Scramble the case of standard input.
This module attempts to rebut the argument that case insensitive code
intrinsically more "usable" for J. Random Novice than case sensitive
code. The flaw in this argument is that it confuses "typability" with
"usability" -- while a case-insensitive language may be less daunting
for the fledgling programmer to type, code which actually _uses_ case
insensitivity is MUCH harder to read. Precisely as with natural
language, learning to read code is essential to learning to write code;
code which is harder to read frustrates this process.
I would therefore argue that addressing the "typability" issue by
modifying the language is the Wrong Thing -- the place to fix this is in
the tools, through the equivalent of an incremental spell checker.
"""
import sys
import string
import whrandom
def identity( c ):
return c
flippers = {}
for c in string.uppercase:
flippers[ c ] = string.lower( c )
for c in string.lowercase:
flippers[ c ] = string.upper( c )
def flipCase( c ):
return flippers.get( c, c )
#
# This set of transformation functions perturbs the stream pretty severely.
#
HEAVY_TRANSFORMS = ( identity
, identity
, identity
, identity
, identity
, identity
, string.upper
, string.upper
, string.upper
, string.lower
, string.lower
, string.lower
)
#
# Perhaps this is more reasonable -- one alpha character in eight flips its
# case?
#
SAMPLE_TRANSFORMS = ( identity
, identity
, identity
, identity
, identity
, identity
, identity
, flipCase
)
def randomCase( istream=sys.stdin
, ostream=sys.stdout
, transforms=SAMPLE_TRANSFORMS
):
"""
Replace random characters in a istream using the functions supplied
in transforms.
"""
for line in istream.readlines():
mangled = []
for c in line:
mangled.append( whrandom.choice( transforms )( c ) )
ostream.write( string.join( mangled, '' ) )
if __name__ == '__main__':
randomCase()
# end randomcase.py
Now observe the effect of running it on itself:
""" Scramble thE case of standard inpuT.
tHis moduLe attempts to rebut the argumeNt that case insensiTive code
intrinsically more "usable" for J. Random Novice than case sensITive
code. The flaw in this Argument iS THAt it confuSes "typabilIty" with
"usAbIlity" -- while a case-inSensitive language may be less dauntIng
For the fledgLing programmEr tO tyPe, cOde which actuALly _Uses_ case
insEnsitivItY is MUCH hArdER TO Read. PreciseLy as wIth natural
Language, learning to read COde is essential to lEarNing to write code;
code which is harder to reaD fRUstrates thiS proceSs.
I would tHerefore argue thaT addrEssing thE "typAbility" isSue by
MoDiFying The laNguage Is the WRoNg Thing -- thE place to fIx this is in
the tools, thrOugh the equiValent of a spell checker.
"""
import sys
import string
impoRT whrandom
Def identity( c ):
return c
flipPerS = {}
for C iN sTring.uppercase:
flippers[ c ] = strIng.lower( c )
For c in string.lOwercaSe:
flippErs[ c ] = string.upper( c )
def flipCaSe( c ):
reTUrn flippers.get( c, c )
#
# This seT of transforMation fUnctions perturbs the strEam pRetty severeLy.
#
HEAVY_TRaNSFoRmS = ( iDeNTiTy
, identiTy
, identiTy
, identity
, IdentiTy
, idenTitY
, STrIng.uPper
, striNg.upper
, stRing.upper
, string.LoWer
, strinG.lower
, strinG.lower
)
#
# Perhaps this IS more reasonaBle -- oNe alpha chaRactER in eight flips its
# casE?
#
SAMPLE_TRANSFORMS = ( identity
, identity
, identity
, identity
, identity
, ideNtity
, IdentiTy
, flipCasE
)
def randomCase( iStreaM=syS.stdin
, ostream=syS.stdout
, tRanSfOrms=SAMPLE_TRaNSFOrMS
):
"""
ReplAce random charaCterS in a istream Using ThE functionS SuPpliED
in Transforms.
"""
For line in istrEam.readLines():
mAnGled = []
for c in liNe:
maNgled.Append( wHrANdom.choice( transfoRms )( c ) )
ostream.write( string.join( mangled, '' ) )
if __name__ == '__main__':
randomCase()
--
---------------------------------------------------------------
Tres Seaver tseaver at palladion.com 713-523-6582
Palladion Software http://www.palladion.com
More information about the Python-list
mailing list