|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
View Poll Results: Which is best to use in source code - Tabs or Spaces? | |||
Tabs | 7 | 28.00% | |
Spaces | 18 | 72.00% | |
Voters: 25. You may not vote on this poll |
|
Thread Tools | Display Modes |
|
|||
Tabs or Spaces?
Hello,
Which is best to use in source code - tabs or spaces?
__________________
And the WORD was made flesh, and dwelt among us. (John 1:14) |
|
|||
Some time ago, I read that some apps do things differently when using tabs vs spaces. YAML, a file layout method, counts indent spaces which are significant. So some people, me included, always have tabs converted into spaces.
|
|
||||
+1
Some editors/IDEs like geany has an option to convert tabs to spaces every time you save a file, I also generally always use spaces instead of tabs, this way you are sure that code will be formatted the way you wanted to
__________________
religions, worst damnation of mankind "If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”. vermaden's: links resources deviantart spreadbsd |
|
||||
I use tab to spaces as well.
I have one ide I use for python that even though it looks like when you hit TAB you get the same indentation. When at the column number in the status bar, one column will read as 15 and the column on the line below will read as 17. So when you open it in another editor its all screwed up.
__________________
"The basic tool for the manipulation of reality is the manipulation of words. If you can control the meaning of words, you can control the people who must use the words." -Philip K. Dick |
|
|||
Wow, How is tabs losing? a single tab indentation takes "1" byte compared to the alternative of 4/8 space characters.
It also helps make files look uniform in text editors... if any of you looked at BSD source, you would see they whole heartedly agree. |
|
||||
Tabs for code ... always, it just works a lot better across different editors, people can set their own tabwidth, it's easier to move the cursor.
I never understood why some people use spaces for code .... For text/config files that other people need to use I use spaces for obvious reasons.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. |
|
||||
Spaces help code to look more uniform from platform to platform. It's hard to keep the tabs/space convention when you are working with a few developers working on different platforms/editors too.
I guess what is more important than choosing between tabs or spaces is sticking to it and making sure everyone follows the convention!
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." |
|
||||
Well, this is something I am only mildly opinionated on believe it or not !!!
When it comes to things like tabs or spaces, where to put the brace, etc of coding style. I don't really care what _other_ people do as long as they _do_ it consistently. I'm accustomed to writing code in a manor that I could write rule-sets based on my formating style to modify things if necessary, and where possible in a style that can hold up to my changing tastes. When it comes to tabs or spaces for indentation, I use both but in different ways. I prefer tabs when individual indentation levels are 'thick', for example I typically use an 8-space tabstop setting for C or C++ code. For that I find tabs easier to work with then spaces. But when the indents are smaller (e.g. 2-4 spaces) I'll normally use spaces, if it's a moderate level (4sp) I'll pick either tabs or spaces for a given language and stick with it. For example, I use a 4 space tabstop for Perl but 4 spaces for Python. The thing that makes me some what different, is when I use tabs for indents -- I use spaces for whitespacing. Code:
void foo_funct() { char *src, *dst; int reallylong; long int arglist; size_t size; ... while ((var = bar_func(src, dst, size, tab | spaces reallylong, arglist)) != whatever) { if (var == something) { do_whatever(var); } } } That way I can change the tabstop from being 2, 4, 6, 8, 10, 12, whatever is desired and the code will still be 'logically' aligned rather then out of order. The way I write changes from time over the years, I do however take sometime when using a language a lot. To sit down and play with formating and find "what works for me". Some of my idiosyncrasies in style are connected to my ways of thinking but most have a solid reason behind it, that I feel is worth while if ones going to do it consistently. Note: where logically aligned is defined as how I feel it is logical to align it. I also have an 80-90x25-35 cols by lines editor to use most times and I limit lines to < 70-80char by nature. Generally I do find spaces easier to work with when using most editors 'autoindent' capabilities.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
|
||||
well, being that I'm coding more in python and tal/dtml these days, I knee-jerked spaces.. because the levels of indentation make tabs unfeasible and python source tends to cause fits when tabbed and not spaced. That being said, this question is highly subjective.
__________________
perl -e "eval pack(q{H*}, join q{},qw{7072696e74207061636b28717b482a7d2c717b34393 23036333631366532303666366536633739323036313733373 33735366436353230373936663735323036353738373036353 63337343635363432303734363836393733323037343666323 03632363532303631323036633639373437343663363532303 66436663732363532303635366537343635373237343631363 93665363936653637326530617d293b})" |
|
|||
Hello,
In vim, you can convert tabs to spaces - that is when you press tab it inserts x number of spaces (x based on other settings) - with: set expandtab or set et Does anyone know how to do this in (n)vi?
__________________
And the WORD was made flesh, and dwelt among us. (John 1:14) |
|
||||
Code:
:set shiftwidth=4 And indent lines with ^T or >> instead of 'tab' -- autoindent will respect this in OpenBSDs nvi *if* the indent is equal to sw but not ts, it will however use tabs to fill it up (e.g. two 'shiftwidths' gets a tab). I don't think nvi will let you remap the tab key but one could always modify their terminal/console so pressing tab sends the same thing as control+t I guess. PS if you leave tabstop set to default 8 while using shiftwidth spaces to indent, you will be able to tell when unwanted tabs creep into your file.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. Last edited by TerryP; 18th June 2008 at 09:51 PM. |
Tags |
vim |
|
|