![]() |
Indentation styles for namespaces?
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 . |
Re: Indentation styles for namespaces?
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 |
Re: Indentation styles for namespaces?
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 |
Re: Indentation styles for namespaces?
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] |
| All times are GMT. The time now is 08:52 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.