Python indentation deters newbies?

B

beliavsky

One of the most commmon reasons programmers cite for not trying Python
is that indentation determines the program flow -- they think its
weird. I think programmers who actually try Python adapt quickly and
do not find the indentation rules to be a problem.

I wonder if there is a way to remove this initial barrier. Could an
alternate source form be defined, so that there are matching if-endif
and for-next constructs instead of significant indentation? The
alternate source form and the current form would result in exactly the
same .pyc file.

I'm not saying that Python's use of indentation is bad, just that it
stops many programmers from trying it.
 
G

Grant Edwards

One of the most commmon reasons programmers cite for not
trying Python is that indentation determines the program flow
-- they think its weird.

True. I thought it was weird when I read about it. I'm not so
closed-minded that it prevented me from trying the language.
I think programmers who actually try Python adapt quickly and
do not find the indentation rules to be a problem.

I wonder if there is a way to remove this initial barrier. Could an
alternate source form be defined,

Please no!!! If you want a different language _use_ a different
language. Don't mangle Python into something else.
so that there are matching if-endif and for-next constructs
instead of significant indentation? The alternate source form
and the current form would result in exactly the same .pyc
file.

Sounds horrible.
I'm not saying that Python's use of indentation is bad, just
that it stops many programmers from trying it.

Oh well.
 
P

Peter Hansen

One of the most commmon reasons programmers cite for not trying Python
is that indentation determines the program flow -- they think its
weird. I think programmers who actually try Python adapt quickly and
do not find the indentation rules to be a problem.

I think you're right on both counts. For me, the adaptation
period was roughly ten seconds...
I wonder if there is a way to remove this initial barrier.

Why? Is there really any evidence that the Python community
is missing a large number of really excellent programmers merely
because they are resistant to the idea of syntactically significant
indentation? Yes, it's one of the most common reasons programmers
cite as you note above, but in absolute terms I doubt it's that
significant.
I'm not saying that Python's use of indentation is bad, just that it
stops many programmers from trying it.

I really question whether we are looking for such programmers.
They sound rather close minded and perhaps even lazy...

-Peter
 
S

Skip Montanaro

beliavsky> I wonder if there is a way to remove this initial
beliavsky> barrier. Could an alternate source form be defined, so that
beliavsky> there are matching if-endif and for-next constructs instead
beliavsky> of significant indentation?

Look at Tools/scripts/pindent.py in the standard distribution. Run it as a
preprocessor over your code before running it.

Skip
 
D

Dave Brueck

One of the most commmon reasons programmers cite for not trying Python
is that indentation determines the program flow -- they think its
weird.

Yes, that is commonly cited. From the programmer's perspective,
indentation implies program flow in nearly *all* modern languages. The
difference is that in Python the compiler believes you.
I think programmers who actually try Python adapt quickly and
do not find the indentation rules to be a problem.
Yep!

I wonder if there is a way to remove this initial barrier.

I sure hope not... if someone can't accept that there might be value in
it being different than what they're used to (so much so that they're
unwilling even to give it a try), then the indentation is only the first
of many things that will give them problems.

In that sense it's really useful - maybe it weeds out people who
wouldn't be happy in Python yet anyway <0.5 wink>.

-Dave
 
D

Dennis Lee Bieber

One of the most commmon reasons programmers cite for not trying Python
is that indentation determines the program flow -- they think its
weird. I think programmers who actually try Python adapt quickly and
do not find the indentation rules to be a problem.
Teach them FORTRAN-IV...

A source line is limited to 80 characters
Statements start in column 7
Statements end in column 72 (or was it 71)
Columns 73 (72) through 80 can be used for an option sequence
number
If a statement is too long for one line, you put a continuation
mark character (any character can be used) in column 6 of the next line,
then continue with the statement
Put a "C" in column 1 to start a comment line
The target of GOTO, IF, and DO loops is identified by a numeric
label.
Labels are up to 5 digits long, located in columns 1 to 5

Oh, and within a statement, white space is ignored -- the
following are the same statement:

circum = 2.0 * radius * PI
c irc um=2 . 0*r ad i u s*P I

And one the following is an assignment, the other is the
beginning of a DO loop:

do 10 i = 3. 14159
do10i = 3,14159



After you give them the above, ask them if they really think
having to line up blocks of code to reflect the structure of the logic
is really that difficult? <G>

--
 
R

Roy Smith

Dennis Lee Bieber said:
Teach them FORTRAN-IV...

A source line is limited to 80 characters
Statements start in column 7
Statements end in column 72 (or was it 71)
Columns 73 (72) through 80 can be used for an option sequence
number
If a statement is too long for one line, you put a continuation
mark character (any character can be used) in column 6 of the next line,
then continue with the statement
Put a "C" in column 1 to start a comment line

In some versions, a "D" in column 1 indicated a debug line, which was
conditionally included depending on some external compile flag.

But, you have to remember that in those days, CPU time was an expensive
and scarce resource, and languages were designed to be easy for the
computer to process. The thought of making the machine do something
that a person could do themselves was absurd.
 
A

Anthony Baxter

One of the most commmon reasons programmers cite for not trying Python
is that indentation determines the program flow -- they think its
weird. I think programmers who actually try Python adapt quickly and
do not find the indentation rules to be a problem.

I wonder if there is a way to remove this initial barrier. Could an
alternate source form be defined, so that there are matching if-endif
and for-next constructs instead of significant indentation? The
alternate source form and the current form would result in exactly the
same .pyc file.

Luckily, the time machine has already been used to implement this.
At the end of an 'if' statement, you can put a "#endif". And in a for
loop, you can put a "#endfor" at the end. The '#' is to indicate that it's
not the preferred form.

In all seriousness - people who bounce off Python because of the
indentation are probably just not willing to learn a new language, or
else they're incredibly bigoted towards whatever language (often
C) that they're used to. Their loss.
 
C

CptPicard

Peter Hansen said:
I think you're right on both counts. For me, the adaptation
period was roughly ten seconds...


Why? Is there really any evidence that the Python community
is missing a large number of really excellent programmers merely
because they are resistant to the idea of syntactically significant
indentation? Yes, it's one of the most common reasons programmers
cite as you note above, but in absolute terms I doubt it's that
significant.

That's true.
As the question is formulated, I don't think that a programmer will be
stopped by the indentation syntax. There are so many languages with very
strange syntax : we adopt them because they are efficient in what they are
doing and are adaptated to our problems.
But on a first approach, if you know that several languages could fix your
problem, you may tend to choose the one you prefer regarding several
criteria like ... syntax.
And for me, the problem could be here: on a quick analysis, people may
prefer Perl to Python (for example ;-) ) just because it looks like that
they are doing the same thing and Perl syntax may look more appealing (not
talking about regular expressions here). And once you are engaged in
learning a language, you tend to think twice before learning another one.
And the main question becomes : what Python will bring to me so that I stop
working on my current language and learn about Python ?
So I don't think that it is a problem of laziness or of being closed minded.

Note: I assume here that people have the choice to choose their programming
languages.

I noticed too that, amazingly, a lot of programmers know about Perl but not
Python.
 
A

Anthony Baxter

I noticed too that, amazingly, a lot of programmers know about Perl but not
Python.

A hell of a lot of the Perl programmers I know have never really programmed
in anything else in the same area. If my choices were Perl, Pascal, or C, I'd
probably choose Perl, too. Indeed, I did, for a while. "I chose
something else".

Anthony
 
M

Mark Jackson

Dave Brueck said:
Yes, that is commonly cited. From the programmer's perspective,
indentation implies program flow in nearly *all* modern languages. The
difference is that in Python the compiler believes you.


I sure hope not... if someone can't accept that there might be value in
it being different than what they're used to (so much so that they're
unwilling even to give it a try), then the indentation is only the first
of many things that will give them problems.

In that sense it's really useful - maybe it weeds out people who
wouldn't be happy in Python yet anyway <0.5 wink>.

To this end, it's worth remembering that Eric Raymond has described
indentation-based blocking as Python's /pons asinorum/:
http://www.linuxjournal.com/article.php?sid=3882
 
E

Ed Suominen

Dave said:
Yes, that is commonly cited. From the programmer's perspective,
indentation implies program flow in nearly *all* modern languages. The
difference is that in Python the compiler believes you.


Yep!

Exactly true in my case:

Day 1: "Wow, that's weird, but I guess I'll give it a try."
Day 2: "Hey, this is cool, and the code looks a LOT cleaner without all of
those braces strewn around."
Day 3: "Of COURSE whitespace is part of the code. It's part of the source
file, duh!"
 
X

Xavier Combelle

I'm not saying that Python's use of indentation is bad, just that it
I really question whether we are looking for such programmers.
They sound rather close minded and perhaps even lazy...

Laziness is maybe not a reason to not use Python. I choose
python because I am lazy: the absence of useless braquets is the best
gift python gived to me. As a C programmer, I am dreaming of a tool
that allow me to use the indentation syntax to write C programms.
I would feel my self so much efficient.
 
T

Thomas Bartkus

> One of the most commmon reasons programmers cite for not trying Python
> is that indentation determines the program flow -- they think its
> weird.
> I wonder if there is a way to remove this initial barrier.

Why? Do we you really want to let just *anyone* in :)

When I explain this about Python and I start hearing that flak, I simply
agree and suggest that Python is not for you.

Some people should be *forbidden* to move outside of java or VB :)
Thomas Bartkus
 
J

John Roth

I noticed too that, amazingly, a lot of programmers know about Perl but not
Python.

Perl has about four times the market penetration of Python. A whole
lot of people regard it as "the language" for system administration.

As far as percieved barriers to adoption, though, I think "there
should be one obvious way to do it" turns a lot of people off
when it's compared to Perl's "there's more than one way to do it."
Again, though, it just takes some familiarization.

John Roth
 
T

Terry Reedy

One of the most commmon reasons programmers cite for not trying Python

I suspect that the main barrier is hearing or reading enough about Python
to serious think about trying it.
is that indentation determines the program flow -- they think its weird.

Giving that structured text (in English at least) routinely uses
significant indentation (lists, outlines, block quotes) and that much
algorithm pseudocode does the same (which was half the reason I called
Python 'executable pseudocode'), I find it puzzling that so many find it
'weird' (if indeed that is true).
I wonder if there is a way to remove this initial barrier.

Perhaps better explanation in the introductory materials might help. Do
you have any suggestions?
Could an alternate source form be defined,

'Could' ? of course. And you are free to do so, and to write a
preprocessor that converts the alternate form to standard Python, and even
to distribute an intepreter that has it builtin, and even to promote
FencePy as a 'Python variant for beginners' or as 'Transitional Python for
the fence-bound'.
so that there are matching if-endif
and for-next constructs instead of significant indentation?

If a block is too long to easily match indentation levels, I myself might
add an unofficial '#end if xyz' (properly dedented) to help readers
(including possibly myself in the future) visually and mentally close the
block. The downside though is to make editing possibly slightly harder.
The alternate source form and the current form would result in exactly the
same .pyc file.

What if the fences and indentation disagreed?
I'm not saying that Python's use of indentation is bad,

I say that Python's use of indentation is good.
just that it stops many programmers from trying it.

Perhaps. But it encourages others to try and adopt it and it is a key part
of making Python code unusually readable, which was and is one of its main
design goals.

Terry J. Reedy
 
J

Jarek Zgoda

Thomas Bartkus said:
Why? Do we you really want to let just *anyone* in :)

When I explain this about Python and I start hearing that flak, I simply
agree and suggest that Python is not for you.

Some people should be *forbidden* to move outside of java or VB :)

Most of newly-addicted to Python says that forced intendation is
something that makes Python programs easier to read and understand.

But you are right, some people should never go outside of (insert your
most hated programming language here, in my case ObjectPascal).
 
E

Erik Max Francis

Peter said:
I think you're right on both counts. For me, the adaptation
period was roughly ten seconds...

Particularly with emacs mode. I didn't have to worry about indentation;
my editor handled that for me.
 
S

simo

I'm a Perl programmer at heart - well that and PHP, plus the odd
dabbling in C/C++/C# etc.

Anyway, the thought of indentation instead of curly braces really put
me off to start with, but I tried it, and as soon as I started to
write larger programs, it became apparent what a good system it was,
plus it forces readable code on you (you wouldn't believe how many PHP
programmers I know who don't indent properly).

I find when using C# that you really need a big monitor/resolution and
an IDE to provide code-folding/split window/brace-matching etc;
otherwise you can't find your way around the source, not so with
Python - you just need a text editor that can do proper tabbing.

Now I write all my desktop apps in Python - I haven't really converted
from Perl/PHP for web stuff yet, as the Python DBI is confusing (or
confused?!) too many libraries, no standard.....
 
J

Jeffrey Froman

Terry said:
Giving that structured text (in English at least) routinely uses
significant indentation (lists, outlines, block quotes) and that much
algorithm pseudocode does the same (which was half the reason I called
Python 'executable pseudocode'), I find it puzzling that so many find it
'weird' (if indeed that is true).

Me too, and in fact I don't believe that the people who complain about it
really think it's weird either. It's just fashionable to dislike Python for
that reason. If using indentation for program flow is so non-intuitive,
then why do C programmers complain so much about other C programmers
indentation, and spend so much energy "cleaning up" indentation to fit
their own idea of how C code should look? I'd think since indentation was
so "insignificant" that any C coder would happily accept any indentation
style as their attention "naturally" separated significant elements between
curly braces. Clearly, this is not the case though.

Jeffrey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top