Forum :: Mods :: Tabs are wrong! Use 4 spaces :)

Sign In

You must sign in to post.

Tabs are wrong! Use 4 spaces :) :: Jun 26, 2007 @ 4:43pm
Ensign philhassey
Joined: Nov 30, 2006
Posts: 671
Location: Zarcon
Hey,

Just a quick tip to modders - set up your text editor to put in 4 spaces instead of tabs, and convert all your tabs into spaces.

See the the python style guide.  Not all set in stone, but the 4 space one is pretty well.

This makes editing a lot easier - especially because if you accidentally mix tabs and spaces - weird things can happen.  So if you stick with all spaces, things go as planned.

- Phil
4 spaces are wrong! Use tabs :P :: Jun 26, 2007 @ 5:29pm
Ensign thirdparty
Joined: Dec 20, 2006
Posts: 279
Location: Eastern U.S.A.
I don't know how to set my text editor to type four spaces when I hit the tab key.  But even if I did know how, I wouldn't do it.

1 - If you use spaces instead of tabs, it takes four backspace keystrokes to delete one, and four cursor keystrokes to move past one.  Requiring extra keystrokes is bad.

2 - If you use spaces instead of tabs, there's a danger of accidentally selecting partial ones, resulting in subtly mis-aligned code after a cut or paste.  Creating new ways to make mistakes is bad.

3 - If you use spaces instead of tabs, then when the computer looks for the text "[space]foo", it will also find instances of "[space][space][space][space]foo"; worse, when it looks for the text "[space][space][space][space]", it'll catch not only actually identations but also strings involving part of one identation and part of another.  In short, using multiple numbers of one character to mean something completely different is bad.

4 - If you use spaces instead of tabs, then when you tell your text editor to change the identation alignment, nothing will happen.  Having nothing happen when you tell the computer to do something is bad.

If y'all really want, I'll run detab commands on my code before releasing it.  But that's all I can offer.
Re: Tabs are wrong! Use 4 spaces :) :: Jun 26, 2007 @ 7:42pm
Ensign philhassey
Joined: Nov 30, 2006
Posts: 671
Location: Zarcon
Hehe - well, as long as you *only* use tabs, and never mix by accident, then whatever :)  If I ever use a few lines from your code I'll be sure to run it through my de-tab script though ;)

Phil
Re: 4 spaces are wrong! Use tabs :P :: Aug 6, 2007 @ 5:01pm
1 Stripe Admiral felix-rabe
Joined: Jun 13, 2007
Posts: 55
Location: Switzerland
I probably won't do any Galcon-related programming anytime soon, so you can consider me "out-of-community" in that regard.

I have to say that conventions like the Python coding guidelines exist for a reason: for situations like these, they avoid having those endless conversations where everybody has their strong opinion and good arguments exist for both sides.

I personally indent using four spaces, following the spec.  I still have to (re)read it thoroughly though, as I know my style differs in some minor ways from it and I better adapt to what the rest of the world does instead of following my own ideals that just make my code look strange in other's eyes.

1 - If you use spaces instead of tabs, it takes four backspace keystrokes to delete one, and four cursor keystrokes to move past one.  Requiring extra keystrokes is bad.

I never have to.  I use GEdit with the indentation plugin - with Ctrl-T I indent, with Shift-Ctrl-T I dedent / outdent / unindent / mentadent (jk).

If I were evaluating editors to replace GEdit as my programming horse, missing this kind of feature would make me not look at it a second time.

2 - If you use spaces instead of tabs, there's a danger of accidentally selecting partial ones, resulting in subtly mis-aligned code after a cut or paste.  Creating new ways to make mistakes is bad.

If I ever copy & paste over multiple lines, I drag the mouse on the right side of the code, from one "end of paragraph" (whatever that could be, e.g. a whole class) to the other.  I normally don't select starting / ending in the middle of lines in this case.

This is a personal decision of how I select multiple lines that I took only few years ago, and I never had trouble when doing it that way.

Also I'm fast enough writing code that, in those cases where I still misalign something, my perfectionism that makes me align code properly doesn't slow me down.

3 - If you use spaces instead of tabs, then when the computer looks for the text "[space]foo", it will also find instances of "[space][space][space][space]foo"; worse, when it looks for the text "[space][space][space][space]", it'll catch not only actually identations but also strings involving part of one identation and part of another.  In short, using multiple numbers of one character to mean something completely different is bad.

First part - if I ever look for "[space]foo", I know what I'm doing and I take into account it might involve indentation.  I almost always do interactive search (and replace) operations, be it with GEdit or with grep (as used from the quick&dirty command line, not from a fine-tuned script).

Second part - I just indent / dedent using keystrokes.  I can't think of a reason why I'd have to search for indentation.

Last part - I guess the Tabulator character is still the most non-portable character in all currently existing character encodings, including Unicode.  Better just use four spaces and What You Type Is What You Get.

4 - If you use spaces instead of tabs, then when you tell your text editor to change the identation alignment, nothing will happen.  Having nothing happen when you tell the computer to do something is bad.

In this regard, actually the opposite is true.  I have spaces-aligned my code neatly and then know it won't just shuffle around by means of some editor settings.  I'm also quite strict about keeping my code below a certain character limit per line.  Having indentation grow is not what I'd want here.

I have GEdit set to an indentation level of four spaces, since I almost always just write Python code with it.  Now there comes that piece of code along where a tab means eight spaces - and almost all those pieces of code had spaces here and there as well (or the other way round - I think I found more spaces-only-indented code than tab-only).  So I go to the Preferences dialog and switch to eight spaces.  Problem with GEdit: it's a tabbed MDI - this preference is global.  So when I'm using that code as a reference for writing some code on my own, I have to switch that setting back and forth all the time I work on / look at a different document.  I got so fed up with this on first sight that I sat down and wrote a dirty plugin hack for GEdit just to have a button in the toolbar that toggles between both indentation levels by means of GConf.

If y'all really want, I'll run detab commands on my code before releasing it.  But that's all I can offer.

Please do.
post updated on Aug 6, 2007 @ 5:10pm

You must sign in to post.

Galcon   Watermelons   Dynamite   The Hairy Chestival
All content of imitation pickles (c) 1999-2008 - Phil Hassey  "we care"