| Author |
Message |
caker
Joined: 15 Apr 2003
Posts: 2371
Location: Galloway, NJ
|
| Posted: Sat Mar 24, 2007 12:38 am Post subject: Spaces or tabs in your code |
|
|
For those coders/developers out there: spaces or tabs?
-Chris |
|
| Back to top |
|
andrewjw
Joined: 30 Aug 2005
Posts: 28
|
| Posted: Sat Mar 24, 2007 8:08 am Post subject: |
|
|
| Definitely spaces. It gives you more flexibility to line your code up, without having to mix tabs and spaces. |
|
| Back to top |
|
c1i77
Joined: 23 Sep 2004
Posts: 68
Location: Delft, Netherlands
|
| Posted: Sat Mar 24, 2007 10:06 am Post subject: |
|
|
I was a 4-space softtab (my ~/.vimrc had sts=4) until I read the coding style guidelines from some guy named Linus Torvalds:
Quote:
Chapter 1: Indentation
Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.
Rationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you've been looking at your screen for 20 straight hours, you'll find it a lot easier to see how the indentation works if you have large indentations.
Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.
In short, 8-char indents make things easier to read, and have the added benefit of warning you when you're nesting your functions too deep. Heed that warning.
...
Read the rest of the very short document at http://pantransit.reptiles.org/prog/CodingStyle.html
Cliff |
|
| Back to top |
|
orsic
Joined: 16 Mar 2007
Posts: 3
Location: Montreal, Canada
|
| Posted: Sat Mar 24, 2007 3:55 pm Post subject: |
|
|
Same here, I use vim with the space option, more flexible and from what I know, using tabs may be a problem in some languages.
c1i77 wrote: I was a 4-space softtab (my ~/.vimrc had sts=4) until I read the coding style guidelines from some guy named Linus Torvalds:
Quote:
Chapter 1: Indentation
Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.
Rationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you've been looking at your screen for 20 straight hours, you'll find it a lot easier to see how the indentation works if you have large indentations.
Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.
In short, 8-char indents make things easier to read, and have the added benefit of warning you when you're nesting your functions too deep. Heed that warning.
...
Read the rest of the very short document at http://pantransit.reptiles.org/prog/CodingStyle.html
Cliff |
|
| Back to top |
|
Deckert
Joined: 24 Mar 2007
Posts: 42
Location: South Africa
|
| Posted: Sat Mar 24, 2007 5:20 pm Post subject: Spaces! |
|
|
Definitely spaces. Makes the code look the same in every editor you edit with and you don't have to mess with setting tab stops first.
I have much respect for Linus Torvalds, but his guidelines are for use in the Linux kernel, and using C as the language.
Also, the editors I use all have indentation highlighting (dotted lines, or whatever) to enable very quick and easy distinction of code segments.
--deckert |
|
| Back to top |
|
smiffy
Joined: 23 Jan 2007
Posts: 66
Location: 80 miles from Adelaide, Australia
|
| Posted: Tue Mar 27, 2007 2:03 am Post subject: |
|
|
Until recently, I have used tabs, but am beginning to move to spaces a) because other people are now looking at/using my code b) it is specified for Drupal module contributions and c) when I have about 10 levels of indent, it's nice not to have to everything wrapping to the next line.
And I use vim, BTW. |
|
| Back to top |
|
sweh
Joined: 13 Apr 2004
Posts: 227
|
| Posted: Tue Mar 27, 2007 8:27 am Post subject: |
|
|
Spaces, because TABs may not cut'n'paste properly so code can end up as a mixture of both.
(Yes, this can cause problems with sendmail and syslog which use TAB as the seperator....) |
|
| Back to top |
|
NecroBones
Joined: 16 Mar 2004
Posts: 110
Location: Sterling, VA
|
| Posted: Tue Mar 27, 2007 3:39 pm Post subject: |
|
|
Tabs all the way, because I add code more than anything else, and it's simply faster and easier. On the occasion that I need to cut and paste (not often since I usually yank and paste in vi), I just use a regex to re-tab the lines.
I agree with Mr. Torvalds on this one, and I don't have the 80-column problem since I use a minimum of 120 columns in my terminals, often more. :) |
|
| Back to top |
|
gsf
Joined: 07 Dec 2005
Posts: 13
Location: Philadelphia, PA
|
| Posted: Wed Mar 28, 2007 2:45 pm Post subject: spaces it is |
|
|
| I do most of my coding in python, where the mixing of tabs and spaces causes havoc, and the majority opinion points toward spaces. |
|
| Back to top |
|
OverlordQ
Joined: 04 Jun 2004
Posts: 200
|
| Posted: Sun Apr 08, 2007 5:04 am Post subject: |
|
|
Tabs only.
Nothing is more aggravating then having to delete individual spaces to make things readable when a single stroke to remove that tab would be quicker.
That and tab is one keystroke :)
And no I'm not using those spawns of Satan called vi or emacs or any of their bastard children like vim |
|
| Back to top |
|
cz9qvh
Joined: 19 Jan 2008
Posts: 14
|
| Posted: Thu Jan 24, 2008 2:03 pm Post subject: |
|
|
| I use tabs exclusively at the beginning of each line and spaces to align code at any point after the first non-tab character. The advantages of tabs at the beginning of a line are being overlooked in this thread, i think. The size of a tab can be redefined so when you are reading code that is indented umpteem times, you can set it to 2 or 3, and when reading code that doesn't use many blank lines, you can increase it to 8 or so to speed up visual scans of code. As long as you use the spaces to format tables or arrays or etc. then you won't get the wierd unaligned column problems that often accompany resizing tabs. |
|
| Back to top |
|
hwilliams
Joined: 25 May 2004
Posts: 18
Location: Newnan, Georgia
|
| Posted: Thu Jan 24, 2008 2:41 pm Post subject: |
|
|
I've been programming mostly in straight C for 28 years and the answer is spaces, spaces, spaces...
EXCEPT you sure better be careful on those hand full of ascii configuration files (makefile is probably the best example) that require tabs only for white spaces. I shutter to think how many total man hours have been lost through the years due to this one issue.
Hal Williams |
|
| Back to top |
|
TofuMatt
Joined: 21 Feb 2008
Posts: 6
|
| Posted: Thu Feb 21, 2008 10:47 pm Post subject: |
|
|
I prefer tabs, but I can deal either way. In Python I used to use spaces more, but now it's mostly tabs.
I hate it when they get mixed. Ewwww... |
|
| Back to top |
|
FunkyRes
Joined: 02 Oct 2008
Posts: 31
|
| Posted: Fri Oct 03, 2008 7:28 am Post subject: |
|
|
Spaces.
I use two spaces for most things.
I use four for php - but I usually write php in a nice gui editor (bluefish) - in vi in a 80 character wide xterm, 2 spaces is plenty. |
|
| Back to top |
|
michiel
Joined: 15 Jul 2008
Posts: 1
Location: Manchester, UK
|
| Posted: Fri Oct 03, 2008 8:06 am Post subject: |
|
|
spaces, definitely spaces.
my ${HOME}/.vimrc uses a 4 spaces soft tab stob. which in my opinion works a lot better than a tab :) |
|
| Back to top |
|
| |