4
Saad17
1y

The debate between using tabs or spaces for indentation in code is a long-standing argument among software developers. Those who prefer using tabs argue that it takes up less space and is more efficient, while those who prefer spaces argue that it allows for more consistency and easier readability.

Many developers have strong opinions on this issue and believe that their preferred method is the only correct one. Some even go as far as to say that using the wrong method can negatively impact their ability to work with the code.

Regardless of which side of the debate someone falls on, it's a common source of frustration and humor among developers. The argument often devolves into jokes and sarcastic comments, with both sides poking fun at the other's preferred method.

Despite the often lighthearted nature of the debate, it highlights the importance of code readability and maintainability, as well as the differences in personal preferences and workflows that can arise within the tech community.

Comments
  • 3
    tabs are clearly superior.

    when using spaces, you either use a dumb editor and have to press the key several times, which costs time.

    or you have an IDE, and you _press_ tab, and it inserts spaces for you. which is just "using tabs with extra steps", AND breaks the principle of least confusion, because on a basic level, "pressing tab" is not expected to result in "inserting multiple spaces", but in "inserting one tab".

    or you just use your editor automatic formatting, in which point the whole argument is completely moot - but if a decision had to be made, it'd be only logical to implement the way that in _all_ other cases is the better way - being tabs.

    i'd like to end my essay with the statement that the whole argument in itself has no practical meaning and is nothing but a humourous antic, since the opinion of anyone who prefers using spaces is, by definition, laughable ;)
  • 2
    @tosensei ypu forget the most important reason, it offers, when all else fails, an opportunity to have difference in opinion to argue about :P
  • 0
    Welcome to devRant! You used the wrong tag. 😁
  • 1
    Oh I though I was one Quora for one second there

    Welcome
  • 1
    @Voxera "difference in opinion"? don't see that. it's either an opinion of prefering tabs, or a fallacy of prefering spaces ;)
  • 4
    The non-rant has been written by ChatGPT.
  • 3
    Is it just me or does this post sound like it was written by chatgpt?
  • 1
    @tosensei And then you come to linter, or at least some code style rules everyone working on the project must follow. Suddenly the same line of code, with exactly 64 characters, appears 80 characters wide in one editor, and 96 characters wide in another, and any code that was aligned for readability with one tab size in mind becomes messy when viewed using a different tab size. Which one of those three "sizes" should be used as the true line length for the code style sake?

    Also most terminals and CLI text editors use tab size of 8 characters, which makes most tab-indented code look like crap.
  • 2
    Hello chatgpt!

    @tosensei I use most of the Jetbrains IDEs for my day job and the tab key inserts however many spaces the settings tell it to. Notepad++ and VS Code do it too.

    I have my indent size set to 2. I enjoy having as much code on screen as possible.

    I have whitespace set to visible, and the tab character sticks out like a sore thumb. Spaces are just a little dot that are easy to ignore.

    With spaces I can have arbitrary indentation for a line. It doesn't come up often, but it is a nice option to have.

    The only thing that is annoying is when I actually do need the tab character I have to jump through hoops to get one.
  • 1
    Tabs are considered better than spaces for code formatting because they take up less space and provide a more consistent and standardized way of indenting code. This helps to make the code easier to read, as the indentation levels are clearly defined and uniform. Tabs also allow for faster navigation and editing of the code, as a single keypress can take the cursor to the next tab stop, rather than multiple presses for spaces. Additionally, using tabs instead of spaces helps to reduce the file size of the code, making it faster to load and transfer.

    Spaces on the other hand are considered better than tabs for code formatting because they provide more control over the indentation levels, allowing for greater flexibility in the appearance of the code. With spaces, developers can fine-tune the number of spaces used for indentation, making it easier to achieve a desired visual layout. Additionally, spaces are more universally supported, as different editors and platforms display tabs differently, which can cause issues with code formatting and readability. Using spaces also ensures that the code looks consistent regardless of the font size or screen resolution, making it easier for developers to work together on a project and collaborate with others.
  • 2
    Be me: use tabs, convert tabs to spaces, everyone fucking wins!

    End of discussion.
  • 0
    @hitko the whole concept of "true line length for code style sake" is garbage. and if it's _really_ important, you just include the style settings in your project and be done with it ;)
  • 0
    May I present to you: The benefit of Apple’s closed system. There’s one IDE and there is no endless discussions about tabs or spaces. Just use the IDE default. Problem solved.
  • 0
    @Lensflare I'm going to be developing an app for iOS this year. Between having to use a Mac and having to deal with whatever ignorant nonsense Apple has foisted onto its blessed IDE, I dread it.
  • 0
    ChatGPT: Rant about tabs vs spaces for indentation.

    Is this ChatGPT jeopardy? Did I win?
  • 0
    @hitko I do mot think I have seen any developer targeted editor using 8 spaces for tab. 2 or 4 are usually the defaults and if someone wants to use notepad, well thats their choice :)
  • 0
    @Voxera How about cat, nano, echo, less, ...? Sure, everyone can configure the one editor they use however they want to, but a ton of other relevant tools default to 8, including GitHub / GitLab, terminals and shells, most command-line utils, etc. I certainly don't feel like googling "how to set tab size in X" every time I need to use a new tool.
  • 0
    @hitko github I agree with but none of the other are tools I use for any major development work so not something I view as a problem.

    And we aim for readable code which means, avoid long lines and avoid multiple levels of indentation so even with big tabs its never a problem :)

    But the current setting does convert the tab to actual spaces in our project

    But I have worked with both and with good tools it is not a problem either way.

    There are more important things to readable code :)
  • 1
    @Voxera Whatever floats your boat I guess, I use these tools quite a lot when looking at something over SSH or a serial console, or when I'm running something from the terminal and don't want to launch an IDE just to make a few small changes.

    With purely functional code you'll still have at least 3 levels of indentation, most OOP code contains at least 5 levels, and if you work with declarative UIs, the only way to avoid a large number of indents is to create many single-use components.

    Now I do prefer spaces because they provide consistency wherever you open the code and whatever tools you use with your code, but I don't mind if someone prefers tabs. I just don't want people to act like tabs are perfect when neither option is, especially not for every use case.
Add Comment