Re:Tests aren’t enough: Case study after adding type hints t...
by lamontcg on Monday October 18, 2021 @04:51PM
(#28911556)
I'm okay with "var = new FooBarBazThingyWithALongName()" because I don't need to see the type name twice there.
In an IDE you can get the type annotation from the IDE over every inferred var type, but I don't like requiring an IDE to see that information and like it showing up in 'less' as well.
Re:Tests aren’t enough: Case study after adding type hints t...
by layer8 on Monday October 18, 2021 @05:02PM
(#28911685)
I agree it's redundant if the type name occurs twice in the same statement. However, further evolution of the code often causes the instantiation to be moved elsewhere, and I wouldn't have confidence that the one doing that change then also changes `var` back to the type name. Instead, it would be nice to have syntax avoiding the duplication in the fashion of `FooBarBazThingyWithALongName thingy = new(...constructor parameters...);`.
Re:Tests aren’t enough: Case study after adding type hints t...
by Serow225 on Monday October 18, 2021 @06:12PM
(#28912483)
C# 9 now has "target-typed new expressions"
https://www.thomasclaudiushuber.com/2020/09/08/c-9-0-target-...
Re:Tests aren’t enough: Case study after adding type hints t...
by lamontcg on Monday October 18, 2021 @10:16PM
(#28914148)
Ideally linting tools on PRs show the refactored code as a violation, and it should be easy to rip a cleanup refactoring across the files before submitting a PR to avoid that.
Re:Tests aren’t enough: Case study after adding type hints t...
by dmart on Monday October 18, 2021 @02:52PM
(#28909793)
Yeah, when writing type inference is obviously nice, but it can be annoying to try to go back and read.
I think the best experience is having a language server annotate the inferred types (like how rust-analyzer does it.) But even then, it can become hard to read code on GitHub or somewhere where tools are not available. Granted that's becoming less and less of a problem, and even GitHub allows using some VS Code extensions now.
Re:Tests aren’t enough: Case study after adding type hints t...
by layer8 on Monday October 18, 2021 @03:05PM
(#28910039)
With good IDE support, writing types isn’t that much of a burden. Either write a function call first and use "assign return value to new variable", or use autocompletion where you only type the initials of a multi-word type name. Plus IDE refactoring actions when a parameter or return type needs to be changed.
For the same reason, I’m not a fan of type-inferring variable declarations.