Python questions from C/Perl/Java programmer

Remco Gerlich scarblac-spamtrap at pino.selwerd.nl
Mon Jul 24 16:13:21 EDT 2000


ye, wei wrote in comp.lang.python:
> 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.

Unless the braces are misplaced. Just like indentation makes sure the logic
is correct, unless it's misplaced. At least with indentation it always does
what it seems to do, braces can be visually misleading if the indentation
looks different.

Other short answers: it saves typing, is more readable, braces aren't
necessary, they're ugly.

It's just Python.

> 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 :
>          ...

Use a good editor. It's not so hard to check if the current line lines up
with the previous one. It's not hard to indent a long C function either,
is it?

> 2. Why variable doesn't have to be declared before use?

Because it's not necessary!

> Is this hard to be implemented in script language?

No, the other way around - this is a scripting language, meant for rapid
development, least hassle for the programmer - so no need for declaration.
Although there is work in progress on this issue - it may become optional
in the future. If you make everything strict and using { } and so on you've
just got some dialect of Objective C or Java or something...

Also, by forcing a variable to be a certain type (like arguments to a
function) you use flexibility. For instance, many functions except to get an
open file, but if you give them some class instance that works just like an
open file the functions don't complain and just work. That's very cool, but
it wouldn't work with strict types.

But well, why am I replying to this. You've just met some Python features
that make Python Python; we're used to them and think they're good. See for
yourself :-).

I've set followup-to poster since we could continue over email, but this has
been done to death in the group already.

-- 
Remco Gerlich,  scarblac at pino.selwerd.nl
"Early to rise, early to bed, makes a man healthy, wealthy and dead." -- TP



More information about the Python-list mailing list