
Is ‘var’ Coming to Java? - mite-mitreski
https://www.voxxed.com/blog/2016/03/var-coming-java/
======
nunobrito
Hopefully not.

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.

~~~
jinst8gmi
Fortunately progress doesn't rely on the approval of the nay-saying minority.
It's type inference for local variables. Do you really think that val str =
"foo" is less readable than String str = "foo"?

~~~
nunobrito
In the example you mention it is readable.

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).

~~~
jinst8gmi
People need to apply common sense when writing code to ensure readability.
Banning type inference isn't going to stop incompetent coders from writing
bad/unreadable code. I'm talking as someone who uses both Java and now
(mostly) Scala professionally. Java's lack of type inference is a source of
great annoyance when I'm working on Java code. In my experience having types
inferred for local variables strikes a good balance.

~~~
nunobrito
Fully agree on common sense.

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.

~~~
jinst8gmi
> One time found a nested IF chain that was 15 levels deep with other IF
> statements.

Ouch, good luck...

