[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Indentation
From:       Richard Smith <kde () metafoo ! co ! uk>
Date:       2005-03-05 15:52:33
Message-ID: 200503051552.33944.kde () metafoo ! co ! uk
[Download RAW message or body]

Hi,

On Saturday 05 March 2005 15:05, Anne-Marie Mahfouf wrote:
> So I would like to know what is the best way to indent, maybe to ensure
> something clean for most editors?

That's a very controversial subject. Here's my opinion:

If you want to use tabs, make sure you use them consistently (ie, be careful 
not to indent with spaces by mistake). The easiest way to do that is to turn 
on visual tabs in Kate. If you want to line text up on two adjacent lines, 
use the same number of tabs on both lines, and line up the rest of the way 
with spaces - this way the text will line up no matter what tab size your 
reader chooses. Only put tabs at the start of a line (otherwise using a 
different tab width will mean your text won't line up).

If you don't want to use tabs, make sure you use spaces consistently (ie, 
never insert a tab by mistake, and use the same number of spaces for every 
indent). You'll want to decide a project-wide indentation width and stick to 
it. Three or four spaces per indent are common.

If you want to mix tabs and spaces emacs-style (that is, 4 space indent, with 
8 consecutive spaces being represented by a tab), think very carefully about 
it. In particular, it won't work if someone has a different tab width to you.

For maximum friendliness to people reading my code, I prefer to indent with 
tabs, so they can decide how big an indent step is. It's marginally less 
trouble to use spaces than tabs, since you don't need to think about what 
happens if the reader's tab size is different (but on the other hand, 
thinking about other people reading your code is a good thing anyway).

Whatever you choose, you should look at the settings for your editor to make 
sure that it's doing what you want. Indenting with tabs or with spaces, as 
described above, ought to be possible in any decent source code editor (and 
is certainly possible in Kate, emacs, vi and joe, which I guess between them 
cover most KDE developers). So it really is up to you.

> I just need to understand why my indentation is bad.

It's your code, so of course you're free to format it however you like. 
Whoever mailed you probably meant that your indentation is inconsistent. In 
khangmanview.h, inside class KHangManView, I can see a few different styles 
of indentation (turn on visual tabs and/or change your tab width to make them 
obvious):

Your Q_OBJECT, constructor, destructor are indented 4 spaces.
Most of the rest of the class is indented 1 tab.
Four lines are indented 8 spaces.
Five lines are indented four spaces then one tab.
One line is indented one space then one tab.

Any of the first three used consistently would not raise many eyebrows (though 
8 space indents are quite big). The fourth and fifth are a bit unusual, as is 
mixing them.
-- 
Thanks,
Richard
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic