Thread: Emit white spaces, when you hit tab. Why?

  1. #1
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694

    Emit white spaces, when you hit tab. Why?

    I read somewhere that I trust
    "You should set your editor to emit spaces when you hit the tab key. "
    But the resource doesn't explain why and I can not ask them!

    So..why?

    The only thing that comes to my mind is that when you want the code to be of minimum length, because you want to be used on the internet, like jQuery for example, then you parse the file and you remove all spaces. However, I think that this is not it, because how hard would it be to say to the program that removes the spaces, to remove tabs too.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Because if you open the program in any other editor, or send the file to someone else, your tabs will look stupid (since no one can ever agree on where the tabstops should be set).

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by tabstop View Post
    ..tabstops
    Thank you tabstop!
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Enjoy some reading on one of the greatest "religious wars" in computer history: https://www.google.com/search?q=tabs+vs+spaces. I'm sure it's even more contentious than the Emacs vs Vi war. Maybe more so than the old OS or browser debates. Probably wont top the cola wars though.

    I prefer spaces (4 of them) over tabs, but I much prefer "doing what the rest of the code does" to "enforcing my own 4-space indentation on a small part of the code, so it looks different than everything else and makes things hard to read".

    One other plus with using spaces instead of tabs is that it works well for forums. The only other thing I will say, if you use spaces, is pick a sensible number of spaces for indentation. I think 2-8 is typical and reasonable, I prefer 4, but my current job uses 2, which has grown on me, but I feel like 6 is too much. Also, make it consistent for every level of indentation. I mean, every tab should move the same number of spaces. You may laugh, but I worked at one place where a significant portion of the code had a very consistent indentation pattern, as a whole, but each level was different. 5 spaces for the first level of indentation, then 3 thereafter, except switch statements, in which the case statements were indented 2 from the switch keyword, and the code in each case statement was indented 2 from it's case label(s).

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    On the matter of spaces vs. tabs, or even the number of spaces in indentation, there should be no compromise. There should be no "it's a matter of taste". As someone who worked with development teams all my life, one thing I can say: code formatting is worth fighting for. It's one of the few issues on code style that is worth fighting for. And if you are in a position to impose your will, you go ahead and use that power.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-04-2010, 02:14 AM
  2. Reading white spaces? oh and scanf_s
    By RobotGymnast in forum C++ Programming
    Replies: 7
    Last Post: 11-01-2008, 05:32 AM
  3. white spaces ...
    By eagles in forum C++ Programming
    Replies: 6
    Last Post: 01-13-2006, 07:55 AM
  4. white spaces
    By Jules in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2004, 02:55 PM
  5. White spaces
    By Garfield in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 11-18-2001, 08:24 PM