New statement proposal for Python

David LeBlanc whisper at oz.nospamnet
Thu Jun 14 22:37:51 EDT 2001


In article <mailman.992549543.6896.python-list at python.org>, 
skip at pobox.com says...
> 
>     David> My proposal:
> 
>     David> alias httpport : 80
>     ...
> 
> Interesting idea.  Why do you prefer ":" over "="?
> 
> 
I prefer : to = because this isn't an assignment per se. It is not, imho, 
a departure from python usage:

def fn(a,b,c):

if something:

for thing in things:

etc.
(in fact it occurs to me that at least the def statement is a form of 
alias where (argument) substition is done! At least conceptually the body 
of a function replaces it at invocation time.)

Creating an inherent means of creating constants (or my preferred 
aliases) is good computer science as someone else mentioned in a reply 
post. Magic numbers are bad - they're sloppy programming and a source of 
errors if they must be used in several places etc. OTOH, aliases clarify 
program meaning and imho make things more comprensible to newbies. I 
think all would agree that "if something is true:" is clearer then "if 
something is not 0:". Likewise, "userpermissions" is much more meaningful 
then 0677 (or whatever - it's been too long since i've used unix heavily, 
but I think the point is clear).

As for the distinction between const(ant) and alias: Perhaps it's a 
matter of aesthetics, but somehow alias is more descriptive then const 
since it suggests the substition that's happening. Further, it's 
incorrect to call "alias true: not 0" a constant imho. To further 
belabour (with a tip of the hat to the english cousins) the point, it 
read so nicely to be able to say "if something is true" rather then "if 
something is not 0" (saves on typing too :-)).

Other suggestions to import large libraries or make modules instances are 
not things calculated to gladden the heart of a newbie who seeks 
simplicity, nor would the code enlargement (my aren't I diplomatic ;)) 
win the approval of an experienced developer who doesn't want to search 
exteraneous lines when a bug pops up - which is statistically more likely 
with more lines of code, not to mention the antics needed to do something 
that should be as simple as possible (imho).

One can certainly argue that this is syntactical sugar. It does however 
serve a multitude of good purposes among which are: maintainability; 
clarity;  consistancy; correctness; good programming habbits; - a not 
inconsiderable set of advantages for a little sugar. 

Finally, this wouldn't break any code, nor would anything (excepting 
perhaps peer pressure) force anyone to use it.

Sincerely,

Dave LeBlanc



More information about the Python-list mailing list