Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #11434 > unrolled thread
| Started by | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| First post | 2011-11-13 21:29 +0000 |
| Last post | 2011-11-17 08:15 +0900 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.c++
Indentation styles for namespaces? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-11-13 21:29 +0000
Re: Indentation styles for namespaces? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2011-11-14 00:39 +0100
Re: Indentation styles for namespaces? drew@furrfu.invalid (Drew Lawson) - 2011-11-18 18:09 +0000
Re: Indentation styles for namespaces? Marcel Müller <news.5.maazl@spamgourmet.com> - 2011-11-14 10:14 +0100
Re: Indentation styles for namespaces? Miles Bader <miles@gnu.org> - 2011-11-17 08:15 +0900
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2011-11-13 21:29 +0000 |
| Subject | Indentation styles for namespaces? |
| Message-ID | <slrnjc0dmk.1bk.grahn+nntp@frailea.sa.invalid> |
I hope this doesn't turn into an argument. I had these header files
at work, where I had most of the contents in a namespace:
/* foo.h */
namespace foo {
stuff;
pages_of_stuff;
...
}
Quite a few pages of that, and everything inside the namespace
indented. Then others took over the code, and when I revisited it last
week I noticed it had been reindented so the namespace content wasn't
indented:
/* foo.h */
namespace foo {
stuff;
pages_of_stuff;
...
}
My questions are simply:
- Do you people tend to indent in such cases?
- Is there some popular editor or IDE which prefers not to?
I can certainly understand that some feel the indent is a waste of
horizontal space, but it's really the way I (and my editor, Emacs)
prefer it.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
[toc] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Date | 2011-11-14 00:39 +0100 |
| Message-ID | <j9pkga$rq4$1@dont-email.me> |
| In reply to | #11434 |
On 13.11.2011 22:29, Jorgen Grahn wrote:
> I hope this doesn't turn into an argument. I had these header files
> at work, where I had most of the contents in a namespace:
>
> /* foo.h */
> namespace foo {
> stuff;
> pages_of_stuff;
> ...
> }
>
> Quite a few pages of that, and everything inside the namespace
> indented. Then others took over the code, and when I revisited it last
> week I noticed it had been reindented so the namespace content wasn't
> indented:
>
> /* foo.h */
> namespace foo {
> stuff;
> pages_of_stuff;
> ...
> }
>
> My questions are simply:
> - Do you people tend to indent in such cases?
Of course.
Perhaps the programmer in question had background from HTML?
> - Is there some popular editor or IDE which prefers not to?
No.
> I can certainly understand that some feel the indent is a waste of
> horizontal space, but it's really the way I (and my editor, Emacs)
> prefer it.
There is one thing though, don't let the parsing level command the
indentation level. For example, IMO, write
namespace a { namespace b { namespace c {
// blah
} } }
instead of
namespace a
{
namespace b
{
namespace c
{
// blah
}
}
}
It is only be similarity with conditionals that the latter may appear
more clear. But that similarity has only to do with outer form (namely
braces), not meaning. For namespaces, parsing-level indentation is just
impractical eye candy -- pretty to look at, until you run out of line.
Cheers,
- Alf
[toc] | [prev] | [next] | [standalone]
| From | drew@furrfu.invalid (Drew Lawson) |
|---|---|
| Date | 2011-11-18 18:09 +0000 |
| Message-ID | <ja6703$1214$1@raid.furrfu.com> |
| In reply to | #11439 |
In article <j9pkga$rq4$1@dont-email.me> "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> writes: >On 13.11.2011 22:29, Jorgen Grahn wrote: >> - Is there some popular editor or IDE which prefers not to? > >No. The previous-block and next-block movement shortcuts in vi look (by default, historically, ...) for the opening brace to be at the start of a line. But using those comes down to a user prefrence, not a preference of the editor itself. I don't like indenting namespaces in implimentation files because it amounts to indenting almost the entire file. It doesn't seem to serve a purpose. -- Drew Lawson I only came in search of answers, never planned to sell my soul I only came in search of something left that I could call my own
[toc] | [prev] | [next] | [standalone]
| From | Marcel Müller <news.5.maazl@spamgourmet.com> |
|---|---|
| Date | 2011-11-14 10:14 +0100 |
| Message-ID | <4ec0dbf9$0$7610$9b4e6d93@newsspool1.arcor-online.net> |
| In reply to | #11434 |
On 13.11.2011 22:29, Jorgen Grahn wrote: > My questions are simply: > - Do you people tend to indent in such cases? I prefer not to indent the content of public namespaces. The reason is simple: there is not benefit of doing so, except for the waste screen space, of course. One file should not contain more the one public namespace, so the indentation won't bring any further structure information. The package syntax of Java takes care of that. Things are a bit different with private implementation namespaces. They may only cover parts of a file, in which case indentation makes sense. > I can certainly understand that some feel the indent is a waste of > horizontal space, but it's really the way I (and my editor, Emacs) > prefer it. Who cares, what /your/ editor prefers? In fact, if you are working in a team, no one must format entire documents. If you do so, the you need to agree to the same formatting rules up to the last blank. This implies that all of you use exactly the same tools with the same settings. Otherwise you will get tons of merge conflicts, which is most likely not what you intended. On the other side, if your tools keep existing formatting of unmodified lines, and if you use tabs only in the front of a line, then you might use rather different settings without conflicts, including the tab size. You might configure your version control software to reject changes of existing source files where almost all lines are modified with a meaningful message. So the people that can't control their fingers or editors get their own problem. Marcel
[toc] | [prev] | [next] | [standalone]
| From | Miles Bader <miles@gnu.org> |
|---|---|
| Date | 2011-11-17 08:15 +0900 |
| Message-ID | <87aa7vmzfq.fsf@catnip.gol.com> |
| In reply to | #11445 |
Marcel Müller <news.5.maazl@spamgourmet.com> writes: >> I can certainly understand that some feel the indent is a waste of >> horizontal space, but it's really the way I (and my editor, Emacs) >> prefer it. > > Who cares, what /your/ editor prefers? You can tell Emacs not to indent namespaces by putting: (add-to-list 'c++-mode-hook (lambda () (c-set-offset 'innamespace 0))) in your ~/.emacs file. More clever would be to add a hook that looks at the "namespace" line, and bases its decision to indent or not on some sort of context, e.g., if there's a comment saying "// noindent", it wouldn't indent (or the opposite if not indenting is more common). [Basically you write a lisp function, and use it's name in place of the "0" above; see the info node "(ccmode) c-offsets-alist" for details.] As such conventions often vary among _projects_, an altnerative would be to place an appropriate ".dir-locals.el" file in the root of source trees; see the info node "(emacs) Directory Variables" for details. -Miles -- Any man who is a triangle, has thee right, when in Cartesian Space, to have angles, which when summed, come to know more, nor no less, than nine score degrees, should he so wish. [TEMPLE OV THEE LEMUR]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web