3 ms·
That's a sad situation, when there are low-hanging fruit Java can pick from other programming languages, like: Type inference: Being able to say: var foo = Fo
by kartickv 10y ago
That's a sad situation, when there are low-hanging fruit Java can pick from other programming languages, like:
Type inference: Being able to say:
var foo = Foo();
Or:
final foo = Foo();
Keyword arguments
Lazy properties / methods, like in Swift.
Dynamic typing: Have a type dynamic, on which all calls are type-checked at runtime. This is similar to Objective-C's id, and could just be syntactic sugar for reflection. One should be able to define a class that can intercept all method calls and (say) forward them to another object, again like Objective-C's forwardInvocation.
Performance: Things like structs, or being able to create an array of objects rather than an array of references to objects, or having a field of an object be another object rather than a reference to one. This should help bring down Java's high memory consumption compared to other languages like Go or Swift.
None of these enhancements will be in conflict with Java's goals. For example, we're not talking about raw pointers (insecure) or ints with platform-dependent sizes (non-portable).
- the8472 10y ago> Type inference There's a proposal[0] for local variable type inference, but it's not scheduled for any specific java version. > Dynamic typing you can run dynamic languages on the JVM. groovy, javascript, ruby, ... > Performance: Things like structs, or being able to create an array of objects part of valhalla[1]. [0] http://openjdk.java.net/jeps/286 http://openjdk.java.net/jeps/286 [1] http://openjdk.java.net/projects/valhalla/ http://openjdk.java.net/projects/valhalla/
- kartickv 10y agoBeing able to run dynamic languages on the VM isn't a substitute for the occasional situations in which dynamic typing in Java would help, say when working with JSON.
- Traubenfuchs 10y ago> type inference There is a JEP (286) for that. Personally I consider it highly harmful. I regularly read C# source of unknown libraries outside of an IDE (Like on Github) and very often I don't have the faintest clue what type a var holds even it is just a type well known to me, making navigation of that code very difficult. > lazy properties This looks interesting. I don't think Java will ever offer it though. > Dynamic Why would you want to kill the static type safety we cherish so much? I only ever had to use dynamic in C# when working with horrible legacy APIs. Besides that, interface proxies and cglib proxies (bytecode manipulated classes) are heavily used in Java frameworks and do the delegation you talk about. > Structs Value types will be available in Java 10. (JEP 169: "Provide JVM infrastructure for working with immutable and reference-free objects, in support of efficient by-value computation with non-primitive types.")
- kartickv 10y agoHow is it harmful to say: var foo = new Foo(); as opposed to: Foo foo = new Foo(); ? As for "killing the static type safety we cherish so much", that's a one-sided view. There are situations when dynamic typing works better, say when working with JSON, and in any case, static typing has many problems: https://kartick-log.blogspot.in/2016/05/statically-typed-languages-need-better.html https://kartick-log.blogspot.in/2016/05/statically-typed-lan...
- ionised 10y ago> Type inference: Being able to say: > var foo = Foo(); I don't want that in my Java. A developer we used to have used the 'val' feature of Lombok to implement type-inference in a lot of the repos he was responsible for and we took a collective decision to remove every last instance of it from the code base.
- kartickv 10y agoI don't see the problem — look at the right-hand side of the expression to find out the type. Swift does it very well. It helps, not hurts, readability.
- deleted 10y ago[deleted]