If you use the feature, and I refactor later because your design was inadequate to today's problem, it is a language problem.
Without your change, I attempt my refactor, and the compiler complains that I've made a mistake - it's unambiguous to the compiler that I've got it wrong, because I've got a type error - and this applies even if you use the use RadioConfig::*
trick to allow you to write set_wifi_state(RadioConfig::Disabled)
as set_wifi_state(Disabled)
. With your suggested change, the compiler sees a correct variant of my new WifiConfig
enum, and doesn't flag up to me that I've missed a spot.
This is fundamental to anything that makes things more implicit - you need only spend time on users.rust-lang.org to see users getting surprised when the various lifetime elision rules result in a lifetime surprising them - for example, the following generates a lifetime error that people get surprised by (playground link:
fn box_it<T: Trait>(it: T) -> Box<dyn Trait> {
Box::new(it)
}
The explanation for the error is simple; this function has an implicit lifetime, and is in fact a short-hand way of writing:
fn box_it<T: Trait>(it: T) -> Box<dyn Trait + 'static> {
Box::new(it)
}
But even this level of implicitness is confusing to some people - because while the compiler error suggests a fix (changing the bound from T: Trait
to T: Trait + 'static
), it doesn't explain why it suggests that change, or how you'd fix it if you wanted to allow it
to be bounded by an arbitrary lifetime instead of 'static
.
This is why I think this should be an IDE feature, not a language feature - my IDE of choice already knows how to add to what I'm typing (e.g. it knows to convert foo.letm
to let mut = foo
and put my cursor between the mut
and the =
), how to add in type inlays and display fn foo(&self) -> &str
as fn<'self> foo(&'self self) -> &'self str
, and it can also remove things from display - so it can display the code the way you want it, and make it easier to type.
Finally, "Also, If you don't want to use it, you don't have to." is not helpful - if anyone I collaborate with uses a language feature, I have to deal with it. If that's the only way you can handle an objection, then you're basically saying that the feature shouldn't be in the language because it can't be used at all.