Python questions from C/Perl/Java programmer

ye, wei yw at alabanza.net
Mon Jul 24 18:49:48 EDT 2000


Remco Gerlich wrote:

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

Perlsonally, I don't agree with you, but I can bear with the rule.

>
> 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?

I have been using 'emacs',  it's a nice editor, however I still concern if
add or remove a new block within a complex logic it may mess up
the old application. However if {} is applied, I'm pretty sure it doesn't
happen.


>
>
> > 2. Why variable doesn't have to be declared before use?
>
> Because it's not necessary!

I can bear the {} issue, however I couldn't bear with variable without
declaration.
I wrote many applications, I couldn't live without declaration. For big
project,
there are so many scripts, everyone may be misspell variable name.
It's very timeconsume and hard to find out such problem, which should
be easy checked out by compiler.


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

I agree with you script language is very good at rapid development, this is why

I like Perl. Java is very good language, however it takes much longer time to
develop projects because it's not a script language.

However I don't think "not need for decalaration" is the favor for rapid
development.
We used "use strict" package in every Perl script to force "variable
declaration", it doesn't
waste any time for development, however project is still rapid to be developed.



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

I will be very *HAPPY* if it's true!!!!!  I believe Python will be much
stronger and grow faster
if such features are enabled.

Python's goal is a simple language, which everyone can use it to write program.

However it should be a good language, which can as more as possible to correct
the mistake
people may make.  This help programmers to shorten development and testing
time.

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

Yes, it is if you define a function expect a base class, its derived class
object should
have no problem to be passed in. Both Java/C++ have this feature.

If don't specify the variable type:
1. When you read code, it's not easy for you to understand how to invoke that
function.
   For example, compare
def f(x, y, z): ...  with def f(int x, complex b, Employ c): ...
which declaration give you more information without read further code?
You know how to invoke the latter one without read its code and comments in
most cases.

2.  it leads the function is mis-called by passing not correct type.

Again, do you know how Perl function is defined? Just like this:
sub f { ... }

Without parameters as well as types. The authors tried to add some prototype
checking later, but too late,  that will
cause imcompatible problem with existed scripts.   Perl's function declaration
should be more flexible, however
without parameter and type checking, it's causing many problems, and couldn't
be tolerated.

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

Thanks!

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

I still would like to post it on mailinglist, hope developer team can think
about it.


>
>
> --
> Remco Gerlich,  scarblac at pino.selwerd.nl
> "Early to rise, early to bed, makes a man healthy, wealthy and dead." -- TP
> --
> http://www.python.org/mailman/listinfo/python-list

--

Sincerely,

Wei Ye







More information about the Python-list mailing list