LB -- Tabs vs Spaces

Was browsing and came across this (http://www.lb-stuff.com/tabs) which I think is written by someone here, anyways he quoted a bunch of people so I figured I'd reply at least to some of them (a lot of them were duplicates).

Why do you care? The tab key can be used to both increase and decrease indentation regardless of if it is tabs or spaces.
---------------
Because there is already a dedicated key on the keyboard for inserting spaces: the spacebar. The tab key should only ever insert hard tabs - to do anything else would make it some other key, such as "the indentation key". It isn't that though. As for removing indentation, I find the backspace key more intuitive than shift+tab or other concoctions.


You can use an argument here that you used below, you are being a control freak here. If I program only in spaces the tab key would never be used if it only inserted hard tabs. Why wouldn't I re-purpose it then? Who would choose to press the spacebar 4 or more times when they can simply press the re-purposed tab key instead? Let people have their own preferences. Do you also want to control what shortcuts do? Are those in your control to dictate as well? Go use Vim and try and type a word, I can tell you right now pressing the Q key doesn't insert the letter "q" without first pressing some other key.

The hard tab length agreement between different text editors cannot be reached / The hard tab length agreement between people cannot be reached
------------
Again: letting the user decide for themselves is a good thing. If you are worried about the length of a tab on someone else's screen, you're a control freak - let people have their own preferences.


It is a good thing but not when it affects me. Having to decide when you are writing code when and where you should use tabs or spaces is more work than the benefit. When I'm writing code I don't want to worry about whether the formatting will be correct especially when there is an alternative that guarantees what you see is what you get. The more important part is writing the code, using tabs with spaces just impedes that by having to worry about formatting which should be trivial (you shouldn't have to worry about that, imo). Tools also don't work well when you blend tabs and spaces, so you are reducing your proficiency for the sake of someone else who might not even like your coding style. I have a lot of preferences when it comes to coding, like having braces on a new line, camel case vs underscores, or some of the weird indentation formats where the braces are on the same line as the code they contain. Only difference is you can't really complain there. If you can read and write code when someone else doesn't use your preference for those you can certainly do the same if they don't use your preference for indentation.

This is even worse on white space sensitive languages (Python, CoffeeScript) as this might actually cause syntax errors or programming logic errors
-----------
Languages should make it hard to do the wrong thing and easy to do the right thing. That includes making it easy to make the code readable and hard to make code look like it does one thing while actually doing another. Languages which require spaces for indentation are asking for trouble unless they also require consistency.


That's not really the fault of the language though is it. What should they use instead of spaces? There is no alternative, not for anything that isn't visible, which would just add clutter to the code. Making alignment of the code do exactly that reduces the chance of errors. You know those brace-less C if-statements that have more than 1 line. People indent them making it look like it's part of the function even when it actually isn't. Enforcing spaces in Python isn't that difficult either, just write a simple program (only a few lines probably) that scans your Python code and if it contains a hard tab anywhere then throw up an error.

There is no style guide or coding conventions saying that the tab character should [be] the indent. This assumption is easy to make because it allows you to stick your head into a sand, ignore the surrounding world and by singing “let the users pick their own tab width” mantra. However, though a cunning idea, this perceived simplicity causes compatibility and co-operation issues
----------------
No style guide? This page is one. You should try to make things so that people's assumptions are correct. Only a malignant person would want to make things so people's assumptions are wrong or dangerous.


Which came first, his post or this page that is quoting his post. Not sure what you think people's assumptions are but if you need a guide for it then there probably isn't an assumption that people make. Anyways not everyone agrees with this style guide (pretty obviously me). If someone suggested to use tabs and spaces together I would tell them they are crazy and probably a masochist. It's far simpler to just use spaces only, hell even tabs only is simpler but you get all that nasty misalignment.

There is nothing gained by having “user chooseable indentation width by adjusting tab character width”. The most used indentation width is 4 spaces anyway, so it is extra effort to maintain the freedom to have a user pickable indent width number instead. Try to go to tell some old UNIX admin that they must adjust their editor tab width
----------------
Ok, explain why. Prove that there is truly "nothing" gained by this. I have already listed several reasons above that contradict this statement. As for "some old UNIX admin", I am deeply sorry that they have to maintain a legacy system from the 1980s. It's 2015.


I explained why as well, there might be a very tiny gain but it's not worth the extra effort you'd have to do to have that benefit. Programmers already have to deal with reading code that is not their own preference anyways.

Tabs cannot be used to format code multi-line functions
---------------------
Right, because tabs are for indentation and spaces are for alignment. I am not saying that you should use tabs everywhere and never use spaces.


Using both just complicates formatting which shouldn't be complicated. No worrying about whether you should be using tabs or spaces. I should be worrying about the code I'm writing not whether I need to use tabs or spaces incase some random person reading my code decides they don't want to read indentation that is 4 spaces.

Most of the other quotes are either duplicates or simply stating that what the person said is in accordance with what he was saying. Would be interested in hearing his replies if he is still around, or anyone else.
Last edited on
This should probably be a PM, not a topic.
Anyone could reply, i guess there just isn't anyone else that uses tabs + spaces.
I agree that using tabs to indent to the correct level and spaces to align within an indentation level would give the best results, but I personally wouldn't waste my time doing it. If the IDE I already use could be configured to do it automatically, I would use that setting, though.
That article is mostly about my opinion and why I do things the way I do them, the way I think, etc. - obviously you can indent code however you want, I was just highlighting some of the more ridiculous quotes and arguments I found from people who either contradicted themselves or made a mountain out of a mole hill. In response I made a planet out of a mountain ;p
in the end, it doesn't really matter if you use spaces or the wrong one
Topic archived. No new replies allowed.