The guideline should be “perfection is attained, not when there is nothing more to add, but when there is nothing more to take away.”
I largely agree with this sentiment. This is also why I am particularly opposed to changes like
impl Trait in argument position.
We now have 3 syntaxes to do exactly the same thing:
fn my_func(x: impl MyTrait)
fn my_func<T: MyTrait>(x: T)
fn my_func<T>(x: T)
where T: MyTrait
This feels incredibly redundant. It is useless complexity in the language. Beginners have to learn multiple ways of doing the same thing.
I personally find the
where syntax to be the best. It allows expressing trait bounds of arbitrary complexity without cluttering up the function signature. They are not sprinkled all over the argument list of the function, but rather clearly grouped and listed afterwards. It also has the highest level of flexibility; both of the other syntaxes have practical limitations that the
where syntax does not.
Even for a single type parameter (as in the example above), I think it looks very clean and elegant. I think it is the most readable of the three.
I think all the other syntaxes are redundant and useless and should be removed (not possible due to stability guarantees).
I personally use it universally throughout my code, because I believe it is the right thing to do. I do not use the other syntaxes, since they are semantically equivalent, but either less readable (inline trait bounds at the definition of the type parameter) or have other limitations (
Of course, it requires a little more typing. However, most of the software development time is spent thinking, not typing. Also, it is far more important for code to be easier and clearer to read, than to be quick to write. I am personally very much against this whole idea of “shaving characters”. Introducing any language changes purely because you are too lazy to type a few extra characters is a bad decision IMO.
This might seem a little hypocritical at first glance, since I love the
? operator syntax. However, the main benefit that I see is not the fact that it is a single character, but rather that it makes code clearer and more readable (being a postfix operator, as opposed to
try!) with no downsides. Hence, it goes along well with my philosophy that I outlined previously and is not hypocritical.