Python questions from C/Perl/Java programmer

ye, wei yw at alabanza.net
Mon Jul 24 12:31:05 EDT 2000


I'm a programmer and have C/C++, Perl, Java, PHP experience, now I'm
interested
in Python now. I spent a day to learn the Python, it's a cool language,
however I have the following
questions:

1. Why not use {}?!
def f:
    ...
why not use {} like this:
def f {
    ...
}

I'm almost couldn't bear with it?! {} is not difficult to be added,
however it can make sure the
logic is correct. It's easy and simple. SPACE and TAB mixed may cause
problem in Python script, consider use 'vi', it's hard to write Python
script.

The other problem is if you want to added a new condition in a complex
already existed condition statement,
e.g. In the following example, If you want to added a new 'if' between
line 1 and 2, you have to add TAB from Line 2 to 199,
it's difficult to make sure you don't make mistake. (The case may be
more complex as the example which I give).

1     if() :
2        if():
3           ....
             ....
             ....
100   else:
             ...
200else :
         ...

2. Why variable doesn't have to be declared before use?
Perl and PHP variables don't have to be declared before use, it's easy,
however
if a variable happens to be spelled wrong, it takes time to found it. In
the other word -
it causes to more time on testing and debug.
This is why perl 'use strict' come out and obviously we benefit from it
a lot.
In perl, if you use 'strict' package, you need declare variable before
use it, or
your script couldn't run. for example:
#!/usr/bin/perl
use strict;
my $i;
$i=...


I like variable need to be declared before use, alos perfer the declare
with type, e.g.
int i;
object x;
def f ( object x, int i):

Is this hard to be implemented in script language?

Thanks for advance!

--

Sincerely,

Wei Ye







More information about the Python-list mailing list