Indentation/whitespace

J

Joe

Is Python going to support s syntax the does not use it's infamous
whitespace rules? I recall reading that Python might include such a
feature. Or, maybe just a brace-to-indentation preprocessor would be
sufficient.

Many people think Python's syntax makes sense. There are strong
feelings both ways. It must depend on a person's way of thinking,
because I find it very confusing, even after using with Python for some
time, and trying to believe the advice that I would learn to like it.
The most annoying thing is that multiple dedents are very unreadable. I
still don't understand how anybody can think significant-but-invisible
dedentation is a good thing.

Note: No need to follow up with long opinions of why indentation is
good -- they have been posted hundreds of times. It just seems that
Python developers think the whitespace thing is only an issue for
newbies. I think that many experienced users don't learn to like it,
but instead just learn to live with it.
 
L

Larry Bates

Joe said:
Is Python going to support s syntax the does not use it's infamous
whitespace rules? I recall reading that Python might include such a
feature. Or, maybe just a brace-to-indentation preprocessor would be
sufficient.

Many people think Python's syntax makes sense. There are strong
feelings both ways. It must depend on a person's way of thinking,
because I find it very confusing, even after using with Python for some
time, and trying to believe the advice that I would learn to like it.
The most annoying thing is that multiple dedents are very unreadable. I
still don't understand how anybody can think significant-but-invisible
dedentation is a good thing.

Note: No need to follow up with long opinions of why indentation is
good -- they have been posted hundreds of times. It just seems that
Python developers think the whitespace thing is only an issue for
newbies. I think that many experienced users don't learn to like it,
but instead just learn to live with it.
Characterizing indentation as "invisible" isn't really fair.
It it WAY more visible than a { character. IMHO the
indentation works very well. I've tried to wade through PHP,
JavaScript, C code that uses those <expletive deleted>
brace ({}) blocks until my head hurt, especially if they
didn't indent as well as using the braces. If they indent
so I can actually read the code, why also use braces to
clutter things up? I've solved the multiple dedent problem
by inserting a comment that shows where the indented blocks
end (sort of where the ending brace (}) would have been.
I also find that if I'm indenting more than a couple of
levels, I probably need to refactor my code into smaller
objects or rethink the process so that I process collections
of objects. I've written in many different languages over
a span of 32+ years and it seems to work for me.

-Larry
 
A

Alex Martelli

Joe said:
Is Python going to support s syntax the does not use it's infamous
whitespace rules?

No, never (even apart from the "its" vs "it's" issue here...;-).
I recall reading that Python might include such a
feature.

And I recall reading that Elvis is still alive and was kidnapped by
aliens, but I don't necessarily believe all that I read.
Or, maybe just a brace-to-indentation preprocessor would be
sufficient.

Fine, then write one -- it's not too hard (about an average interview
question for hiring a programmer, I'd say). As for how to integrate
such a preprocessor with CPython, I would suggest you follow precedent
by allowing an arbitrary "source-code-reading hook" to be optionally
specified by setting sys.preprocessor (and/or via commandline flag,
environment variable, etc -- but, the ability to install the hook from
site-configure.py would probably be sufficient).

You could maybe get 99% of the way there by using the existing "import
hooks" mechanism (the same one that lets you import from zipfiles: it's
designed to be easily extensible), but I don't think that would help
with the "main script" (which doesn't get imported), interactive
interpreter sessions, etc; also, I'm not sure it would easily allow
seamless interoperation with other such hooks (e.g., to let you import
from zipfiles sources that need to be preprocessed).

The main reason I suggest a general-purpose mechanism for the hooking-up
of the preprocessor is that such a mechanism might stand a chance to be
accepted (via the usual PEP procedure), as long as other interesting use
cases can be found; I suspect that if the only use case was "turn braces
into indents/dedents", the PEP would stand no chance.

For example, a small but vocal minority has long campaigned for
non-ASCII characters to be allowed in identifiers; a preprocessor might
be able to do this by translating them into ASCII on the fly (though
that wouldn't necessarily work well with getattr and friends... but
then, neither do 'private' identifiers starting with two underscores;-).
still don't understand how anybody can think significant-but-invisible
dedentation is a good thing.

We're even, then, since I can't understand the reverse;-).
Note: No need to follow up with long opinions of why indentation is
good -- they have been posted hundreds of times. It just seems that

Respecting your wish, I'm not discussing the issue at all (although, by
trying to make some point AGAINST it, you really make it very hard: if
you don't want such a discussion you shouldn't start one yourself and
then try to impede your opponents from rebutting your points, that is
really an extremely unfair attempt on your part). I'm pointing you to
ways you might get your wish, if you're willing to do some work for the
purpose. Coding the preprocessor is the easy part -- the work is mostly
in doing the PEP, including a variety of strong use cases for a general
purpose preprocessor. (Of course, forking Python to hardcode your
preprocessor is easier, but forking always has other problems).


Alex
 
D

Dave Benjamin

Alex said:
The main reason I suggest a general-purpose mechanism for the hooking-up
of the preprocessor is that such a mechanism might stand a chance to be
accepted (via the usual PEP procedure), as long as other interesting use
cases can be found; I suspect that if the only use case was "turn braces
into indents/dedents", the PEP would stand no chance.

+1 on the preprocessor idea, especially if it would allow us to hook in
at the AST level as well. (No comment on the curlies. ;)

Dave
 
T

Thomas Bartkus

Joe said:
Is Python going to support s syntax the does not use it's infamous
whitespace rules? I recall reading that Python might include such a
feature. Or, maybe just a brace-to-indentation preprocessor would be
sufficient.

Many people think Python's syntax makes sense. There are strong
feelings both ways. It must depend on a person's way of thinking,
because I find it very confusing, even after using with Python for some
time, and trying to believe the advice that I would learn to like it.
The most annoying thing is that multiple dedents are very unreadable. I
still don't understand how anybody can think significant-but-invisible
dedentation is a good thing.

Note: No need to follow up with long opinions of why indentation is
good -- they have been posted hundreds of times. It just seems that
Python developers think the whitespace thing is only an issue for
newbies. I think that many experienced users don't learn to like it,
but instead just learn to live with it.

Okay - I'll take your note and not argue about "why indentation is good"

But - why should Python
"support s syntax the does not use it's infamous whitespace rules"
It's unique to Python. That's what Python *is*.

If one doesn't like it, one needn't waste one's time with it. No other
other language abides by those rules except Python.

So just choose a different language to work with.
Thomas Bartkus
 
T

Terry Hancock

+1 on the preprocessor idea, especially if it would allow
us to hook in at the AST level as well. (No comment on
the curlies. ;)

Only +0 on it myself, but I do know of a use-case -- certain
types of web-templating frameworks can be easier to use if
the inserted code can be put on one line.

Some people have been agitating for some way to do this with
Python for some time (on Zope lists), and a preprocessor
would provide a means for them to get what they want.

OTOH, I have been able to manage with the way things are. It
encourages good separation between templates and code, which
is supposed to be a good thing according to the "Zope Zen".
;-)
 
J

James Tanis

It just seems that
Python developers think the whitespace thing is only an issue for
newbies. I think that many experienced users don't learn to like it,
but instead just learn to live with it.

I disagree, I don't think you can be an experienced python programmer
and not be comfortable with its syntax. On the other hand you *can* be
an experienced programmer, but that's not the same thing. I don't care
how much code you've written in Python, if your not comfortable with
the syntax then you clearly don't use it with enough consistency to
bring yourself to that point where you "own" it. There's nothing wrong
with that, for whatever reason, maybe Python isn't for you.. but
certainly don't blame it on something as small as significant
indention, because we've all been there and its just not that hard to
make the change. There are quite a few good high-level languages out
there these days. This may be out of place, but I'd suggest checking
out Ruby if you want something as powerful and "fun" to code in as
Python but with more Perl-like syntax. It doesn't quite have as much
of a diverse module selection as Python and Perl but that will change
with time. Open source gives us an unprecendented amount of choices,
try them all out.. I have, and I came up with Python because for me it
is the "best fit." That may not be true in your case, which is
perfectly fine.
 
T

thakadu

It is not really unique to Python as I have pointed out on this or
other forums before. The Occam (OCCAM?) language also uses significant
whitespace in much the same way as Python and there may also be others.
 
R

rbt

BartlebyScrivener said:
What's needed is STRICTER whitespace enforcement, especially on April
Fools Day. Some call it whitespace fascism.

http://www.artima.com/weblogs/viewpost.jsp?thread=101968

I've only been coding Python for about 3 years now. C is the only other
language I'm moderately good with. Most of the people on
comp.lang.python have _much_ more coding experience than I do. I don't
know who came up with this PEP, but I like it a lot. To me, it makes
sense, just like Python makes sense. Any time-line on implementing this?
 
T

thakadu

I consider myself a fairly experienced Python coder and although I am
not "uncomfortable" with significant whitespace there are a few places
where I do find it annoying and I wouldnt mind an alternate block
delimitation syntax. I would prefer something like the ruby "end"
though rather than '{' and '}'. The place I find it annoying is in
pasting snippets of code from say web pages. I very often google for a
piece of code and then paste it into my editor and almost always the
pasted piece of code has different indentation and causes a compiler
error. Sometimes in vim "100==" fixes it but very often not. It would
be nice if you could use an "end" delimiter for quick experimentation
with code and then later on go and remove the "end" and fix the
indentation.
 
G

Gary Herron

Joe said:
Is Python going to support s syntax the does not use it's infamous
whitespace rules? I recall reading that Python might include such a
feature. Or, maybe just a brace-to-indentation preprocessor would be
sufficient.
Only over our dead bodies! ("our" = the large and
always growing Python
community.)
Many people think Python's syntax makes sense. There are strong
feelings both ways. It must depend on a person's way of thinking,
because I find it very confusing, even after using with Python for some
time, and trying to believe the advice that I would learn to like it.
The most annoying thing is that multiple dedents are very unreadable. I
still don't understand how anybody can think significant-but-invisible
dedentation is a good thing.
You've got the visible/invisible aspect of things
*exactly* backwards.
The point on a line of text where things change
from white space to
non-white space is *highly* visible. The several
pixels that represent a
{ or } are nearly invisible within a line of text.
(So one usually
compensates by putting them alone on a line,
making them somewhat more
visible.)

Try this experiment: Print out a page of C++ code,
tape it to the wall,
and start walking backwards. You will still be
able to discern the
structure of the code *long* after you can no
longer identify the
curly-braces. (Provided you properly indented you
C++ code -- you *do*
indent you C++ code don't you?)

Gary Herron
 
G

Gary Herron

rbt said:
BartlebyScrivener wrote:



I've only been coding Python for about 3 years now. C is the only other
language I'm moderately good with. Most of the people on
comp.lang.python have _much_ more coding experience than I do. I don't
know who came up with this PEP, but I like it a lot. To me, it makes
sense, just like Python makes sense. Any time-line on implementing this?
Look at the date. That was an April Fools joke.

Gary Herron
 
B

BartlebyScrivener

The PEP is not a joke. It's a sensible set of guidelines. The blog post
advocating enforcement is, shall we say, a sportive modest proposal?

rpd
www.dooling.com

"There is no human problem which could not be solved if people would
simply do as I advise."--Gore Vidal
 
S

Steven D'Aprano

It is not really unique to Python as I have pointed out on this or
other forums before. The Occam (OCCAM?) language also uses significant
whitespace in much the same way as Python and there may also be others.

Python doesn't have any more significant whitespace than any other
language:

x=12*sum([3,5,7,9,2][1:4])+3#comment

means the same thing as:

x = 12 * sum ( [ 3 , 5 , 7 , 9 , 2 ] [ 1 : 4 ] ) + 3 # comment

(although there are recommendations for where you should use whitespace).
You can mix spaces and tabs between tokens.

Like most computer languages, line breaks are significant in Python.
Nobody worries about that except maybe Forth programmers.

Also, *indentation* is significant, unlike most languages which treat
indentation as syntactically optional but enforce it via coding standards,
code beautifiers, pretty-printers, etc.
 
A

Alex Martelli

thakadu said:
It is not really unique to Python as I have pointed out on this or
other forums before. The Occam (OCCAM?) language also uses significant
whitespace in much the same way as Python and there may also be others.

Haskell. Rules not identical to Python (they have something called "the
offside rule" which is at least as subtle as the one in soccer;-) but
practical effects that are quite close.


Alex
 
J

James Tanis

It is not really unique to Python as I have pointed out on this or
other forums before. The Occam (OCCAM?) language also uses significant
whitespace in much the same way as Python and there may also be others.

Your right of course, but I don't think it really even needs to be
said. I mean whether or not Python is the only language that uses
white space in a significant manner doesn't change the fact that..
well Python can do whatever the heck Python wants to do with its
syntax. Honestly I wonder how so many coders actually came to be
interested in the field -- one that pretty much thrives in part on its
neverending ability to vary, grow, and change -- if something so small
can warrant so much attention.
 
B

bonono

James said:
Honestly I wonder how so many coders actually came to be
interested in the field -- one that pretty much thrives in part on its
neverending ability to vary, grow, and change -- if something so small
can warrant so much attention.
That is what a "cafe" type newsgroup is for, nothing but time killing
:)

For those who really cannot stand it, they would have moved on to
whatever other language that they feel better(or more tolerable in
whatever sense).
 
S

Steve Holden

thakadu said:
I consider myself a fairly experienced Python coder and although I am
not "uncomfortable" with significant whitespace there are a few places
where I do find it annoying and I wouldnt mind an alternate block
delimitation syntax. I would prefer something like the ruby "end"
though rather than '{' and '}'. [...]
Of course, therein lies the answer: the "I don't like indentation" crowd
should all be put in a room and not allowed out until they can all agree
on the best alternative.

regards
Steve
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top