3 ms·
Except that having the type info is really, really useful at the call site. I know the IDE is able to infer it and display it but it's still a pain to see all t
by abraxas 5y ago
Except that having the type info is really, really useful at the call site. I know the IDE is able to infer it and display it but it's still a pain to see all the vars during a code review in a browser.
- matt2000 5y agoAgree, it's a straight up reduction in code readability for all future maintainers so a single original developer can avoid doing a thing their IDE probably would do for them automatically. (I use "introduce variable" to create most variables automatically of the correct type). Yes I know the IDE can also reveal what type a var is, but you generally read code in lots of places that aren't IDE enabled. It also adds more work for the compiler. I'm not sure the effect on Java compile types yet but Kotlin and Swift have both suffered from slow compile times and this seems to be a factor. I'm guessing that most of the larger codebases out there will add "no var allowed" to their style guides within the next few years.
- Skinney 5y agovar shouldn’t increase compilation time in any meaningful way. The compiler has to figure out the type anyway (otherwise, how would you get type errors?).
- kaba0 5y agoIt’s not an either-or thing though. I prefer defaulting to vars and changing specific variable definitions to show explicit types based on the right hand side expression. These “no var allowed” and friend global rules are almost always bad (looking at the myriad c++ rules) —- there are cases where it will make code more readable and others where the traditional style is the preferred.
- jamesfinlayson 5y agoYeah I'm not sure where this originated (recent C++ has something similar with auto and I think C# now has var as well) but if I'm doing a code review rather than writing code in an IDE, var is a bit of a hindrance.
- dunefox 5y agoIt's not the IDE, it's the compiler that infers it. So type information is always available.
- xxs 5y agoThat's not the point - try having 2 or 3 way diff, pull request with just var. It's =awful=. I know most of the standard APIs (incl. overloaded methods and what not) by heart but not every little function and class in a million lines of code project. To me var adding is mosttly an anti-feature - when using an IDE, I dont even bother to declare the stuff, it gets auto completed. When I read code outside the IDE - well it sucks. It's not the level of 'perl - write only', but at least it aspires to be.