Is ‘var’ Coming to Java?(voxxed.com) |
Is ‘var’ Coming to Java?(voxxed.com) |
The lack of type inference in Java is one of the few things we still have for keeping prima donna programmers far away on the Javascript domains.
Explicit type inference reduces the effort of debugging code and simplifies understanding the object behind each variable. This is honestly a reason why I find programming in Javascript so messy and time consuming.
Perhaps you can agree that for an extended class (not a primitive like a String) it will make code quality revisions for both humans and compilers more difficult?
Because in Java you find classes extended very frequently and the code always should point to whatever object you are expecting so that the output is perfectly clear for everyone.
A positive side-effect is that some people will try to cram-up as many instructions per line as they can, for readability purposes they are literally forced to break their code into perfectly readable (and repeatable) functions. This in turn makes the code easier to breakpoint/debug/audit.
I'm talking as someone who professionally programs both in Javascript and Java. For me the real beauty of Java is not having to look at someone else's code that crams up functions within functions and type infers everything he can. Really, it gets quite painful to review and debug such code.
So would be sad to see Javascript ninjas now start jumping into Java and doing the same kind of thing. We don't need ninjas to quickly hack Java code together, we need proper engineering that builds lasting and maintainable code. So, different audience and purposes (philosophies if you will).
Unfortunately managers hire cheap coders, so it was kind of useful this natural obstacle to repel code ninjas, or at minimum demotivate them from writing cryptic code.
I'll tell you, even with static typing rules I've seen code where I just think: "why, oh why?". One time found a nested IF chain that was 15 levels deep with other IF statements.
In Javascript it is honestly so difficult to try figure out what they were expecting as output, because comments are never present on the code. If you write scala, that is good but there are reasons why Java caters a different type of projects and audience.
Ouch, good luck...