indentation

S

Steven D'Aprano

If I type *hypothetical* code for a post, *I* have to
type all the spaces, and I often use 2 per indent level. If I type in
IDLE, *it* adds the spaces (4 per indent) automatically.

But of course you would never post code without testing it first, right?
That would an Abomination Unto Nuggan.

*wink*
 
J

J. Clifford Dyer

How about PEP 8? It's not even hidden deep in the bowels of the PEP --
it's almost at the top.
http://www.python.org/dev/peps/pep-0008/

"For really old code that you don't want to mess up, you can continue to
use 8-space tabs."

Fair, but limited to old code, so doesn't apply to instructions for new
code.
Then there's string.expandtabs():

expandtabs(...)
S.expandtabs([tabsize]) -> string

Return a copy of S where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.

The default for a tab does not imply anything about how python code
should be indented.
Here's Jamie Zawinski:
http://www.jwz.org/doc/tabs-vs-spaces.html

"On defaultly-configured Unix systems, and on ancient dumb terminals and
teletypes, the tradition has been for the TAB character to mean ``move to
the right until the current column is a multiple of 8.'' (As it happens,
this is how Netscape interprets TAB inside <PRE> as well.) This is also
the default in the two most popular Unix editors, Emacs and vi."

Again, refers to the interpretation of a tab, rather than indentation
conventions.
This page is a little old (2002), but it states that the standards for
OpenBSD and Linux (presumably the kernels) are 8 space indents:

http://xarg.net/writing/tabs

Not python. I think when Bruno says it's *the* standard, we can assume
he means "for python."
Here's a style guide that recommends 2, 3 or 4 space indents:

http://www.cs.bris.ac.uk/Teaching/Resources/COMS12100/style/

Again, it's for java and C, not python.
And of course, whenever there's a difference of opinion, we can turn to
the ultimate source of all knowledge: Googlefight! *wink*

http://www.googlefight.com/index.php?lang=en_GB&word1=tab+8
+spaces&word2=tab+4+spaces
Nearly 50 million hits for "tab 8 spaces" versus a piddly 762 thousand
hits for "tab 4 spaces".

And I still don't care how many spaces are in a tab. ;D

Cheers,
Cliff
 
R

Ross Ridge

Terry Reedy said:
Yes there is. If I type *hypothetical* code for a post, *I* have to
type all the spaces, and I often use 2 per indent level. If I type in
IDLE, *it* adds the spaces (4 per indent) automatically.

Hmm... I have doubt then how much it really can be *the* standard if
it's only being followed it when it's convenient.

Ross Ridge
 
L

Lawrence D'Oliveiro

In message
every time I switch editor all the script indentation get mixed up ...

Mixed up in what way? Are you configuring your editors to do automatic
space/tab conversion in inconsistent ways?
 
S

Steven D'Aprano

Fair, but limited to old code, so doesn't apply to instructions for new
code.

I didn't say it does. But it's a standard, one of many.

Then there's string.expandtabs():

expandtabs(...)
S.expandtabs([tabsize]) -> string

Return a copy of S where all tab characters are expanded using
spaces. If tabsize is not given, a tab size of 8 characters is
assumed.
The default for a tab does not imply anything about how python code
should be indented.

But it implies that 8 spaces is a standard.


[snip]
Not python. I think when Bruno says it's *the* standard, we can assume
he means "for python."

When you make an assumption, you make an ASS out of U and MPTION.

*wink*

I didn't think my post was terribly difficult to understand or that it
would be so controversial. It is a simple objective fact that there is no
such "THE" standard, not even for Python. Certainly it is true that 4-
space indents is a very common standard, and that it is recommended by
Guido and required for the standard library, but it is not the only
standard, not even for Python code.

I managed to avoid all the tedious arguments about which braces style
(for C programmers) or BEGIN/END positioning (for Pascal programmers) was
"THE" standard. I would have hoped that in the 21st century we'd got past
that nonsense. By all means argue that interoperability with others is
generally a good thing, and 4-space indents is sufficiently common that
it maximizes your ability to interoperate. You won't get any arguments
from me. (That's why I use 4-space indents, even though they are an
Abomination Unto Nuggan.)

But let's not pretend that Windows is "THE" standard operating system,
vanilla "THE" standard ice cream flavour, and 4-spaces "THE" standard for
indents. If interoperability is not important to you, go right ahead and
use any standard you like, or even pick something non-standard like 17-
space indents. There's no Indent Police who will arrest you for failing
to live up to the standard.
 
L

Lawrence D'Oliveiro

Steven D'Aprano said:
Here's Jamie Zawinski:
http://www.jwz.org/doc/tabs-vs-spaces.html

"On defaultly-configured Unix systems, and on ancient dumb terminals and
teletypes, the tradition has been for the TAB character to mean ``move to
the right until the current column is a multiple of 8.''

Actually, I think that should be "multiple of 8 plus 1". If you're in column
1, pressing tab will move the equivalent of 8 spaces, which takes you
column 9, not 8.
 
T

Terry Reedy

Steven said:
But of course you would never post code without testing it first, right?
That would an Abomination Unto Nuggan.

*wink*

I have learned at least three times to either test or specify
*untested*, except when testing is impossible, as when discussing
unimplemented syntax or answering questions based on unposted input. I
have learned much from posting *tested* code snippets.
 
B

Bruno Desthuilliers

GHUM a écrit :
(snip)

Thus spake the Lord: Thou shalt indent with four spaces. No more, no
less.
Four shall be the number of spaces thou shalt indent, and the number
of thy
indenting shall be four. Eight shalt thou not indent, nor either
indent thou
two, excepting that thou then proceed to four. Tabs are right out.

+4 qotw !-)
 
M

Marc 'BlackJack' Rintsch

Actually, I think that should be "multiple of 8 plus 1". If you're in
column 1, pressing tab will move the equivalent of 8 spaces, which takes
you column 9, not 8.

Ever noticed that computer freaks often start counting at 0? ;-)

Ciao,
Marc 'BlackJack' Rintsch
 
G

Glenn Linderman

Derek Martin:
I know of several people who favor the idea of "indent with tab, align
with space." [...] I favor this myself actually, [...]

Thanks Guido, in Python3 this is finally a Syntax Error (I have asked
for this probably about three years ago).

What has changed with respect to white space? via what PEP #?
Unfortunately the new Python-syntax-based Delight language starts with
a half-bad foot regarding indents:
http://delight.sourceforge.net/syntax.html

ick. As recommended on the epage, I won't be trying the Delight language.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top