# Non-snake case: variables vs functions

**URL:** <https://internals.rust-lang.org/t/non-snake-case-variables-vs-functions/1479>\
**Category:** Uncategorized\
**Created:** [January 29, 2015, 2:17pm UTC](https://internals.rust-lang.org/t/non-snake-case-variables-vs-functions/1479 "2015-01-29T14:17:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhardy](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dhardy/32/2399_2.png) [@dhardy](https://internals.rust-lang.org/u/dhardy)\
**Post date:** [January 29, 2015, 2:17pm UTC](https://internals.rust-lang.org/t/non-snake-case-variables-vs-functions/1479/1 "2015-01-29T14:17:44Z")

</div>

There is an annotation to disable the “snake case” lint:

```
#[allow(non_snake_case)]
fn FunnyFunctionName(){
    let Y = 2.4;
    ...
}

```

but that is a little crude in it’s application. (It is invalid, for example, to use the annotation directly on a local variable within the function.)

## Proposal

Add two new annotations, `non_snake_case_fn`, `non_snake_case_var` (or even three: `non_snake_case_fn`, `non_snake_case_let`, `non_snake_case_param`). These can be used to turn off the “snake case” lint (or lints) in specific cases.

## Motivation

In a few cases I find it reasonable to use non-snake-case names: when **copying equations** from a scientific/mathematical article (sometimes referencing an external work is much easier than documenting everything in the code), when **using acronyms** (in this case it’s debatable whether or not the acronyms should be converted to lower case). And sometimes odd other cases (though mostly temporary).

Usually, however, these are localised exceptions from the norm, and I’d like to use standard names elsewhere, hence `#[allow(non_snake_case)]` is a bit of a blunt tool.

## Examples

Use of an acronym in a function name:

```
[#allow(non_snake_case_fn)]
fn special_func_ABC(...) {...}

```

I’m not even sure if the above should be allowed by default (so long as the first letter is lower-case and every capital letter follows an underscore or another capital letter).

A function using more mathematical syntax for variable names:

```
[#allow(non_snake_case_var)]
fn compute(x: f64) -> f64 {
    let X1 = ...;
    let a = ...;
    let Z = ...;
    ...
}

```

## Alternatives

The status quo: all or nothing (apply `[#allow(non_snake_case)]` at the function/module/project level).

---

<div class="post-metadata">

**Author:** ![P1start](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/p1start/32/23_2.png) [@P1start](https://internals.rust-lang.org/u/P1start)\
**Post date:** [January 29, 2015, 10:38pm UTC](https://internals.rust-lang.org/t/non-snake-case-variables-vs-functions/1479/2 "2015-01-29T22:38:53Z")

</div>

We originally had separate `non_snake_case` lints for functions and variables, but in [PR #15773](https://github.com/rust-lang/rust/pull/15773) I consolidated them into a single lint at the request of the devs. I personally much prefer the current approach, but given that we have lint groups (added in the same PR) I guess we could make `non_snake_case` a lint group that encompasses `non_snake_case_variables`, `non_snake_case_functions`, `non_snake_case_modules` etc., allowing for both fine-grained control _and_ ease of use in cases where you don’t need precise control, all in a backwards-compatible manner. That said, I see little reason to separate these lints—the motivation given isn’t really enough in my opinion to warrant such a change.

(I believe that acronyms should always be lowercase in snake case names, much like how they must be capitalised `Abc` in camel case names.)

---

<div class="post-metadata">

**Author:** ![DanielKeep](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/danielkeep/32/1332_2.png) [@DanielKeep](https://internals.rust-lang.org/u/DanielKeep)\
**Post date:** [January 30, 2015, 3:02pm UTC](https://internals.rust-lang.org/t/non-snake-case-variables-vs-functions/1479/3 "2015-01-30T15:02:55Z")

</div>

I thought there was something in the works in regards to allowing annotations in arbitrary places. Wouldn’t that be an even better solution? 😛

I remember shoving a heap of code into an inner function in a macro expansion once, just so I could attach annotations to the code: I had warnings leaking out of the macro expansion that I couldn’t turn off otherwise.

---

<div class="post-metadata">

**Author:** ![tbu](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tbu](https://internals.rust-lang.org/u/tbu)\
**Post date:** [January 30, 2015, 9:29pm UTC](https://internals.rust-lang.org/t/non-snake-case-variables-vs-functions/1479/4 "2015-01-30T21:29:08Z")

</div>

There was something in the works for allowing attributes everywhere. Note that this does not necessarily include specifying lint behavior everywhere.

---

<div class="post-metadata">

**Author:** ![P1start](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/p1start/32/23_2.png) [@P1start](https://internals.rust-lang.org/u/P1start)\
**Post date:** [January 31, 2015, 7:35am UTC](https://internals.rust-lang.org/t/non-snake-case-variables-vs-functions/1479/5 "2015-01-31T07:35:40Z")

</div>

That’s [RFC 16](https://github.com/rust-lang/rfcs/blob/master/text/0016-more-attributes.md), which hasn’t yet been implemented (but has been accepted). I suspect that after 1.0 (as with a lot of things) someone might get around to implementing it. I agree that that’s a better solution, though, but we might have to wait.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:23am UTC](https://internals.rust-lang.org/t/non-snake-case-variables-vs-functions/1479/6 "2019-03-25T08:23:47Z")

</div>

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