No Thoughts about Everything
b-blochl
bblochl2 at compuserve.de
Wed Feb 25 10:53:31 EST 2004
I wonder about the huge traffic in the question how many tuples are
dispensible. I find that a question of only ternary or quarterny order -
use it or use it not (free after Shakespears "to be or not to be). Well,
I had my part on that.
But introducing students to python as a first programming language lists
and tuples are astoninglishy always constant points of confusion as well
as the other points of the citatet list. I will not repeat it now, but
the class-questions are more interesting for me and fundamental for the
choice of python.
A point of vital interest for me are the classes and the handling of
class variables. I have read a lot of discussion threads in the mean
time and the PEP 318 as well. One point of critic will become obsolet
with the possible future change described in PEP 318. (Use of Java-like
modifiers is simpler.)
I find the syntax and handling of classes and class variables (or static
variables) in python not an absolute success. Fist that is a result of
comparing my personal experience with Java in the first place. Second it
is an experience of introductory teaching python. The learning curve is
astoninglishly steep, but it will flatten arriving at classes and
objects in python. Compared with Java I found it just opposit.
Beside, I find the concept of modifiers in Java very attractive. (May be
that concept is not absolutely clean OO - but it is very simple to apply
in real world programming.) Some arguments I found in the discussions
make me arguing that some concepts connected to that modifiers are
absolutely misunderstood. For instance "information hiding" with the use
of the modifier "private" for instance variables and/or methods
basically means that no direct access from the clients is allowed. There
is no doubt, that that concept rescues bugs and improves program
modification. In the discussions very often "information hiding" is only
interpreted as "hidden code". Even compiled Java code can easily be
recovered - start a internet search for appropriate tools. In an
interpreted language like python I see no problem at all. (Guido will
never allow hiding.......)
Let me give you an instance for the use of the Java modifiers static and
final. (There are three "visibility" and seven other modifiers in Java)
That problem is not a constructed and log searched example, but an every
day application in teaching for instance natural or engineering science,
while using Java. I kindly ask for help to transfer that simple, single
line intelligent to python in the best possible way:
static final double c=2.99792458e8;
That is the speed of light in vacuum in scientific (exponential)
notation. I use it in a class as a class variable. That means it will be
shared as a single copy of a variable among all of the objects
instantiated from that class. That is the meaning of the modifier
"static". With final I make it to a constant, that cannot changed by any
code. (double is self speaking, it is not necessary in python - as
anyone knows.) I dont like to use c as global variable. A possible
waywith the following code recipes?
1. modifier final
For instance recipe 5.15 Defining Constants (Alex Martelli) out of the
python cookbook (OReilly, ISBN 0-596-00167-3) shows, how to define
constants. About 10 lines, instead of one modifier - I have not found
another way.
2. modifier static
There is recipe 5.6 i(Alex Martelli, Carel Fellinger) in the cited book
shows how to implement static Methods to make variables static. Three
more lines for a simple modifier.
With some time and by trial and error may be I find the solution. But
there are many Geeks reading python.org. I think for them it is only a
fingersnip to transfer that to the python way? So, here again my Question:
How can I create such a "class constant" (static final / recipe 5.15 and
5.6 in one) in python as short as possible?
(I hope you recognize, why teaching python to beginners becomes tedious
in python arriving at that point?)
Thanks in advance
Bernhard
More information about the Python-list
mailing list