Earlier quoted context omitted.
Optional, alright, but promoting bad practices. If people like dumb-down languages, there are plenty of them already!
What are the bad practices being promoted by this? How does it qualify as dumbed down? Simply ranting about things that, charitably, you don't seem to understand, does not make the rants valid.
JEP 286: Local-Variable Type Inference
111–120 of 132 posts
Re: JEP 286: Local-Variable Type Inference
#112Earlier quoted context omitted.
> I think deciding what to allow and prohibit by default is an important design decision. I don't think I disagree with that, but I don't think it was made wrong here. It's true that you "risk the chance" of reading unannotated code, but I find there are times when the code I need to write is clearer to me than the type it'll have, and being able to defer annotation past compilation is occasionally a big win and ofte…
My own experience is that I've been running into less scenarios where I think omitting the type makes code more readable (coming from Scala). It doesn't help myself and my coworkers that it's easy (or 'lazy') to omit annotations. I often wish I was using a text editor or IDE that understood my code and could insert type annotations for me, maybe automatically, and maybe not choose to do so if the line of code would "…
But readability can easily matter less than other things over the course of one compile. This is why I think the best choice is demanding top level annotations for reasonably complete code (say, every commit) and not doing so before I can ask for the shape of something, or see that it outputs what I thought, or run my tests, or see what type errors I get elsewhere.
It might be marginally better to demand it by default and have a flag to disable the check. Demanding it always is more than marginally worse (which is not to say it's the end of the world - it's totally not).
Re: JEP 286: Local-Variable Type Inference
#113Earlier quoted context omitted.
What are the bad practices being promoted by this? How does it qualify as dumbed down? Simply ranting about things that, charitably, you don't seem to understand, does not make the rants valid.
The best practice is that the type of the variable is of the interface, not the implementation except in some special cases.
If you were using a factory, var would infer the factory signature's type, which would normally be the interface.
Re: JEP 286: Local-Variable Type Inference
#114Earlier quoted context omitted.
My own experience is that I've been running into less scenarios where I think omitting the type makes code more readable (coming from Scala). It doesn't help myself and my coworkers that it's easy (or 'lazy') to omit annotations. I often wish I was using a text editor or IDE that understood my code and could insert type annotations for me, maybe automatically, and maybe not choose to do so if the line of code would "…
I agree that omitting the type rarely, if ever, makes the code more readable. But readability can easily matter less than other things over the course of one compile . This is why I think the best choice is demanding top level annotations for reasonably complete code (say, every commit) and not doing so before I can ask for the shape of something, or see that it outputs what I thought, or run my tests, or see what ty…
Which is kind of why I wish for tooling outside the compiler to make the effort in specifying types (when it increases readability, maybe based on heuristics) very minimal. Wishful thinking.
Re: JEP 286: Local-Variable Type Inference
#115Earlier quoted context omitted.
I agree that omitting the type rarely, if ever, makes the code more readable. But readability can easily matter less than other things over the course of one compile . This is why I think the best choice is demanding top level annotations for reasonably complete code (say, every commit) and not doing so before I can ask for the shape of something, or see that it outputs what I thought, or run my tests, or see what ty…
Yeah, when the effort put into inserting types is higher cost than reading them (as with short lived / unstablized code), what you're saying makes sense. Which is kind of why I wish for tooling outside the compiler to make the effort in specifying types (when it increases readability, maybe based on heuristics) very minimal. Wishful thinking.
Re: JEP 286: Local-Variable Type Inference
#116Re: JEP 286: Local-Variable Type Inference
#117Earlier quoted context omitted.
I totally agree, type inference speed writing a code, nothing more. For easy cases reading such code is OK (var path = "/usr/bin/whatever" - obvious), but with a more complex code it becomes awful. I'm a C++ programmer, and quite often I have to dig through dozens of headers to find out what this magic "auto" really means.
That's because C++ combines type inference with a gnarly compilation process. In a language like Java, editors will support it and you'll just be able to "mouse over" (or press a key combo in Vim/Emacs) and it'll tell you the inferred type.
Re: JEP 286: Local-Variable Type Inference
#118Earlier quoted context omitted.
The best practice is that the type of the variable is of the interface, not the implementation except in some special cases.
This is complete nonsense if you're using a static constructor and not a factory. There's zero point to doing this for a local, statically constructed type. It's not a best practice. If you were using a factory, var would infer the factory signature's type, which would normally be the interface.
Re: JEP 286: Local-Variable Type Inference
#119Earlier quoted context omitted.
The best practice is that the type of the variable is of the interface, not the implementation except in some special cases.
So stop using constructors and start using static factory methods. The return type of a static factory method can be the interface type.
Re: JEP 286: Local-Variable Type Inference
#120Earlier quoted context omitted.
I totally agree, type inference speed writing a code, nothing more. For easy cases reading such code is OK (var path = "/usr/bin/whatever" - obvious), but with a more complex code it becomes awful. I'm a C++ programmer, and quite often I have to dig through dozens of headers to find out what this magic "auto" really means.
That's because C++ combines type inference with a gnarly compilation process. In a language like Java, editors will support it and you'll just be able to "mouse over" (or press a key combo in Vim/Emacs) and it'll tell you the inferred type.