No Thoughts about Everything

b-blochl bblochl2 at compuserve.de
Fri Feb 27 11:35:26 CET 2004


Dave Brueck schrieb:

>bblochl wrote:
>  
>
>>I found a solution for the simulation of access modifier "static final "
>>in python:
>>
>>
>>class Mytest:
>>    LOGE_10=(2.302585092994046,)
>>    #Klassenkonstante (static final) use a tuple :-)
>>    #def __init__(self):
>>
>>    def log10(self,x):
>>        return(log(x)/LOGE_10[0])
>>
>>testmath=Mytest()
>>print "LOGE_10=%10.8f"%Mytest.LOGE_10[0]," and
>>log10=%f10.8"%testmath.log10(3)
>>Mytest.LOGE_10[0]=1
>>#print "LOGE_10=%10.8f"%Mytest.LOGE_10[0]," and
>>log10=%f10.8"%testmath.log10(3)
>>    
>>
>
>You want constants because you're worried that somebody will reassign the
>value, but do you (1) actually expect that that same programmer will remember
>to index it and (2) won't reassign a list value? :) Forcing the programmer to
>remember to do LOGE_10[0] instead of just LOGE_10 will be a source of way more
>bugs.
>
>Nothing is stopping him/her from doing:
>    Mytest.LOGE_10 = 5
>  or
>    Mytest.LOGE_10 = [5]
>
>If you really have to deal with this type of programmer, Python is probably not
>a good language to use. I recommend Pascal or something more strict because
>Python does little or nothing to protect against ill-intentioned /
>undisciplined programmers.
>
>But whatever you choose to do, please please PLEASE don't teach this to your
>new Python programmers - it is not how Python programs are written, it makes
>the code less readable, and it doesn't solve any real problem (where "real"
>means "one that actually occurs in practice").
>
>If it gives you some sense of security, then go ahead and use it in your own
>private code, but please don't pass this along to your students as "how you
>simulate Java's  'final' modifier in Python" because that's incorrect.
>
>Nice talking to you - have fun!
>-Dave
>
>
>  
>
Hi Dave,
Thanks for your constructive mail. I argue that many of the commenters 
have lost the starting point of that discussion thread that I incautious 
began 24.02.2004  and the development of the discussion in between. (Be 
shure that I will avoid such in the future!)  So obviously some people 
think me to drive crazy in using python in a way one usually does not - 
python spirit. To clarify in short: There was a contribution, where some 
critic points were listed - and the first point was "clumsy static class 
methods" and some statements to this point. (See PEP 318).

Myself I tried for longer to find a simple way to use access modifiers 
in python. I know them from JAVA since long time and I highly appreciate 
them for clearance and simple application to variables and classes as 
well. Absolutly beautiful and simple! (See/ Design principles  
http://www.python.org/dev/culture.html/ rules "1. Beautiful is better 
than ugly." and "3.  Simple is better than complex.")  So I asked in the 
mailing list for such concepts. ( I know Jython and I like it as much as 
python and I will check it again.)

My  starting point was the modifier static in combination with final. (I 
will use it to define natural constants once, without a chance to change 
them, may be eventually by inattention.) But I argue that that 
JAVA-concepts are not familiar in the python world. (One should look 
over the fence from time to time!) The modifier "final" (he keyword 
final) means that the value assigned to a name is final and will never 
change. such name declared *static and final* will exist as a single 
copy of the constant and will be shared among all the objects 
instantiated from the class. In JAVA a variable (or class) is set static 
simply by applying the modifier "static" and a variable (or class) is 
set final simply by applying the modifier "final".(To remember: "1. 
Beautiful is better than ugly." and "3.  Simple is better than 
complex.") Then one copy of that variable (object) will be created the 
first time that a class is loaded, and that copy will remain in 
existence until the program stops running. (That ist possible in python 
by the builtin "staticmethod(function):". But I find the application of 
the keyword static more elegant and simple.

*Again: The essential point of my interest was  to combine static with 
final in python as well!* That is state of the art and common use in 
real OOP. That is not a pervert idea of mine but a weel established 
concept. I never saw my snipplet of dirty code as the philosophers 
stone. ( The philosophers stone is sometimes very similar with the fools 
stone.) I know the unacceptable disadvantage of the error message if 
someone tries to change the value of the tuple. So it is not applicable 
in a real program! I used it to clearify my imagination of the 
realisation of "static final". So obviously that everyone thinks me to 
write crazy code and wearing a too large hat or pushing beginners off 
the programmers wagon! And I never ever planned to "teach" such nonsense 
code to everyone. (Again it was only a try to clarify the proposed 
concept.)

Preventing  programmers to reassign values of Variables is obligate 
suspicion for the sake of robust professional program development. The 
essential point  is, that no one should ever finger a static final 
varable in strict OOP and there very often is absolutely no need for! It 
is absolute wrong to speak of ill-intentioned /undisciplined 
programmers. Mankind is very unperfekt and one should stay on earth. 
Every programmer always is ill-intentioned /undisciplined - at first I 
myself! As a fact the largest error in computer science is sitting in 
front of the computer! ( May be the wife/husband of a programmer may 
have left him, or actually the beer drinking event "Oktoberfest" in 
Munich makes some headache. And so on.)  So it should be a rule of the 
trade to make the making of errors impossible where ever possible. For 
instance use of "static final" will help. Use it when ever appropriate!

There are some different fields of application - for some fields python 
is perfect as it is. But I miss some modern concepts in python I would 
like to find and use. I do miss the usual concepts of modern programming 
techniques in python. For instance I find it practically impossible to 
map a UML design to a python program. I would say *UML sets the 
conceptual standard for todays professional application programming*. 
Conceptual standard says nothing about syntax. My vision and dream is 
the marriage of the scripting power with the intentation syntax  with 
the strict object power of JAVA.. (I am awaiting a flame?)  And I have 
pointed out that sefety *must be* mostly part of the language to keep 
systems save and manageable!  In the Jython index I found no entry for 
the keyword "final".

You mention Pascal: Turbo-Pascal was a good choice in the past, 
ANSI-Pascal was horrible. Pascal - to my opinion has reached the 
retirement age. Python died on its side effects. Python should take 
care! That compares exactly to the problem, where the actual discussion 
bagan! Pascal has a second life in  Delfi/Kylix. (In my oppinion Delfi 
is a good choice for transporting ultra heavy load.) Your proposed 
solution was to change to another language - no problem.  I confess JAVA 
to my choice, because of the straight OO concept and some features that 
have been the center of the preceeding discussion.

I hope I met the point and cleared up all misunderstandings for one and 
ever.

Have fun with the device!

Bernhard





More information about the Python-list mailing list