[Tutor] improvements on a renaming script

Cameron Simpson cs at zip.com.au
Mon Mar 10 04:11:10 CET 2014


On 09Mar2014 22:50, bob gailer <bgailer at gmail.com> wrote:
> Beware using tabs as indents. As rendered by Thunderbird they appear
> as 8 spaces which is IMHO overkill.
> It is much better to use spaces. Most Python IDEs have an option to
> convert tabs to spaces.

Further to this remark, this isn't an instruction to not use the
TAB key. It is advice to get your editor to fill in the program
text with the necessary number of spaces instead of inserting a
literal TAB character. (But if you can't tell your editor to do
this, then avoid the TAB key; use the space bar.)

> The Python recommendation is 4; I use 2.

Me too. But not in code I give to other projects; there the rule
is "use their coding standard", and that is usually 4 spaces per
indent for Python projects.

As an example, I use vi/vim and have this in my config:

  set expandtab
  set shiftwidth=2
  set tabstop=8

The expandtab tells vim to insert spaces instead of a TAB character.

The shiftwidth reflects my 2 space indent preference.

The tabstop reflects the expectation that interpretation of the tab
keystroke and of any literal TABs in the text expects them to indicate
an 8-column TAB convention.

Note that many users set their tabstop equivalent to 4 or whatever
their preferrer indentation depth is. This is why it is some important
and useful to get your editor to insert spaces: whatever your
personal tabstop setting, the program text will be correctly rendered
for others because it will not contain TAB character, it will contain
spaces.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

Wirth's Law: Software is getting slower more rapidly than hardware
             becomes faster.


More information about the Tutor mailing list