New statement proposal for Python

David LeBlanc whisper at oz.nospamnet
Fri Jun 15 23:08:11 EDT 2001


In article <slrn9ijrog.8bp.philh at comuno.freeserve.co.uk>, 
philh at comuno.freeserve.co.uk says...
> On 15 Jun 2001 02:37:51 GMT, David LeBlanc <whisper at oz.nospamnet> wrote:
> >
> >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.
> 
> Surely a newbie can understand that if you assign a variable to a 
> value, and then never change it, then it is working as a constant.
> 
> I have no problem having cxonstants like this, e.g.
> 
>    programVersion = "0.2.7"
> 
> it seems to me that:
> 
>    alias programVersion: "0.2.7"
> 
> is no clearer, and is an extra something for a learner to have to learn.
> Entities should not be multiplied unnecessarily!

I absolutely agree that entities shouldn't be multiplied unnecessisarily! 
However your suggestion in fact does just that: there is nothing that 
prevents one from reassigning to programVersion in some module you 
import. Oops... The important difference is that you can't change the 
replacement text of an alias once set: it's immutable.

> > I 
> >think all would agree that "if something is true:" is clearer then "if 
> >something is not 0:".
> 
> What's wrong with:
> 
>    if something:
> 
> which is what I would use here.

Hardly worth mentioning that if (something) is a common source of error 
in languages like C and C++ where the missing boolean is assumed.

> > Likewise, "userpermissions" is much more meaningful 
> >then 0677
> 
> Indeed so. And in python, one can say:
> 
>    userPermissions = 0677

And in Python, 432 lines later one can say userPermission = 0777 and then 
scratch one's head as to why file permissions have gone awry. If it where 
an alias, you'd get a usefull error: Error: attempt to change alias.

> (Personally I prefer the way Smalltalk handles non-decimal radixes,
> i.e. 8r677)

That I can agree with :>

> >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;
> 
> When I hear that phrase, I reach for my gun. Go and use Pascal or
> Eiffel if you're into bondage-and-discipline.

Oh god am I tempted... but i'll refrain.

Dave LeBlanc



More information about the Python-list mailing list