Python indentation (3 spaces)
On 2018-10-08 20:13:38 +0000, Grant Edwards wrote:
> On 2018-10-08, Peter J. Holzer <hjp-python at hjp.at> wrote:
> > Theoretically I would agree with you: Just use a single tab per
> > indentation level and let the user decide whether that's displayed
> > as 2, 3, 4, or 8 spaces or 57 pixels or whatever.
> > In practice it doesn't work in my experience.
> Nor in mine. On problem is that under Unix is that there isn't just
> one place where you would need to configure the tab width. There are
> dozens of text-processing tools that get used on all sorts of text,
> including program sources in a variety of languages.
> For "just use tabs" to work, all of those tools would have to
> magically recognize that they're looking at Python source and adjust
> the tab size accordingly. That isn't going to happen.
Well, no. The idea of "just use tabs" isn't have a different tab width
per language, but a different tab width per user. So I - being a fan of
fixed-width fonts - would set the tab width to 5 spaces (just to pick a
somewhat unusual number), and Python, Perl, C, TypeScript, HTML, CSS,
etc. code containing tabs would be displayed and printed with that tab
width. You set your tab width to half an inch. And all your text files
are displayed and printed with that tab width. Gene uses 3 spaces, etc.
There aren't that many tools which would have to be configured. For me
that would be vim (the text editor), the tty driver and/or the terminal
emulator (not sure what the right place is), less (the pager), and paps
(for printing). Maybe a few others, but the vast majority of tools
doesn't care about the tab width. For them a tab is just a single byte.
The problem is in my experience that a "use only tabs" policy is hard to
enforce. People will type spaces when they should use tabs (and use tabs
when they should use spaces), their software will autoconvert between
spaces and tabs (with a different number of spaces per tab for each
user), etc. The result is an awful mess. "Use only spaces" is much
easier to enforce: Just reject any file (except binaries and makefiles)
with a 0x09 byte at commit time.
(Now that I think of it, "use tabs" might work better in Python than in
other languages because in Python indentation has syntactic meaning. If
your editor replaces some tabs with spaces or vice versa, your program
won't compile any more and you will (hopefully) fix it before committing
_ | Peter J. Holzer | we build much bigger, better disasters now
|_|_) | | because we have much more sophisticated
| | | hjp at hjp.at | management tools.
__/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 833 bytes
Desc: not available