Discuss Scratch
- Blaze349
-
Scratcher
1000+ posts
Space vs tab
No flamewar. I want to know which is better for me to use in general code.
- Jonathan50
-
Scratcher
1000+ posts
Space vs tab
In languages like Python and Lisp using spaces is conventional so I do that, but in C using a tab is conventional so I do that, I prefer that way but it isn't a big deal.
Last edited by Jonathan50 (Aug. 11, 2017 10:47:24)
- herohamp
-
Scratcher
1000+ posts
Space vs tab
I used tab. I can't think of a time I have ever used space when trying to format stuff.
- gdpr533f604550b2f20900645890
-
Scratcher
1000+ posts
Space vs tab
I use spaces because apparently different editors handle tabs differently.
- bobbybee
-
Scratcher
1000+ posts
Space vs tab
I use whatever everyone else in the project is using. If it's my own project, I'll use whatever. If you want a religious argument, better ask about editors 

- herohamp
-
Scratcher
1000+ posts
Space vs tab
I used tab. I can't think of a time I have ever used space when trying to format stuff.I also just don't do anything then use Atom-Beatify or your IDEs equivalent
PS forget you python. What if I don't want to tab everything in when its in a function
Last edited by herohamp (Aug. 11, 2017 21:17:30)
- _nix
-
Scratcher
1000+ posts
Space vs tab
People that use a mix of spaces and tabs (tabs for intent, spaces for alignment) are incredible and amazing, but I'm sadly not one of them 
I use two-spaces on my own projects.

I use two-spaces on my own projects.
- NickyNouse
-
Scratcher
1000+ posts
Space vs tab
I use whatever my editor defaults to, as long as it's consistent and readable I don't really care
edit: I guess I use spaces if I need to vertically align things like
edit: I guess I use spaces if I need to vertically align things like
var abcde = 2,
bcde = 1;
Last edited by NickyNouse (Aug. 12, 2017 00:28:54)
- Blaze349
-
Scratcher
1000+ posts
Space vs tab
I use spaces because apparently different editors handle tabs differently.Pls explain?
- TheMonsterOfTheDeep
-
Scratcher
1000+ posts
Space vs tab
I use spaces because I often like to align things along boundaries smaller than tabs, and it's a real pain to use mixed spaces and tabs unless you have a good IDE. Essentially, any IDE that would treat the situation optimally (for me) would treat all whitespace as spaces, but save it as mixed spaces and tabs.
- MegaApuTurkUltra
-
Scratcher
1000+ posts
Space vs tab
The objectively correct answer is whatever your style guide asks for.
And if you don't have a style guide you're doing something wrong.
And if you don't have a style guide you're doing something wrong.
- rdococ
-
Scratcher
1000+ posts
Space vs tab
Contrary to MegaApuTurkUltra's claim, the objectively correct answer is tabs, with a few additional spaces if you want things to align more perfectly. 

Last edited by rdococ (Aug. 14, 2017 15:01:05)
- TheUltimatum
-
Scratcher
1000+ posts
Space vs tab
The objectively correct answer is whatever your style guide asks for.Oh noes… I have no style guide!
And if you don't have a style guide you're doing something wrong.
All of my c looks like this:struct link { int data; struct link* next; }; struct link* create(int data, struct link* next) { struct link* new_link = (struct link*)malloc(sizeof(struct link)); new_link->data = data; new_link->next = next; return new_link; } struct link* prepend(struct link* head, int data) { struct link* new_link = create(data,head); head = new_link; return head; } struct link* append(struct link* head, int data) { struct link* cursor = head; while (cursor->next != NULL) { cursor = cursor->next; } cursor->next = create(data,NULL); } int length(struct link* head) { int i = 0; struct link* cursor = head; while (cursor != NULL) { i++; cursor = cursor->next; } return i; } int get(struct link* head,int index) { int i = 0; struct link* cursor = head; while (cursor->next != NULL && i != index) { cursor = cursor->next; i++; } return cursor->data; } void dispose(struct link* head) { struct link* cursor; struct link* tmp; cursor = head->next; head->next = NULL; while (cursor != NULL) { tmp = cursor->next; free(cursor); cursor = tmp; } }
- Znapi
-
Scratcher
500+ posts
Space vs tab
Even if you used tabs purely for indenting and spaces for more fine control (like fancy alignment) only after tabs, which is difficult to do in most editors, you still have the problem of maximum line lengths. A line fitting within an 80 character viewport for someone using 2-space tabs might extend past 80 characters for someone using 4-space tabs. Horizontal scrolling to see past the 80 character mark is annoying, and naive line wrapping is ugly and hard to read:
Ideally, code should be formatted for readability and to fit onto the screen. Exactly how depends on the style guide:
However, a different tabs widths might require different formatting, which is problematic if people with different tabs widths try working on the same code (or maybe you try printing your 2-space tab code to your own terminal, which could use different tab width):
You could force everyone to use the same tab width, but then you still have the issue of trying to use spaces for fancy vertical alignment at the same time as tabs. You also still have to worry about other tools, like the terminal or GitHub, trying to display code with a different tab width. Having everyone use spaces, the same indent width, and a standard 80-character line length is just simpler.
+-----------Viewport----------+
|int main(int argc, char *argv|
|[]) { |
| very_long_line(arg1, a_long|
|_name(arg2, arg3), arg4); |
|} |
| |
+-----------Viewport----------+
|int main(int argc, |
| char *argv[]) |
|{ |
| very_long_call( |
| arg1, |
| a_long_name(arg2, arg3), |
| arg4 |
| ); |
|} |
| |
+-----------Viewport----------+
|int main(int argc, |
| char *argv[]) |
|{ |
| very_long_call( |
| arg1, |
| a_long_name(arg2, arg|), Uh oh....
| arg4 |
| ); |
|} |
| |
+-----------Viewport----------+
|int main(int argc, |
| char *argv[]) |
|{ |
| very_long_call( |
| arg1, |
| a_long_name(arg2 | This is better
| arg3), |
| arg4 |
| ); |
|} |
| |
Last edited by Znapi (Aug. 14, 2017 20:50:18)
- TheMonsterOfTheDeep
-
Scratcher
1000+ posts
Space vs tab
@Znapi:
It's still possible to do this with various-width tabs: just make sure every line will fit into an 80-character screen using <some tab length, perhaps 2 or 4> and then people using an 80-character viewport can just set their tab width to that width.
It's still possible to do this with various-width tabs: just make sure every line will fit into an 80-character screen using <some tab length, perhaps 2 or 4> and then people using an 80-character viewport can just set their tab width to that width.
- Znapi
-
Scratcher
500+ posts
Space vs tab
@Znapi:You still will have other tools trying to use different tabs widths, and why use tabs if you are going to require certain tab widths anyways?
It's still possible to do this with various-width tabs: just make sure every line will fit into an 80-character screen using <some tab length, perhaps 2 or 4> and then people using an 80-character viewport can just set their tab width to that width.
- TheMonsterOfTheDeep
-
Scratcher
1000+ posts
Space vs tab
But you don't require certain tab widths. You simply require that your code is compatible with one particular tab width, and everybody who has the option and desire to use a different one can.@Znapi:You still will have other tools trying to use different tabs widths, and why use tabs if you are going to require certain tab widths anyways?
It's still possible to do this with various-width tabs: just make sure every line will fit into an 80-character screen using <some tab length, perhaps 2 or 4> and then people using an 80-character viewport can just set their tab width to that width.













