Some languages are destined to be always overly verbose. One feature I’d hoped for in later versions of Java was implicit typing. In C#, for example, you can declare:
var customer = new Customer("Jose Cañusi");
It’s not too hard for the compiler to figure out that
customer is of
Java still has no implicit typing. Any time you need a non-specific Customer instance, you need the following code:
Customer customer = new Customer("Elmer Sklue");
I’m out of breath doing all that typing! Well, not really: I didn’t do all that typing. But I’ve suppressed a scream too often pairing with folks who do type the word customer three different times.
We have computers to compute for us. Never mind that the Java language is a cranky old uncle, you at least have a Generation Z development environment if you’re using Eclipse or IDEA.
I’m pretty sure I first saw J.B. Rainsberger demonstrating the following tip at least a dozen years ago.
Type the instantiation (right-hand) side of things first:
new Customer("Anne Teak");
Do not type the left-hand side! Instead, press Cmd-1 (Quick Fix; the corresponding keystroke is Alt-Enter in IDEA). Select Assign statement to new local variable and press enter. If you’re young enough to store away another shortcut, use the slightly more effective Cmd-2-L key combination instead.
Unnecessary typing represents distraction, waste, and risk.
Michaeli September 24, 2016 at 4:16 am
Was sending you a question and noticed I had just seen this fly over the wire on Reddit the other day. Great minds think alike.