←back to thread

498 points azhenley | 1 comments | | HN request time: 0.001s | source
Show context
bitwize[dead post] ◴[] No.45767911[source]
[flagged]
embedding-shape ◴[] No.45768025[source]
Eh, Rust is kind of "immutable by default" but not really enforcing that + "constants" in the way I think Carmack advocates for. Other languages does better in that regard. Examples: https://play.rust-lang.org/?version=stable&mode=debug&editio...
replies(1): >>45768257 #
jasonthorsness ◴[] No.45768257[source]
Yeah the encouragement of shadowing is a little weird (learning Rust coming from Go where it is sort of discouraged)
replies(1): >>45769864 #
1. tialaramex ◴[] No.45769864[source]
Discouraging shadowing in languages with unclear lifetimes makes plenty of sense.

Clippy offers lints for (three?) distinct ways of shadowing because in most cases it turns out people who don't like shadowing only had problems with typically one specific kind of shadowing (e.g. same type unrelated shadowing, or different type same value shadowing) and since that varies why not offer to diagnose the specific problem this programmer doesn't like.

To be concrete some people are worried about things like:

  let sparrows = get_a_list_of_sparrows();
  // ....
  let sparrows = sparrows.len() + EXTRA_SPARROWS;
Whereas for some people that seems fine but they're worried about:

   let sparrows = find_wild_sparrows();
   // ....
   let sparrows = find_farmed_sparrows();
These are both shadowing the name sparrows, and Rust is fine with either but Clippy can provide different lints so that you can ban one of them while using the other freely in your codebase.