It's one of the things I really missed when going from C# to Java, but with IntelliJ, the typing experience is very similar from C#. Imagine I want to have a variable like: Person p = new Person("John"); All I would type in IntelliJ is: new Person("John").var After pressing "tab", that will autocomplete for me and put the focus on the variable name so I can rename it from the default inferred value.
Don't most decent IDEs support something like that? In Eclipse you can just type new Person("John") And then hit Ctrl-2 L.
Representing the Impractical and Impossible with JDK 10 “var”
71–80 of 131 posts
Re: Representing the Impractical and Impossible with JDK 10 “var”
#72While I submitted this, I would like to voice my opinion that I am against "var" in Java. People may ask, "Why should I have to enter in the type if the compiler can infer it for me?" My answer is twofold: 1) You or some other maintainer will need to know what that type is later when reading the code. Of course, "var" is meaningless, requiring you to dig back one or more steps to determine the actual type. 2) You don…
On a side note, its getting very tiring to rewrite the whole ecosystem every time a language is being annoying. Can the CS types please work on this real world problem a little instead of going knee deep into homotopy type theory? Please solve this somehow: allow engineers to leave a language without leaving its library ecosystem - lets make libraries super-portable, easily.
Re: Representing the Impractical and Impossible with JDK 10 “var”
#73While I submitted this, I would like to voice my opinion that I am against "var" in Java. People may ask, "Why should I have to enter in the type if the compiler can infer it for me?" My answer is twofold: 1) You or some other maintainer will need to know what that type is later when reading the code. Of course, "var" is meaningless, requiring you to dig back one or more steps to determine the actual type. 2) You don…
Its so funny, watching Java fans talking about silly things like `var` whilst their language gets more obsolete every day. I'm so sorry, but basic type inference won. Can you please go away so we can get a good ecosystem and a good language (with first class support VM wise) to go with it in a single package? On a side note, its getting very tiring to rewrite the whole ecosystem every time a language is being annoyin…
Re: Representing the Impractical and Impossible with JDK 10 “var”
#74Earlier quoted context omitted.
Address address = contract.getAddress(); Not sure how this helps. I pretty much knew 'getAddress' would return some sort of Address structure. It's not like knowing the type name tells you what properties are on it. So what's the point?
With an IDE (or even most code editors) you can ctrl+click on Address to go straight to its definition.
Re: Representing the Impractical and Impossible with JDK 10 “var”
#75While I submitted this, I would like to voice my opinion that I am against "var" in Java. People may ask, "Why should I have to enter in the type if the compiler can infer it for me?" My answer is twofold: 1) You or some other maintainer will need to know what that type is later when reading the code. Of course, "var" is meaningless, requiring you to dig back one or more steps to determine the actual type. 2) You don…
People usually fight this with "why would I need to type it if the compiler can figure it out!?" but those people don't understand the cardinal rule of software engineering: code is not for the compiler or the computer to understand, it is for the programmers to understand. If this wasn't the case then more people would be using APL or similarly esoteric languages.
Adding the extra effort of recursing down the rabbit hole to find the first type being used does not sound like it will make Java more friendly.
Re: Representing the Impractical and Impossible with JDK 10 “var”
#76This will be nice, but what I really want in Java is a type alias feature (what C++ calls "typedef"). This would be particularly helpful for function parameter and return types, which 'var' won't help with.
Re: Representing the Impractical and Impossible with JDK 10 “var”
#77While I submitted this, I would like to voice my opinion that I am against "var" in Java. People may ask, "Why should I have to enter in the type if the compiler can infer it for me?" My answer is twofold: 1) You or some other maintainer will need to know what that type is later when reading the code. Of course, "var" is meaningless, requiring you to dig back one or more steps to determine the actual type. 2) You don…
People said the same thing about auto in C++. Few years later and everyone I know (and codes C++) loves it and uses it all the time. Its a great addition and like lambas will certainly improve how we write Java
Re: Representing the Impractical and Impossible with JDK 10 “var”
#78This will be nice, but what I really want in Java is a type alias feature (what C++ calls "typedef"). This would be particularly helpful for function parameter and return types, which 'var' won't help with.
Re: Representing the Impractical and Impossible with JDK 10 “var”
#79Earlier quoted context omitted.
I'm pro var * I write code a lot more fluidly with var. When I go back to writing non-var code (enforced by some departments) I find that it breaks my focus on solving the problem at hand. I end up writing my code with var and then going back and replacing my vars with the type names. * I find code a lot easier to read. I can understand the flow of the logic easier, the variable names are enough. Unless you have the…
Counter-argument to changing the return type of a function with var: You can change the return type of the function to another type that might break some assumptions later in the code. For example, if the code assumes it has a type Foo with a length field, and you change the return type of tha function to a Bar without that length field, the compiler will complain that Bar doesn't have a length field, rather than com…
Re: Representing the Impractical and Impossible with JDK 10 “var”
#80Earlier quoted context omitted.
With an IDE (or even most code editors) you can ctrl+click on Address to go straight to its definition.
`var address` you can also in a short matter of clicks get to the definition of address's type, whatever it is, if you have an IDE.
When did programming suddenly shift away from "the programmer should be aware of what they are doing?"
Hell, I can't count the number of times I've had to troubleshoot bad imports/classpath management brought about by some genius letting his IDE do his thinking for him.