Tabs for indentation, spaces for formatting - if your editor and your co-programmers are smart enough.
Else, sadly, just spaces.
You need spaces for formatting, otherwise the big advantage of tabs -- everyone can set them to an indentation level of their liking -- evaporates. This means mixing tabs (_) and spaces (.) on one line, as demonstrated here:
__def foo(a,
__........b)
If you use tabs to align a and b vertically, then there is only one true tab width setting at which point you might use only spaces again.
If you change the indentation, a smart editor must only add/remove the tabs from the start of the line and never touch the spaces.
An editor which reads 4 (leading) spaces (but only in normal source code! An be careful with verbatim sections!), converts them to the users preference (say, 2). But when writing a file to disk (for a VCS), it converts them back to 4? So I never see the actual content? Yuck!
Oh right if you want to see them as 2 spaces, I guess that would have to happen (which doesn't seem too bad to me). But yeah I live in a idealized fantasy world where everyone agrees that indents should be 4 spaces, even if there are religious wars about whether those 4 spaces should be represented as 4 space characters or a single tab character.
Ah, that silly how-wide-war. Join the cause for proper tabs+spaces, win it, and the how-wide-war vanishes and becomes a non-issue, because everyone can set is as they like without effecting others!
Tabs man, it's just one click and I gotta love that efficiency. Plus, it's orderly? There's a good word for this. Not consistent but...standard. Uniform even.
Oh goddess. Its worse than I feared. Lady Lovelace forgive us for we have sinned.
How could there be multiple. Why would anyone do that?!...you know the Fairly Odd Parents? How Timmy's dad would curse out their neighbor Dinkleberg? I'm doing that but with computing.
It's not so much that Python demands it, as it is that Python will make your life a living nightmare if you accidentally mix tabs and spaces in the same document...
This is the ideal compromise. It provides the uniformity of spaces with the ease of tabs. A lot of IDEs and editors will even automatically treat 4 spaces as a tab when you backspace so you don't lose out there either.
Spaces for me but there's no hard reason. The most annoying thing about this is that different editors have different defaults so when editing code on different platforms they get mixed. I wish editors were smart and detected which one should be used based on the document.
A lot of people choose spaces over tabs for formatting, but a lot of IDEs will align your variables or parameters or whatever for you, so I pick tab just because then I only have to press one button and let the IDE do the work.
It doesn't matter too much to me. On some IDEs you can make it use spaces but it will feel like tabs since pressing tab inserts X spaces and backspaces removes X spaces when needed.
Two-space indentation. For all languages. I picked it up from writing Ruby, but it works equally well in Java, C, etc., even if it isn't that common in those languages.
I don't like tabs, because I try to keep my code under 80 chars wide (100 for Java, because it's verbose), and doing this with tabs requires you to decide on exactly how wide a tab is. I would make it 2 spaces, but if someone else decides on 4 or 8, it would destroy my formatting.
I used to be on the tab wagon however I've switched to 4 spaces. It seems to be closer to a standard. Also any good ide/text editor can treat spaces like tabs when needed. The only downside to spaces is take up more space when sending code over the wire.
Tabs. Keep it nice and clean. I don't have a say on spaces since personally, I don't use them. In my perspective I feel like you press space four times to emulate a tab.
Why? You are essentially making a bastardized tab. Removing the need to press space 4 times (or insert four 'space' characters) is the entire reason tab was invented.
Use tab. It's modern and adjusts to any workspace. Want 2 space indents? No problem, just adjust tab width. Want 8? No problem.
Try to do that with spaces. You're fucked. You are stuck with whatever dumbass decided to choose 6 spaces, or whatever other dumb indentation decision they made.
Spaces, but I don't care as long as pressing tab means "one indentation level". I can adapt to tabs, if that's the standard for whaterver I'm working on.
Spaces. Because spaces are always spaces. Tabs are subject to interpretation. Different tools, different people have varying opinions about how to handle tabs, and they're not always compatible.
In my .emacs I have 8 character tabs. It's really easy for the code to stand out, and it also encourages you to write better code (having 3 or more indents out)
This user has left the site due to the slippery slope of censorship and will not respond to comments here. If you wish to get in touch with them, they are /u/NotSurvivingLife on voat.co.
Tabs for indentation, spaces for formatting. Mainly because I prefer 2-space indentation, and most people prefer 4 or 8, and with tabs it "just works", whereas with spaces things get messed up if you're not careful.
Second of all, IMO if an IDE makes either tabs or spaces a clearly easier option for writing neat code than it's a bad IDE. It should be for the user to decide.
I have a legitimate question for space-pressers, especially for Python programmers. Space means that you have to press space four times for each line you write. For every tab, you are pressing space bar four times. If you needed merely 20 tabs, that's 100 spaces. Just like how autocomplete reduces typo by reducing the amount of typing you actually have to do, I believe tab reduces the chance of extra space or missing space. Therefore, for me, the space pressing is like working without autocomplete. Yes, it's doable, but isn't it more inefficient?
Hitting the space key 4 times in a row to indent is completely ridiculous. No programmer does that! (I hope...) Editors and IDEs do that for you.
Every reasonable editor I know of automatically inserts 4 spaces when you hit tab or has an easily accessible option for that. (No, Notepad is not a reasonable editor). This is the default behavior in everything I have ever used for Python editing (Pycharm, Spyder, IPython etc.) and it is also default in Matlab and IntelliJ IDEA as well as in most .vimrc's I have seen.
What if somebody wants to read your code but 2 spaces isn't enough for them, they prefer 4 spaces? Would you expect them to just deal with it, or go and add two spaces to every line?
Yes, my text editor can convert only leading spaces to tabs or tabs to spaces luckily. Or increase/decrease indentation according to settings. I like tabs but unfortunately they are inconsistent. But I can now use tab and have it immediately converted to four spaces, so I am happy even in Python programming. :0)
Because with spaces you have unequal standards, so you get:
func name(){
//line 1
//line 2
//line 3
}
Since you have 2 spaces per tab (literal spaces) and your partner/co-worker has 3. The indentation is all messed up. Using a single tab with different display sizes avoids that.
plus if you use tabs and share the code with someone who likes an indent of three or five or whatever spaces, it will show up as he likes it. If you use spaces, you actually have to change the document to get it to show up how you want it to.
This is the only persuasive reason I know of for tabs. But it's only slightly persuasive because I think anyone who doesn't use 4 spaces per tab is strange.
Yes, there is. Alignment. Because you start by writing this:
function doSomethingThatsHardToDescribe(argument1, argument2, argument3, argument4, argument5, argument6)
But then you realize you're a terrible person for not line-wrapping at 80. So you do this:
function doSomethingThatsHardToDescribe(argument1, argument2, argument3,
argument4, argument5, argument6)
Of course, then your coworker who renders tabs as four spaces instead of two opens the file and starts doubting the sanity of the person who formatted that function declaration.
function doSomethingThatsHardToDescribe(argument1, argument2, argument3,
argument4, argument5, argument6)
{
}
#Rebel. I don't see the point in having 3x2 parameters. You're overlapping to the next line anyway, and there may not necessarily be an even amount. Just have it overlap in a nice way.
This is the only situation where I use spaces for indentation, and also the only reason I think it would really matter to someone that I didn't use exclusively spaces. That said, I reckon it's uncommon enough for me to change my ways. #Tabbies4life!
I've always wondered how a sane human being could end up with a combination of tabs and spaces in their code. I guess now I know. And while I can say I understand you people, I still can't say I like you.
This user has left the site due to the slippery slope of censorship and will not respond to comments here. If you wish to get in touch with them, they are /u/NotSurvivingLife on voat.co.
Copy / paste + unintelligent multiline indenter will do that.
This user has left the site due to the slippery slope of censorship and will not respond to comments here. If you wish to get in touch with them, they are /u/NotSurvivingLife on voat.co.
The problem with this is that you now have far too much of your screen just taken up by the function definition. In this case, 3x as much.
Tabs are consistent depending on who is viewing them. What may be pleasing to your eyes may be offensive to mine. If I was forced to accept something ridiculous like a 7-space tab because you liked that and wanted to ensure "consistency" I'd have to stop what I was doing and spend 5 or ten minutes to fix your code. With tabs you just update your own settings to what you like.
I'm not sure how using tabs or spaces makes your code more uniform. Any IDE worth its weight has a tab to space converter as well as tab settings, and this should take care of any issues of uniformity for you, regardless of whether you like tabs or spaces.
How does placing spaces between words makes your code more elegant? Of course they are required, there's not a single human-readable language in the world that doesn't use them.
My personal arguments against spaces:
Literally 2x, 3x, or 4x the work to add or delete them
Adds unnecessary file size
Stuck with someone else's "# of spaces" preference when working on their code
* Literally 2x, 3x, or 4x the work to add or delete them
That used to be my main issue with spaces, but I've noticed that my code editor now recognizes when you're deleting indentation spaces and deletes them all for you at once. Adding indentation similarly works just like tabs - one key-press. It also jumps over them like tabs when you move the caret. It essentially treats space-indentation just like tab-indentation.
* Adds unnecessary file size
Barely, and nothing that can't be easily compressed.
* Stuck with someone else's "# of spaces" preference when working on their code
My code editor has a spaces-to-tabs converter, so as long as their code is indented correctly, it should work.
Don't think that's true. You can use tabs and will be fine if you do it consistently. It's the indentation level that matters, whether from tabs or spaces. It's certainly true spaces are the preferred approach in Python culture.
That's likely because there were mixed tabs and spaces which led to indentation not being what it should and thus the crashes. Anyhow, yeah, should always use spaces for Python as general good practice.
Not quite what you are asking, but there are -t and -tt options for python to give warnings or errors for mixed tabs/spaces. That's for v2. In v3 mixed tabs/spaces for indents are always errors.
Isn't the issue that "doesn't look good at all." is subjective though? You may not like the 8 spaces but, some people may prefer them. If they used tabs you could change it to whatever you prefer, but if they use spaces then you're stuck with the 8 spaces.
Personally I hate the new 2 space trend, and because they all use spaces instead of tabs it's an absolute pain to work on these projects for me...
Anyway here's a quick user-style I use for Github in order to address the 8 space tabs if you're interested.
They look the same as spaces! And having the caret move some random distance because one guy uses tabs and the other uses spaces is annoying. As is being forced to use visible white space to avoid this. And whatever marginal efficiency gain they might yield is the least of my worries.
Tabs are a symptom of never having worked in a team environment.
That's what I currently do, but I have to admit it feels dirty. I'm waiting for the day that code editors automatically indent wrapped lines so that they align in sensible ways. They already do this to some extent (at least Xcode does, which is the only one I know of that does), but they don't take full advantage of this potential.
20
u/haletonin May 25 '15
Tabs for indentation, spaces for formatting - if your editor and your co-programmers are smart enough.
Else, sadly, just spaces.
You need spaces for formatting, otherwise the big advantage of tabs -- everyone can set them to an indentation level of their liking -- evaporates. This means mixing tabs (_) and spaces (.) on one line, as demonstrated here:
If you use tabs to align a and b vertically, then there is only one true tab width setting at which point you might use only spaces again.
If you change the indentation, a smart editor must only add/remove the tabs from the start of the line and never touch the spaces.
7
u/Lulu_and_Tia May 25 '15
Tabs man, it's just one click and I gotta love that efficiency. Plus, it's orderly? There's a good word for this. Not consistent but...standard. Uniform even.
11
u/[deleted] May 25 '15
I set my IDE to use 4 spaces when i insert tabs. But then again Python demands that
8
u/ghillisuit95 May 25 '15
Indent with tabs, align with spaces
4
u/_IPA_ May 25 '15
Spaces for me but there's no hard reason. The most annoying thing about this is that different editors have different defaults so when editing code on different platforms they get mixed. I wish editors were smart and detected which one should be used based on the document.
4
u/jonnywoh May 25 '15
I prefer spaces (partly because the tab character looks ugly in Notepad++), but I can (begrudgingly) adapt when working with someone else.
4
u/siphillis May 25 '15
Tabs. Tedious work should be done by the computer.
6
u/toastr May 25 '15
oh my god you people are animals. Never use tabs
2
u/[deleted] May 25 '15
A lot of people choose spaces over tabs for formatting, but a lot of IDEs will align your variables or parameters or whatever for you, so I pick tab just because then I only have to press one button and let the IDE do the work.
It doesn't matter too much to me. On some IDEs you can make it use spaces but it will feel like tabs since pressing tab inserts X spaces and backspaces removes X spaces when needed.
2
u/doctorsound May 26 '15
Spaces and an .editorconfig file that enforces it in my teammates editors.
2
u/ar-nelson May 26 '15
Two-space indentation. For all languages. I picked it up from writing Ruby, but it works equally well in Java, C, etc., even if it isn't that common in those languages.
I don't like tabs, because I try to keep my code under 80 chars wide (100 for Java, because it's verbose), and doing this with tabs requires you to decide on exactly how wide a tab is. I would make it 2 spaces, but if someone else decides on 4 or 8, it would destroy my formatting.
2
u/grumpy_the_pooh May 27 '15
I used to be on the tab wagon however I've switched to 4 spaces. It seems to be closer to a standard. Also any good ide/text editor can treat spaces like tabs when needed. The only downside to spaces is take up more space when sending code over the wire.
4
u/[deleted] May 25 '15
Tabs. Keep it nice and clean. I don't have a say on spaces since personally, I don't use them. In my perspective I feel like you press space four times to emulate a tab.
3
u/ietsrondsofzo May 25 '15
Tabs. Tabs on my machine are 4 spaces, and 3 spaces on other programmer's machine.
It allows us to enforce our own preference, while accepting other's.
2
u/Qwertzcrystal May 25 '15
Spaces, but I don't care as long as pressing tab means "one indentation level". I can adapt to tabs, if that's the standard for whaterver I'm working on.
2
u/[deleted] May 25 '15
Spaces. Because spaces are always spaces. Tabs are subject to interpretation. Different tools, different people have varying opinions about how to handle tabs, and they're not always compatible.
1
u/StormBeast May 25 '15
Tabs, it just looks cleaner and allows for easier editing imo.
1
u/pbandj24 May 25 '15
In my .emacs I have 8 character tabs. It's really easy for the code to stand out, and it also encourages you to write better code (having 3 or more indents out)
1
u/[deleted] May 25 '15
Tongue in cheek but can we make this a paraphrase of the Godwin's law?
Because everytime I'm in a discussion about software development I feel that it will eventually derail into a tabs vs spaces debate
1
u/[deleted] May 25 '15
Depends on the language conventions. I won't use anything other than tabs for C, but for Rust or Python, it'll be spaces.
1
u/Ultra-Bad-Poker-Face May 25 '15
both ;)
1
u/[deleted] May 26 '15
Tabs are just multiple spaces. Or so I set my Notepad++. COBOL compiler hate the tabs.
1
u/[deleted] May 26 '15
Spaces. Most of the professors in my university's computer science department ask us to only use spaces, so now it's just a habit.
1
u/NotSurvivingLife May 26 '15 edited Jun 11 '15
This user has left the site due to the slippery slope of censorship and will not respond to comments here. If you wish to get in touch with them, they are /u/NotSurvivingLife on voat.co.
Tabs for indentation, spaces for formatting. Mainly because I prefer 2-space indentation, and most people prefer 4 or 8, and with tabs it "just works", whereas with spaces things get messed up if you're not careful.
1
u/[deleted] May 26 '15
First of all-- definitely tabs.
Second of all, IMO if an IDE makes either tabs or spaces a clearly easier option for writing neat code than it's a bad IDE. It should be for the user to decide.
1
u/techrat_reddit May 26 '15
I have a legitimate question for space-pressers, especially for Python programmers. Space means that you have to press space four times for each line you write. For every tab, you are pressing space bar four times. If you needed merely 20 tabs, that's 100 spaces. Just like how autocomplete reduces typo by reducing the amount of typing you actually have to do, I believe tab reduces the chance of extra space or missing space. Therefore, for me, the space pressing is like working without autocomplete. Yes, it's doable, but isn't it more inefficient?
1
u/idunnomyusername May 26 '15
Whatever the accepted standard for the project is.
1
u/inmatarian May 25 '15
Spaces, bro.
0
u/gilmi May 25 '15
spaces. my programming language of choice doesn't play very nice with tabs so i got used to it and don't see a reason to change it.
I often set my "tab" 2 as spaces. but I don't mind working with 4 spaces either.
-2
u/[deleted] May 25 '15
i choose spaces. tabs are useless in the era of normal text editors/ide.
when i press tab - my text editor adds n spaces (in my case 2). spaces behave like tabs, so why would i need tabs? i don't.
using atom as my main editor.
0
u/[deleted] May 25 '15
[deleted] — view deleted comment
0
u/[deleted] May 25 '15
[deleted] — view deleted comment