You are not logged in.
Pages: 1
Topic closed
I tried to find some information about this in the forum, but I didn't succeed (perhaps I failed at the search). My apologies if this a trivial topic, but as I'm in the learning process of programming (I started with Python and php myself, and Pascal at college) this is a new world to me.
Yesterday I was editing a txt file in Vim, and I encounter a few issues trying to print it. That's when I learned that tabbing all the way thought to format some text maybe is not a good idea. Then a guy in #Vim directed me to use spaces instead of tabs for indenting and formating the text / programs that I write, as the tab indenting is -almost- only needed by makefiles. Also he showed me than in Python programming it is suggested to use spaces as well.
I googled a bit and I found sites like this, with pros and cons about both styles. Also I found a Vim plugin (Smart Tabs) that at first sight seems quite nice, like it have the best of both worlds.
So my question here is: what should I do? Choose one style and stick with it for ever? Choose according the language? Mix up both? Without any experience on this subject it's hard to know the right way, as it seems that both styles have (strong) advantages and disadvantages.
Also, if is not too much no ask, what tab size should I work with? 8 seems a bit large, although seems to be pretty standard for some languages.
Currently I've this on my .vimrc (the relevant part, of course):
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set autoindent
set smartindent
Thanks in advance for any advice.
Sorry for my English. Feel free to point out my errors.
Offline
I just always use 4 spaces. you can't go wrong with that in any editor.
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
> I just always use 4 spaces. you can't go wrong with that in any editor.
+1
... unless your team agreed on another settings.
Offline
take a look into adding some "autocmd" lines into your .vimrc
This will automatically set vim options based on the type of file you happen to be working on.
here's an example I found, seems pretty full featured.
http://github.com/bryanforbes/dotfiles/ … ster/vimrc
look at lines 57-101. I'm pretty sure this is what you are looking for.
Hofstadter's Law:
It always takes longer than you expect, even when you take into account Hofstadter's Law.
Offline
> I just always use 4 spaces. you can't go wrong with that in any editor.
+1
... unless your team agreed on another settings.
Then you change your team
Last edited by Inxsible (2010-07-15 14:28:32)
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
> Then you change your team
I never thought one can be so dogmatic wrt tab-spaces dilemma. ;-)
Offline
Yes, I think to "choose one style and stick with it" is the most important thing.
I always use two spaces to indent because I like the way it looks. Besides makefiles, I don't use any language that forces me to use either tabs or spaces, so that's not a problem.
I really like this quote:
If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.
(from Wikiquote) After reading that, I don't think about indentation as much anymore.
Sorry for my English. Feel free to point my errors.
"Sorry for my English. Feel free to point out my errors." ^_^
Offline
> Then you change your team
I never thought one can be so dogmatic wrt tab-spaces dilemma. ;-)
Double entendre.
Either make your team change the way they work...or actually change your team
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
Thanks you all for your replies, that was quick
I think I settle with 4 spaces indent. One final question: this should be commented in the source code (or be noted in any other way for that matter), or is totally irrelevant to someone else?
@drcouzelis: Thanks for pointing that out
Sorry for my English. Feel free to point out my errors.
Offline
> One final question: this should be commented in the source (...)
Cyrusm showed you a nice set of autocmds - autocmds are one of the ways people do it.
Offline
Oh, what I meant is that if I need to state in the source code that I'm using 4 spaces instead of tabs so anyone that read that source code is aware of that, or if that is unnecessary.
I'm sure I didn't explained myself, sorry about that.
Sorry for my English. Feel free to point out my errors.
Offline
One final question: this should be commented in the source code (or be noted in any other way for that matter), or is totally irrelevant to someone else?
Most projects have a HACKING file that explain their code standards.
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
> I'm sure I didn't explained myself, sorry about that.
You did and I think I understood you right.
autocmd BufRead,BufNewFile *.hs set et ts=2 sw=2 softtabstop=2
This one line may be enough. You put it in the haskell files you work on and they serve as meta-information about the formatting.
Offline
Thanks. That is what I tried to ask
I'll check some github projects for that file, that way I can learn how to do it. Thanks again to all of you
Sorry for my English. Feel free to point out my errors.
Offline
Oh, what I meant is that if I need to state in the source code that I'm using 4 spaces instead of tabs so anyone that read that source code is aware of that, or if that is unnecessary.
I'm sure I didn't explained myself, sorry about that.
I just tell my team to not mess with my code. I really do.
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
'll check some github projects for that file, that way I can learn how to do it. Thanks again to all of you
Here is an example from our very own pacman.git: http://projects.archlinux.org/pacman.git/tree/HACKING
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
Why would anyone use spaces?
Here's the ultimate advantage of tabs: Everyone can set his own preferred tab width.
Introducing Peter and Sven. Peter likes a 2 space indent because then a lot of code fits onto the screen. Sven prefers a 8 space indent because then the indenting is more visible. So what do they do? Exactly, they use tabs to indent. Sven sets his tab width to 8 spaces and Peter sets his to 2. Problem solved.
Offline
Why would anyone use spaces?
Because inevitably someone will use a combination of spaces and tabs for indentation and alignment and then everyone is confused. Tabs are fine, spaces are fine. Just don't use both.
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
Why would anyone use spaces?
Here's the ultimate advantage of tabs: Everyone can set his own preferred tab width.
Introducing Peter and Sven. Peter likes a 2 space indent because then a lot of code fits onto the screen. Sven prefers a 8 space indent because then the indenting is more visible. So what do they do? Exactly, they use tabs to indent. Sven sets his tab width to 8 spaces and Peter sets his to 2. Problem solved.
In my very short experience, using tabs screws up the text formatting when is opened in different editors. Generally not an issue if the line starts with tabs chars, but when there're tabs after some text (like <tab><tab><text><tab><text>). As I'm not a programmer myself, I don't know how ofter do you insert tabs after the text (maybe for comments or align some variables values or such?)
Sorry for my English. Feel free to point out my errors.
Offline
The reason I don't like tabs is because, even though Vim might know to render them as 4 spaces, cat/grep/sed/awk/perl and friends don't.
Offline
The problem I have with tabs is just that this:
int
some_long_function(some_really_long_declaration_that_forces_a linebreak,
<tab><tab><tab> other_parameter name)
{
will look totally different in another editor with a different tab size:
int
some_long_function(some_really_long_declaration_that_forces_a linebreak,
<longtab><longtab><longtab> other_parameter name)
{
EDIT: I guess it would be okay if you always used spaces for alignment like this, but most editors will insert tabs for you when you try to indent that line, possibly without you even noticing.
Last edited by tavianator (2010-07-16 17:05:37)
Offline
Or better, switch over to Whitespace. Then you will not confuse yourself .
I always used to indent code with tabs, but after reading that I will try to use spaces-only.
I'm also known as zmv on IRC.
Offline
Watermel0n wrote:Why would anyone use spaces?
Because inevitably someone will use a combination of spaces and tabs for indentation and alignment and then everyone is confused. Tabs are fine, spaces are fine. Just don't use both.
And there it is. There is truly nothing left to be added to this discussion that hasn't been discussed to death for many years.
rson451, thanks.
Offline
Pages: 1
Topic closed