To an extent, assuming names are sensible. Personally I'd use var everywhere if it was just myself, but when working on a team I need to assure everybody can figure it out quickly.
Aside from the C++ lambdas item, these all seem like very sensible rules to apply to Java code. Indeed, they seem well aligned with some of the discussion here:
Java, as I recall, doesn't allow you to capture closures with type inference - at least it didn't with Java 8 and Lombok - you had to capture it with an appropriate delegate type. C++ can capture it with with std::function by signature, but otherwise lambdas have anonymous types so inference is required somewhere - std::function infers the type via template argument type.
Java and C# closures work a bit differently, so the rules operate differently.
There's a seperate rule that I apply to C++ and C# - if the function is templated/generic and you provide the return type as an argument, I capture with type inference. I don't like writing the type twice.
Since Java is more flexible and can infer generic arguments on one side of an expression, it isn't as needed there.
4
u/Programmdude Sep 16 '20
To an extent, assuming names are sensible. Personally I'd use var everywhere if it was just myself, but when working on a team I need to assure everybody can figure it out quickly.