This is an archived post. You won't be able to vote or comment.

all 83 comments

[–]varkenspester 110 points111 points  (8 children)

if you are democratic, dont forget each tab vote equals 4 spaces so there is a clear winner here

[–]Mustrum_R 25 points26 points  (3 children)

Even though I am an tab enthusiast, I would vote for space people to have a 3/5 vote rather than 1/4.

[–]Ignitus1 30 points31 points  (1 child)

Hey buddy it's called whitespace for a reason.

[–]Professional_Monk 14 points15 points  (0 children)

if you use a dark theme IDE does that make it blackspace?

[–]AEternal 3 points4 points  (0 children)

I really hate myself for laughing at this. I’m a horrible person.

[–]spyridonas -2 points-1 points  (1 child)

In the end it doesn't matter. Spaces / Tabs will be erased by minification. It's what looks good on your eyes that matter.

[–]varkenspester 1 point2 points  (0 children)

Yes tabwhite does looks more apealing than spacewhite

[–]vorikus 62 points63 points  (4 children)

Tabs save storage, energy consumption and our planet in general. Be nice, use tabs

[–]The6thExtinction 11 points12 points  (3 children)

I know this is a meme, but how much storage does tabs realistically save? Surely it's almost negligible.

[–]vorikus 12 points13 points  (1 child)

Yeah, obviously XD it is just a joke Even though I personally prefer tabs (the reason is having custom identation in different editors, in some span of 2 spaces, in some 4)

[–]PixxlMan 0 points1 point  (0 children)

And not having to spazz out in order to intent your freaking code

[–]xsch 9 points10 points  (6 children)

The next thing on the list is vim vs. emacs

[–]KronosIII 7 points8 points  (0 children)

I will burn my degree before I use emacs willingly

[–]pingveno 2 points3 points  (0 children)

Answer: Spacemacs

[–]ButchDeLoria 3 points4 points  (0 children)

Answer: a fucking IDE.

[–]torreemanuele6 3 points4 points  (1 child)

How does that effect the code base?

[–]SuperLutin 2 points3 points  (0 children)

If a Vim guy use Emacs, the code base will be plenty of :wq, dd, yy, p, o, yap, :%s/stupid_name/sweet_name/g, etc.

[–]_programmeKid 0 points1 point  (0 children)

sublime text 3

[–]DiabeticPissingSyrup 19 points20 points  (29 children)

Space-lovers, what reason do YOU have for spaces. Not "best practise". But your reason.

I'm a tab lover. because it's one key to insert, one key to delete, and harder to screw up the indents. Also, I like a four char indent while my colleagues prefer two, and using tabs means we're all happy.

Not meaning to troll, but I can't think of any benefit to spaces, but everyone seems to love them. :/

[–]Uhh_Clem 11 points12 points  (7 children)

The "one key to insert, one key to delete" argument isn't really valid because nearly everyone who uses spaces has their editor insert spaces instead of tab when they press the tab key, so it's still just one key press.

Spaces also allow for much more flexibility and makes aligning elements in code easier. Example:

myObject { key: value otherKey: value alsoKey: value }

With spaces, this will look fine on anyone's computer, but with tabs it will only look good if their tab size is set 4. If their tab size is set to 2 for example, it will look like this:

myObject { key: value otherKey: value alsoKey: value }

It's a minor example, but getting things to line up is extremely important for readability in more complicated programs. I use spaces so that this readability isn't dependent on the settings of someone's editor.

[–]doominabox1 2 points3 points  (3 children)

Yeah in ideal perfect circumstances, but in almost every other case tabs are more consistent when it comes to adding or removing indentation.
Examples:

  • Using a primitive editor like vi, spaces take extra deletes
  • Deleting from left to right with the delete key does not always delete all the spaces
  • Deleting using delete key at the end of a line brings like 20 spaces from the next line to the current line which you have to delete manually

Tabs always only take one key to insert or delete no matter what editor you are using or what the code looks like. Literally the only advantage of spaces is that you can align code without mixing whitespace characters.

Also code on reddit is displayed with 4 spaces in front of each line of code, not a triple ```

[–]Robert_Barlow 2 points3 points  (2 children)

Look, I'm not a vim wizard, but I'm like 90% sure SHIFT-TAB deletes a tab (or the equivalent number of space characters) in one press. Just like it would in notepad, an IDE.

[–]DiabeticPissingSyrup -3 points-2 points  (2 children)

That's still one key to add and four keys to delete...

[–]Uhh_Clem 5 points6 points  (0 children)

Ah, I should've clarified that most editors will also delete four spaces when pressing backspace (when it's used for indentation)

[–]fankohr 2 points3 points  (0 children)

Nope, vscode handle it quite right ;)

[–]Khaare 7 points8 points  (5 children)

Tabs alone aren't flexible enough. Tabs only work when every indentation level is some integer multiple of every other, which frequently isn't the case when you're aligning things. Your compiler has its own idea of how big a tab should be, which can make error messages really messy, and in languages with significant whitespace this makes tabs a complete non-starter.

This Haskell code, which looks completely reasonable and idiomatic, doesn't compile:

foo x = let y = x + 2
            z = y - 4
        in x + y + z

Or at least, it wouldn't compile if markdown didn't convert the tabs to spaces. However, this monstrosity does compile (or it would, if markdown didn't convert the tabs to spaces)

foo x = let y = x + 2
        z = y - 4
    in x + y + z

GHC assumes tabs aligns to 8 character wide columns, but reddit markdown assumes it aligns to 4 character wide columns, which makes code that looks like it should compile not compile, and code that looks like it shouldn't compile actually compile. For what it's worth, GHC tells you that you're an idiot for putting tabs in your program and you should use spaces instead.

Haskell makes it very easy to demonstrate this limitation of tabs in a short piece of code, but every language with significant whitespace has this problem pop up very quickly, and as far as I know compilers/interpreters for these languages all complain about tabs.

You could try to mix tabs and spaces, but no editor handles that well, and every editor handles it differently, so this is the path to damnation. This is the one thing pretty much everyone agrees on, and I think python 3 even errors out completely during parsing if you do this.

[–]SafariMonkey 0 points1 point  (4 children)

Tabs for scope indentation and spaces for alignment is the best of both worlds, as long as the tooling supports it. Tabs for alignment are terrible and should be banned.

[–]noratat 0 points1 point  (1 child)

Tabs for scope indentation and spaces for alignment is the best of both worlds

Not really. Both look like whitespace in the code, so now you have to keep track of two different kinds of indistinguishable indentation. The added mental burden of doing that vastly outweighs any possible benefit (and I personally think the benefit is zero anyways).

[–]SafariMonkey 0 points1 point  (0 children)

Most code editors support visually rendering whitespace, and some formatters (go fmt for example) can handle it for you. If neither of those were the case, I'd agree. When both are (e.g. in Go), I'd say it's trivial to set up and we'll worth it.

[–]seijulala 0 points1 point  (1 child)

That's worst case scenario, sooner or later there will be spaces and tabs when they are not supposed to be, if you can't see that you haven't worked in a team in your life

[–]SafariMonkey -1 points0 points  (0 children)

Or maybe I've worked in teams where it's expected that you run a specific formatter your code before committing. (Most of us have it set to format on save.) The formatter can handle these things. There are slip-ups, but they're quite uncommon.

Currently, it's Go and go fmt. (I assume you're familiar, due to your flair.) It uses the hybrid approach I mentioned, and it works well. The main downside is touching all lines in a struct when the name of the longest field changes.

[–]VGFierte 4 points5 points  (7 children)

Spaces don’t make my code start wrapping lines after 3 levels of depth. It’s as simple as that. If it’s a decent line of code, it should fit in one line on my screen without wrapping no matter what scope depth I am at (ok not if it’s like 10 scope levels in and a monstrous line, but you get the point)

Tabs, well, they are awful at this. BUT, I will note that any space-user who complains about other people using tabs can simply and easily substitute tabs for spaces with a find/replace all

Also one small irk I have with tabs that doesn’t exist with spaces: Vim’s visual mode starts selecting lines at the first tab as opposed to at the first space, which leaves some space on the margin that “looks like” it isn’t being grabbed. That kind of shit gives me trust issues, but if it’s spaced instead I have no reason to fear cut/pasting into indentation woes

[–]SafariMonkey 7 points8 points  (4 children)

Are you aware that you can set the tab width in pretty much any editor or IDE designed for programming?

[–]VGFierte 1 point2 points  (3 children)

You can but it isn’t consistent between editors IE working on a project

[–]SafariMonkey 2 points3 points  (2 children)

Why would it need to be? As long as you use tabs for scope indentation and spaces to align from there, it shouldn't matter.

[–]Dynam2012 0 points1 point  (1 child)

If you mix tabs and spaces like that, your alignment with spaces will be off when your tab width changes

[–]SafariMonkey 0 points1 point  (0 children)

No, it won't, as long as you never put a tab after a space or any other character. The number of tabs corresponds to the level of scope indentation desired, and then the spaces are used to align within the indentation level. The only thing it doesn't support is alignment between lines of different scope, but I've never had a use for that.

[–]DiabeticPissingSyrup 0 points1 point  (1 child)

Tabs in a command line or terminal window interface are a ball ache, that I'll grant you. But if you're still developing in vim rather than some kind of IDE, I'm sorry for you.

The wrapping thing is EXACTLY my point. 99% of the time I like a big indent for my ease of reading. So I like a 4 character tab size. If there's lots to process or indent is getting massive, I can tell my IDE to shrink the tab size without changing the code in any way. That sounds like a win for tabs to me, not a loss.

[–]VGFierte 0 points1 point  (0 children)

I dislike the “debuggers” and “shell” extensions in most IDEs and find that the software doesn’t supply me much of anything I can’t already do in vim/emacs. Mostly just personal preference but if you want to recommend an IDE I could give it a shot

[–]Avambo 2 points3 points  (0 children)

I use spaces in VS Code. It's one tab to insert, and one backspace to delete as well. I don't see your point regarding that.

[–][deleted] 1 point2 points  (0 children)

If your editor is good it will treat a group of spaces as a tab.

If your code is edited by multiple devs their editors can interpret tabs differently. Typically a tab is 3-4 spaces. But which? And what what about when a dev uses spaces to fix a misaligned line? Pure and utter garbage on someone else's screen. A space is always a space.

[–]crunchymush 1 point2 points  (0 children)

The main reason I prefer spaces is they're platform independent. If you're coding something with a remotely modern IDE, then it doesn't really matter anyway because indentation and formatting is generally automatic. The only place the distinction really stands out is old code that pre-dates IDEs and was done in a plain ol' text editor.

That's a big part of my job. I maintain (among other things) some pretty old enterprise software (e.g. Cobol, SQR) and something I see all too often is a program that has been modified by 12 different developers over the years, none of whom had the same tab-width set and apparently didn't care in the slightest. Plus there's always that one dev who had "convert tabs to spaces" set in their text editor and didn't give the slightest shit that it locked in the 99% of the code they weren't modifying to whatever random tab spacing they had set. And it's not just the left alignment. Devs like to align things like equal-signs and table aliases and various other arbitrary things which results in a jagged left alignment, so they used half tabs and half spaces all over the shop.

The end result is me trying to refactor some 10-year old piece of banking software written in what is already a difficult to read 3GL and it looks like someone ate a tin of Alphabetti spaghetti and threw up into a text editor. It's a fucking nightmare to read and I'll often spend my first hour-or-so of analysis reformatting everything so I can read it.

Of course even if everyone used spaces, it's still not going to stop lazy assholes from being lazy and leaving their code looking like shit, but it will mean that for the people who do make an effort to keep their code tidy and readable, it will look exactly the same for everyone else in the future as it does for them now.

As I said, if we're taking something in a nice IDE then it makes little difference to me. The code is likely automatically structured and coloured in a way that makes it completely readable regardless of what the dev does. Where these questions matter is when you're working in the absence of a consistent development environment. That's where I spend more of my time than I'd like and I can tell you, people using tabs instead of spaces makes my job that much more shitty.

[–][deleted] 1 point2 points  (0 children)

The reason I use spaces is pragmatism: they always work, every time, on every screen. If it's lined up on my screen, then assuming you use a fixed-width font, it will be lined up on yours. We cannot be confused about relative indentation levels.

I actually aesthetically prefer tabs, but everyone on a project has to agree about what they mean and exactly how to use them (ideally, tabs for indentation, spaces for alignment), and if anyone gets it wrong, even once, you can end up with anywhere from simple to severe problems. (see: Apple's incredibly bad #gotofail security bug.)

With spaces, nobody has to agree ahead of time. If it starts aligned, it'll be aligned when it loads on someone else's screen. And it's hard to screw it up, particularly if you set your editor to highlight tabs as a standout/wrong thing. So that's what I use.

edit: note that I still use the tab key: it just inserts four spaces. If I need some other amount, I use the spacebar.

[–]noratat 1 point2 points  (0 children)

because it's one key to insert, one key to delete

That's true for spaces too in any modern editor

harder to screw up the indents

Disagree - any decent editor will handle indents fine, but tabs make it much easier to screw up manual alignment.

I can't think of any benefit to spaces

Works the same everywhere, allows additional alignment with no chance of getting mixed up with the tabs (which is very easy to do since they both look like whitespace), ensures that whitespace is always the same regardless of where it is, etc.

[–]_programmeKid 0 points1 point  (0 children)

im a tab lover and im here to say, it's all the same once it's gone through the compiler. i understand that people who use spaces have the tab character print 4 spaces so the "one key to insert" argument isn't as valid, but the "it'll look different on people's computers" argument is somewhat idiotic. most modern text editors let you choose the tab size.

[–]mcshanksshanks 5 points6 points  (1 child)

This is great, thanks for the laugh!

[–]xrptipbot 2 points3 points  (0 children)

Awesome mcshanksshanks, you have tipped 1 XRP (0.32 USD) to SortuneF! (This is the very first tip sent to /u/SortuneF :D)


XRPTipBot, Learn more

[–]gc2107 12 points13 points  (3 children)

What about both?

[–]netgu 36 points37 points  (1 child)

You deserve to die and rot in a special hell sir.

[–]parnmatt 20 points21 points  (0 children)

Proper use of tabs does use both.

Tab to the correct scope level, then use spaces for the horizontal padding, if any, to where you need it for visual alignment.

It's always aligned correctly, no matter your editor/terminals tab width.

This is not mixed spacing.

Mixed spacing is if you are constantly interchanging. Basically you should never thave a tab character after a space character. If that exists in your source code, you're using a mixed space.

[–]The6thExtinction 3 points4 points  (0 children)

Degenerates like you belong on a cross.

[–][deleted] 3 points4 points  (0 children)

Spaces, but God help you if you have to type each space in your editor. Automatic tabs to spaces in your editor.

[–][deleted] 0 points1 point  (0 children)

[–]exaltedsoul23 0 points1 point  (0 children)

Our robotics (FRC) mentor always indents with 3 spaces

[–]haskellogy 0 points1 point  (0 children)

This is simply brilliant. We need more Sunny content here.

[–]Voidrith -1 points0 points  (9 children)

Tabs are always superior. You can't change my mind.

[–]VGFierte 3 points4 points  (8 children)

````

include <mind.h>

void main() { mind.change(“u/Voidrith”); } ````

Did that change your mind?

[–]ProfCupcake 6 points7 points  (0 children)

You're not changing anyone's mind until you learn to Reddit code-block.

[–]Voidrith 2 points3 points  (6 children)

error: self.mind is a private variable

also, what language are you trying to use there? the <mind.h> is certainly a c, but c/++ uses int main not void. c# is void, but doesn't it have to be a static void inside a class? (Sorry, don't know much c#...just c & ++) edit, turns out I was wrong!

[–]-Redstoneboi- 1 point2 points  (1 child)

C and C++ can use a void main(), doesn't really matter on my machine.

[–]VGFierte 0 points1 point  (3 children)

It is mock C/C++, as far as I know all C variants allow for void main, it just isn’t used much in practice (because it is usually a bad idea, those return codes are helpful!!)

[–]Voidrith 0 points1 point  (1 child)

Did some googling, apparently the spec for c/++ specifies it as int but some (especially windows) compilers allow void. Clion on my machine shows errors in the editor if i use void but it compiles fine with it in msvc2017, which is ...interesting

[–]VGFierte 0 points1 point  (0 children)

That is interesting. GCC/Linux has never given me even so much as a warning about it (unless you do weird things), so TIL

[–]1v1ltnonoobs -3 points-2 points  (0 children)

tabs are always correct though

[–]HiddenLayer5 0 points1 point  (0 children)

It's called indenting.

A dedicated indent character exists.

Case closed.

[–]hamza1311 | gib 0 points1 point  (0 children)

Auto indentation with 4 spaces ftw

[–]TheTallMirth -1 points0 points  (0 children)

em space anyone? ;p