70
gdb123
5y

tab vs spaces, which do you prefer?

Comments
  • 17
    Spaces, because they look consistent out-of-box everywhere.
  • 7
    To tell you the truth, this has been asked before, and the answer is apparently spaces because most modern editors will convert a tab character to 4 spaces by default.

    Its pretty much like newlines and version control. They will generally be converted to unix newlines by default and so the issue is not really relevant anymore
  • 4
    Spaces.
  • 2
    Spaces, if I get to choose, but the difference is so insignificant that I often just leave it on whatever the editor default is.
  • 3
    Four spaces per indentation level.
  • 6
    😐😐😐😐Emojis
  • 9
    Tabs. You can change at will how they appear without touching the code (or by only touching prettier/lint files). Today I prefer tabs to be equal to 4 spaces. Tomorrow I might switch to 2. You can't do that with spaces.
  • 1
    Spaces for the control but sometimes tabs because it's quicker. I use spaces more often because I like to line-up my codes and paragraphs nicely.
  • 2
    Tab vs spaces here we go again. So 2 spaces or 4 or are you eccentric and 3 spaced out.

    Thank Go for tabs and a build in formatting tool.

    Spaces displayed consistent everywhere is a myth. Depends on Font. So tabs can be adjusted to your needs is just about any decent editor. Removing the whole how many spaces debate which is far more important than bullshit consistency. Tabs are made for indentation spaces are not.
  • 0
    I press tab, and the editor converts to spaces, so I guess both?
  • 0
    @FrodoSwaggins I'm not a lunatic but open dyslexic font looks way different than courier.
    If I feel that lines are getting to long to fit I can adjust my tab with for the project without fucking up the contents.

    Don't get me wrong I'm using PSR-2 on PHP as this is the dominant standard and that is fine. I will adapt. However tabs are better. Using golang makes that clear every time. There is some discussion about the Drupal code standard again for Drupal 9. Won't see that happen with any Go project.
  • 0
    An interesting concept I found on a SO post about this type of discussion, is that you store your source as whatever, and have your editor just format it the way you want to see it. Kinda like how HTML and CSS are supposed to work.

    Are there any editors/IDEs that have experimented with that type of functionality?
  • 7
    Tabs because spaces are stupid. Makes it harder to select the right position with the mouse and you can't navigate with arrow keys which I do all the time for efficiency

    They're objectively worse
  • 1
    @FrodoSwaggins To be fair, it's the same argument as "spaces look the same everywhere". 4-wide tabs are the standard that everyone uses
  • 2
    @12bitfloat True, "everybody" uses tabs because obvious reasons. Spaces are error prone and less convenient, simple as that. If editors did not have any sort of automatic conversions, then the majority would press tab to get their indents on.
  • 2
    @theuser Which makes me wonder why people are using spaces in the first place when they are so annoying to use, editors have to pretend they are actually tabs
  • 2
    @12bitfloat Spaces are more absolute and consistent. If you worked in a public open source project with lots of contributors, then that project would probably use spaces consistently. For other smaller or internal projects where everybody have the same tooling, then the consistency would not be such a big factor.
  • 0
    Using tabs to type 2 spaces! Works and looks great
  • 1
    @theuser My code is 100% consistent stylistically, and I exclusively use tabs. I guess it's more of a concern when doing crazy half-indents for wrapped lines or something but that's definitely harder to keep consistent than just two tabs
  • 10
    3 spaces of course.

    It's a very satisfying compromise between frontenders who use 2 and backenders who use 4.
  • 1
    Spaces. Two spaces in most of the cases.
  • 1
    @12bitfloat sadly not everyone uses 4-wide tabs (https://kernel.org/doc/html/...)
    Other wise I totally agree w/ you, spaces suck

    And maybe spaces are visually more constant, but fuck that when fucking symfony now forces you to use 4 spaces in YAMLs but your 300_000 LOC codebase uses 2 ! 😑
  • 0
    @MagicSowap OMG, indeed, enforcing more spaces per indentation level is not pragmatic at all.
  • 3
    Tabs. And I just can't get why the hell people can just still think about spaces.

    @12bitfloat mentioned how awful it is for navigation, which is true, objectively
    Now about presentation, as far as I understand the functioning of tabs, it is rendered as regular separation of a certain amount of space fixed by your editor
    So visually you can't see a difference with spaces, plus there's something great about it: since it is rendered by your text editor, you can set it to be of any width you want without annoying your coworkers working on the same file with different indent likings. So no stupid compromise.
  • 0
    @CodeTalker Spaces are better if you want to align indents to some text element. For example in python if your function call gets too long you're allowed to break the parameter list into multiple lines, but they have to be aligned to the opening parenthesis. You can't do that with tabs precisely because you can't expect them to be exactly 4 chars wide.
  • 0
    To be honest, I tend to stick with what this tells me:

    https://ukupat.github.io/tabs-or-sp...

    That way, when I publish my code or collab, I minimize the chance of annoying others... because to be honest, I don't really care all that much.

    I was serious about 3 spaces though, all my historical Haskell projects are 3-spaced in any place where indentation is an arbitrary choice instead of alignment-based, because I've worked professionally on multiple large Haskell codebases which where 3-space indented.

    Their reason really was "it's a compromise between 2 and 4", and it grew on me after a while.
  • 0
    Spaces. The debate has dried up, and all but a minority of styling docs now specify spaces (for most languages anyway.)

    At this point it doesn't really matter about the finer reasons why, it becomes about being pragmatic rather than principled. There's some things in life where going against the flow and being principled is really worth it - spaces vs tabs is not one of those arguments.
  • 0
    @AlmondSauce ON TO THE LIGHT VS DARK MODE DEBATE!

    No?

    OK HOW ABOUT FIGHTING BLOODY BATTLES OVER CURLY BRACE PLACEMENT? K&R VS 1TBS, ROUND ONE, DING DING DING!

    Still no?

    OSX VS LINUX? VIM VS EMACS?

    No?

    OK can we at least all agree that Postgres beats both MySQL and MariaDB?
  • 0
    @bittersweet OpenLDAP if you ask me.
    Or if you want it to react fast: Redis on a swapped drive (because all our data wouldn't fit into memory) which is actually a giant LVM logical volume spanning over several files on networked drives mounted to the database server with SFTPFS.
  • 1
    @Lor-inc > SFTPFS

    I don't know why, but I find that abbreviation offensive.
  • 0
    @bittersweet SFTP filesystem. It's a tool to mount sftp shares. It should be sftpmnt though.
  • 1
    @Lor-inc But it sounds like someone spraying spit in my face πŸ˜†
  • 0
    According to language. There’s different best practice as defacto by languages and in most cases, that is space. The only matter is how many spaces. 2 or 4.
  • 0
    Don't ask questions like this, unless you want to start ww3
  • 0
  • 0
    @vintprox thing is, you can't just enforce a different indentation level on an existing codebase !

    Especially as we are talking about yaml here, which means bad indentation = bugs/crashes and you can't just regex 2 to 4 spaces easily.

    Maybe you like 4 spaces in your yamls, but I don't. And I have other things to do than changing the indentation of config files ffs !
  • 0
    @Lor-inc I'm rarely doing that so I didn't think about it, but you have a point
    This is a shame this can't be done with tabs — though I can't see a proper way to do it
  • 2
    Tabs for indentation, spaces for alignment.
  • 0
    @CodeTalker It can't be done with tabs precisely because their width is adjustable, which is a their selling point. What could be done, is to have the IDE differentiate alignment from indentation and convert to spaces only the alignment part.
  • 0
    @MagicSowap But I jsut said that: it's very inconvenient, you know. Syntax enforcing more spaces/indent = evil
  • 0
    Why tab vs space debate?

    If I am not wrong tab is usually just 4 space.
  • 3
  • 3
    Tabs because it's literally what they are for, indention.
  • 1
    Tab on the keyboard. The editor may or may not convert it to spaces. I leave it to luck.
    Only relevant for python anyway, which i don't use much
  • 0
    @pythondev No, they're actually for alignment in columns. That's why their width varies depending on what's before them. For indentation you wouldn't need this - otherwise quite problematic - feature.
  • 0
    @shakur Good point, I did not know this. He may have felt that two wasn't legible enough and 4 was too error prone? Its quite convenient to hit the spacebar three times as opposed to four.
  • 0
    @theuser but hitting tab once is easier πŸ˜‰
  • 2
    @theuser @pythondev I highly doubt RMS would've pressed the spacebar three times, he's the kind of person who, if he has to do something thrice, will get the editor to do it for him so he only needs to issue indent and outdent commands.
Add Comment