Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Finalizing more naming conventions #430

Closed

Conversation

aturon
Copy link
Member

@aturon aturon commented Nov 3, 2014

This conventions RFC tweaks and finalizes a few long-running de facto
conventions, including capitalization/underscores, and the role of the unwrap method.

See this RFC for a competing proposal for unwrap.

Rendered

Note: Though marked as closed, this RFC was in fact accepted.

| General constructors | `new` or `new_with_more_details` |
| Conversion constructors | `from_some_other_type` |
| Local variables | `snake_case` |
| Static variables | `SCREAMING_SNAKE_CASE` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants as well, right?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should consider CamelCase for constants, since SCREAMING_SNAKE_CASE is extremely abrasive to look at and it more clearly demonstrates the difference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there are precedents in both directions here, and I'm not sure it's clear that we should draw a distinction between these two kinds of variables.

Looking around, we've got:

I'll also point out that "SCREAMING_SNAKE_CASE" is abrasive probably because it has the word "screaming" in all caps. Something like MAX_WIDTH vs MaxWidth seems less abrasive to me

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to use enums to represent keys in a termbox-like console input library, but it turns out that Ctrl-I and Tab keys map to the same escape sequence so I'll have to use CTRL_I and TAB instead of CtrlI and Tab now if I want to use it in a match :(

@glaebhoerl
Copy link
Contributor

I think consts (as opposed to statics) should be CamelCase. Two reasons: lines up with enum variants, which they are semantically most similar to, and we can say that CamelCase is for "compile-time (known) things" (which types and constants both fall under).

@brendanzab
Copy link
Member

Yup. I agree with @glaebhoerl on this. Either that or make variants screaming, but I don't think anyone wants that!

@arcto
Copy link

arcto commented Nov 3, 2014

I agree with @glaebhoerl in that constants and enum variants should share the same CamelCase. After all, enum variants are a kind of constant.

I think it's fair though that static variables stand out (using SCREAMING_SNAKE_CASE). They are a different beast -- especially mutable ones.

@glaebhoerl
Copy link
Contributor

That's the other idea I was going to float... perhaps it might make sense to distinguish mutable statics from immutable ones. Meaning that: we use normal snake_case for statically allocated immutable data (which is totally harmless), just like lets, and SCREAMING_SNAKE_CASE for both static muts and plain statics with any kind of interior mutability ("global mutable state, oh my!").

@brson
Copy link
Contributor

brson commented Nov 3, 2014

This discusses acronyms in camel case but not snake case: e.g. is_XID_Start should probably be is_xid_start.

@netvl
Copy link

netvl commented Nov 5, 2014

Especially big +1 for unwrap()/into_inner() convention. I think it is much better than renaming unwrap() on Option/Result.

@thepowersgang
Copy link
Contributor

Just to leave my two cents on the topic of statics. I'm all for "screaming case" (Caps) for constants, but for interior mutable data (StaticMutex) using snake case would be preferable. [Similar to @glaebhoerl's comment]

@glaebhoerl
Copy link
Contributor

(That's actually the reverse of my comment.)

@nikomatsakis
Copy link
Contributor

Isn't the convention not new_with_more_details but rather with_more_details?

@aturon
Copy link
Member Author

aturon commented Nov 18, 2014

@nikomatsakis

Isn't the convention not new_with_more_details but rather with_more_details?

Good catch! This was leftover from the original wiki that I started with. I will update.

@brson
Copy link
Contributor

brson commented Nov 18, 2014

Accepted. Discussion. Tracking.

@brson brson closed this Nov 18, 2014
@brson
Copy link
Contributor

brson commented Nov 18, 2014

Accidentally rebased this instead of merged.

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Nov 22, 2014
This change applies the conventions to unwrap listed in [RFC 430][rfc] to rename
non-failing `unwrap` methods to `into_inner`. This is a breaking change, but all
`unwrap` methods are retained as `#[deprecated]` for the near future. To update
code rename `unwrap` method calls to `into_inner`.

[rfc]: rust-lang/rfcs#430
[breaking-change]

Closes rust-lang#13159
cc rust-lang#19091
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Nov 23, 2014
This change applies the conventions to unwrap listed in [RFC 430][rfc] to rename
non-failing `unwrap` methods to `into_inner`. This is a breaking change, but all
`unwrap` methods are retained as `#[deprecated]` for the near future. To update
code rename `unwrap` method calls to `into_inner`.

[rfc]: rust-lang/rfcs#430
[breaking-change]

Closes rust-lang#13159
cc rust-lang#19091
bors added a commit to rust-lang/rust that referenced this pull request Nov 25, 2014
This change applies the conventions to unwrap listed in [RFC 430][rfc] to rename
non-failing `unwrap` methods to `into_inner`. This is a breaking change, but all
`unwrap` methods are retained as `#[deprecated]` for the near future. To update
code rename `unwrap` method calls to `into_inner`.

[rfc]: rust-lang/rfcs#430
[breaking-change]

cc #19091
mzabaluev added a commit to mzabaluev/rust-c-str that referenced this pull request Nov 25, 2014
Apply conventions described in [Rust RFC 430][rfc]
where `unwrap` is reserved for panicing methods.

[rfc]: rust-lang/rfcs#430
djrenren pushed a commit to djrenren/libtest that referenced this pull request Jan 22, 2019
This change applies the conventions to unwrap listed in [RFC 430][rfc] to rename
non-failing `unwrap` methods to `into_inner`. This is a breaking change, but all
`unwrap` methods are retained as `#[deprecated]` for the near future. To update
code rename `unwrap` method calls to `into_inner`.

[rfc]: rust-lang/rfcs#430
[breaking-change]

Closes #13159
cc #19091
@gorilskij gorilskij mentioned this pull request Jul 10, 2019
@chpiatt
Copy link

chpiatt commented Oct 12, 2019

Just came here to point out that ThisNamingConvention is more accurately referred to as Pascal Case. In the documentation you refer to it as Camel Case, which more commonly follows thisPattern.

@gomesalexandre
Copy link

Hey, just came here to state the same thing as @Pyython. You refer to PascalCase as CamelCase, while camel casing has the first letter not capitalized(camelCase).
Any chance of modifying it in the docs? 🙏

@nikomatsakis
Copy link
Contributor

By docs, do you mean the RFC? Ideally, we'd have these docs living somewhere else and update there, but I'm not sure if they do. We don't generally modify the text of RFCs heavily after they're landed, prefering to keep more stable docs up to date.

@shepmaster
Copy link
Member

shepmaster commented Jan 13, 2020

This has already been addressed by #2389 and your duplicate issue #2849.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.