Don't indent inline modules

#1

This is the C++ style I (and most others?) use:

namespace foo { namespace bar {
void baz();
}} // namespace foo::bar

The equivalent in Rust would be:

pub mod foo {
pub fn bar() { /* ... */ }
} // mod foo

This is similar to jQuery not indenting the body of the top-level RequireJS function.

0 Likes

#2

I wouldn’t particularily like this inconsistency for a little bit less indentation.

3 Likes

#3

It was just a thought. The fact that Rust also has file level modules makes this somewhat unnecessary. Having said that, one extra level of indentation often bites you in the end (especially with a 80 character limit).

0 Likes

#4

Also, I would like to add that in the middle of the file, you cannot find the difference between a module function or a function attached to the files main module

0 Likes

#5

This is one of the many things I don’t particularly like about C++. It makes it very difficult to see when the module ends.

0 Likes

#6

Also, this doesn’t really fit with Rust anyway, because each file is its own module. In C++, I’ve usually seen this style used when most of/the entire file is wrapped in a namespace, which Rust does automatically for you.

1 Like

#7

This C++ style only exists because of the extreme prevalence of a single namespace {} block covering the entire contents of the file. Normally, any nested namespace {} blocks do in fact get indented. Your first code example is something I’ve personally never seen in a C++ codebase.

And FWIW, even that really common style doesn’t play well with any sort of IDE that has auto-indentation. Even Xcode, which I have to assume is used a fair amount for C++, wants to indent the entire namespace.

Inline modules are not common enough in Rust (especially multiple levels of inline modules) to make it worth trying to reduce the indentation.

0 Likes

#8

[quote=“As eridius, post:7, topic:94”] Inline modules are not common enough in Rust (especially multiple levels of inline modules) to make it worth trying to reduce the indentation. [/quote] … and when inline modules are used I think it’s important to make that visually stand out with the indentation.

0 Likes

#9

Normally, any nested namespace {} blocks do in fact get indented.

No they don’t. Take a look at LLVM, protobuf, Cinder, Chromium, V8…

Even Xcode, which I have to assume is used a fair amount for C++, wants to indent the entire namespace.

Yeah. I wouldn’t call that a feature though. :smiley: Xcode indents access modifiers too, even though most people don’t want that either.

Just to recap, I basically agree with you. Just a thought.

0 Likes

closed #10

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

0 Likes