Mailinglist Archive: opensuse (1473 mails)

< Previous Next >
Re: [opensuse] editor that does not eat out TAB characters
  • From: G T Smith <grahamsmith@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
  • Date: Tue, 16 Jun 2009 11:04:58 +0100
  • Message-id: <4A376E4A.3010309@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

nordi wrote:
Maura Monville wrote:


I am appalled at a modern object-oriented language that is built on a
suyntax which is sensistive to indentation !
This is not a bug, it is a feature. It forces programmers to use
indentation, and to use it consistently. That means all Python programs
are indented the same way (=easy to read).


Indentation based block definition has some limitations. While many
aspects of Python are very good, this particular departure is problematic.

I explored Python out of curiosity a while back and this particular
feature was enough for me not to consider making use of the language for
any future project.


Also, you don't have to explicitly mark blocks with {..} or do...done or
whatever as in other languages. This explicit marking and the
indentation have redundant info about the program structure: One is for
the compiler/interpreter, one for the human. But redundancy can lead to
inconsistency, e.g. a programmer writing
if (foo == 1)
bar();
foobar();

A minor issue. Which for any half way decent IDE would be reformatted as ..

either

if (foo == 1 ) bar();
foobar();

or

if (foo == 1 )
bar();
foobar();

according to formatting preferences by applying the IDE formatter...

BTW Some consider it good practice in C/C++ and similar to use the form...

if (1 == foo) bar();

to avoid accidents like

if (foo = 1) bar();

which is usually correct syntax but may not give intended result. When...

if (1 = foo) bar()

in most languages will generate a runtime or compile syntax error..


For the human eye, foobar() belongs to the if statement. For the
compiler it does not, because there is no {...}. This kind of mistake
cannot happen in Python, because syntactically, what you see is what you
get. Removing the redundant info also makes it easier to read the code,
because there is simply less to read.

Depends whether the syntax actually adds functionally, e.g. in many
C/C++ like languages blocks can be used to control variable scope.
(Something rather difficult to follow without an explicit beginning and
end of block definition). What the block indentation does is make EOL a
kind of implicit end of statement and obscures more subtle aspects of
code structure.

(Closures must be fun in Python... :-) )




So using indentation as part of the syntax makes programs easier to read
and eliminates an entire class of programming errors.


Regards
nordi


[1] http://www.ferg.org/papers/debugging_in_python.html




- --
==============================================================================
I have always wished that my computer would be as easy to use as my
telephone.
My wish has come true. I no longer know how to use my telephone.

Bjarne Stroustrup
==============================================================================
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAko3bkkACgkQasN0sSnLmgIDTgCfVzSjomWOQy6YOx7Zh1IQa5rC
hvsAoIglmxvlh0vZINzGEfwXQICu6b6F
=HzmW
-----END PGP SIGNATURE-----
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups