Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Spaces vs Tabs

by Tanktalus (Canon)
on Jun 16, 2017 at 14:14 UTC ( [id://1192940]=perlmeditation: print w/replies, xml ) Need Help??

Do you use spaces or tabs in your code for indentation?

Apparently, StackOverflow says you get paid better for spaces than tabs!

(I'm not sure whether to take this seriously or not, or, if serious, how much salt to consume simultaneously...)

Me, I just let my editor do my indenting for me, and it produces spaces, so I'm good. :)

Replies are listed 'Best First'.
Re: Spaces vs Tabs
by shmem (Chancellor) on Jun 16, 2017 at 15:30 UTC
    Apparently, StackOverflow says you get paid better for spaces than tabs!

    This interpretation of statistical data looks like some sort of post hoc ergo propter hoc fallacy to me.

    More experienced and better programmers get better pay, and they surely have seen lots of source code with messed up indentation, so they use spaces.

    For instance, one schmock does set tabstop=4 in vi, the next goes WTF?? and is told to set ts=4 to get the intended (indented :-) view, but has set expandtab in their .vimrc, edit, save. The next one pages the file with less(1) and seriously goes WTF.

    I use spaces, except where tabs are mandatory. There are a couple of config file formats which absolutely demand tabs.

    More chars in the source file, more volume, better pay :-P

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      Yes, I think someone went on a fishing expedition. I wonder if space-use correlates with online-forum-use? It's irritating when your posts get tabdamaged.
Re: Spaces vs Tabs
by tybalt89 (Monsignor) on Jun 16, 2017 at 16:34 UTC

    Since I'm retired and no longer get paid for code, I use tabs because they take less disk space (snicker).

    Then for pasting to perlmonks I have the following line in my .vimrc (vim forever!)

    nnoremap QQ :w !expand -2 \| (echo \<code\>; cat -; echo \</code\>) \| + xclip<CR>

    which converts tabs to spaces and wraps the whole program in a code block and sticks it in the clipboard for immediate pasting.

Re: Spaces vs Tabs
by LanX (Saint) on Jun 16, 2017 at 14:19 UTC
    > Me, I just let my editor do my indenting for me, and it produces spaces, so I'm good. :)

    Yes auto-indenting is a bliss ... but even better if your editor knows how to back-delete spaces till the former tab stop.

    update

    See also emacs M-x untabify changes all tabs in the region to appropriate numbers of spaces.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re: Spaces vs Tabs
by SuicideJunkie (Vicar) on Jun 16, 2017 at 15:01 UTC

    The idea that you can only choose one is the root of the problem, IMO.

    Tabs are indentation, spaces are alignment. Then you can set your tab width to anything and it all works.

    If tab stops could be globally set at PI spaces wide, then this would be obvious.

    In the end, you just go with the flow and clone whatever style is already there to get money.

      The idea that you can only choose one is the root of the problem, IMO.

      I'd say that the root of the problem is unfamiliarity with old typewriters, and the fact that the convention of tab stops defaulting to 8 spaces can so easily be overridden in the wrong way, yielding disastrous results.

      Tabs are indentation, spaces are alignment.

      The other way round that is. On the old typewriters, you could set stops for alignment of data skipping thus a fixed amount of spaces, mainly for filling out tables; whereas the indentation in typesetting e.g. at the beginning of a paragraph was done with spaces.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: Spaces vs Tabs
by zentara (Archbishop) on Jun 16, 2017 at 15:32 UTC
    get paid more for spaces than tabs

    It makes sense, since the technocrats probably analyze code by how much actual text-code there is. Since a space is actually holds a character space, your code's character count is higher with spaces.

    What peeves me is the little useless dots many editors insert into spaces to show they are not used.


    I'm not really a human, but I play one on earth. ..... an animated JAPH
      I think I always used tabs, but seems that my primitive editor of choice convert them into 2 (?!) spaces.

      Anyway I'll pass all my codebase through  perl -i.bak -e "s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e" and monday I'll ask my boss for more money.. ;=)

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        Don't sell yourself short - go for 32 instead of 8. Have to justify that widescreen monitor somehow.

Re: Spaces vs Tabs
by oiskuu (Hermit) on Jun 16, 2017 at 21:05 UTC

    Autoindent and tabs. I have learnt to keep it simple and mechanical. "Smart" editor mode did not work for me; the logic goes:

    • Text alignment is separate from indentation. E.g. a char table[] definition, where you put spaces before the small numbers to make the columns align. The editor does not know where indentation ends and whitespace starts.
    • The "smart" editor makes mistakes. Having to guess what happens if I hit that Backspace key amounts to an unacceptable cognitive load / annoyance.
    • My fingers find Tab and Backspace easily, I'll never use any other keys to change indentation.
    • Manual indent changes are effortless and "automatic". Somehow being assertive and in control goes well with the flow of thought.
    • Consequently, I encode indent level as tabs in the source files.

    Of course, using tabs is not mandatory, but to sum this up:

    People who do not know of indentation character are bound to reinvent it.

    ps. Oh by the way, should you want to increment the troll-level, the next question to ask is if one uses braces for scoping.

    pps. Curiously, Unicode has a number of space characters, but none wider that 1 em...

Re: Spaces vs Tabs
by talexb (Chancellor) on Jun 19, 2017 at 15:21 UTC

    Ugh .. this debate has been going on for decades. To me, it was just something to generate traffic .. aka "Someone is wrong on the Internet!" Tie it to "Who gets paid better?", and you've got a burst of traffic for a week.

    Meh.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      Indeed. I hear talk that in order to combat the Black Friday audience drop-off of the last few years, they are planning a two-for-one special: "Vi .vs. Emacs: Who has the biggest cahonies" & "Windows .vs. Linux: Who spends more time maintaining their OS, than coding", in-depth exposés :)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

        Now this made coffee come out of my nose! ...and I was drinking water!

        It's the "cahonies" that really sell the joke. :-)

        Just another Perl hooker - But the purist monks keep telling me I should do it for love, not money.
Re: Spaces vs Tabs
by Tux (Canon) on Jun 16, 2017 at 21:19 UTC

    Why or??? Don't discriminate! MIXED! Of course. MIXED! (TIMTOWTDI)


    Enjoy, Have FUN! H.Merijn
Re: Spaces vs Tabs
by sundialsvc4 (Abbot) on Jun 19, 2017 at 22:41 UTC

    This is why I continue to write all of my code on an Apple ][!! Its 40-column uppercase-only screen ensures that I can fill up the same amount of square-footage using only half as many characters, thereby doubling the amount that I get paid!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://1192940]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found