News for hackers. Stuff that matters.
Re:Diminishing returns of static typing by icebraining on Monday October 02, 2017 @01:39PM (#15385980)
Typing in Java could be better, sure, but even with its quirks it's way better than the nothing you get with dynamic languages.

I disagree; that Java was the standard example of statically typed languages is what convinced me for a long time that I didn't want anything to do with it. Having to pollute my code with all that crap, deal with a lot of dumb restrictions and still have NPEs left me with a sour taste.

Only after I discovered Haskell (and more recently Idris), did I realize that static typing can actually be worthwhile.

Re:Diminishing returns of static typing by mattnewton on Monday October 02, 2017 @02:01PM (#15386215)
Agreed, every time I had to patiently explain to javac that shockingly, my new ArrayList<T> was a List<T>, my new FooBar was a FooBar, and always would be, it drove me slowly mad. Still, I was thankful for the static types when trying to understand where this strange object came from and what it was supposed to do. I’m glad we have modern languages that have the potential to do an even better job of that without a lot of the verbosity.
Re:Diminishing returns of static typing by breischl on Monday October 02, 2017 @03:42PM (#15387250)
Those things are indeed obnoxious, but they are truly _Java_ issues rather than static typing issues. For instance, C# will figure that stuff automatically in many cases using the _var_ keyword. The Lombok plugin can add something like that into Java, although it's only about 80% as good because of other Java limitations, primarily type erasure.
Re:Diminishing returns of static typing by mattnewton on Monday October 02, 2017 @06:36PM (#15388570)
I agree. While I have never used C# in anger I have played with enough other (non-Java staticky typed) languages to know that it doesn’t have to be this bad :D
Re:Diminishing returns of static typing by nradov on Monday October 02, 2017 @03:07PM (#15386894)
While it may be frustrating to novice programmers, the distinction between interfaces (List) and implementation classes (ArrayList) is quite valuable, especially when dealing with huge code bases that have to be maintained over decades. Those declarations help to establish an internal design contract and clarify the developer's intent. In this particular case, a future maintenance programmer could switch from ArrayList to any other class which implements the List interface without breaking the program.
Re:Diminishing returns of static typing by nicoburns on Monday October 02, 2017 @06:32PM (#15388544)
True, but there are more elegant solutions. For example, Rust's traits allow you to define a trait (somewhere in between an interface and an abstract class in Java), and then methods can be generic over any object that implements that trait. And structs and traits have a many-to-many relationship.

This allows you implement patterns like duck typing which are idiomatic in languages like javascript, but impossible to implement in java.

Re:Diminishing returns of static typing by x0x0 on Monday October 02, 2017 @05:56PM (#15388305)
Which happens exactly how often? I've been writing java code for the better part of two decades and basically never needed to swap my list/set/map types around. Also, one of the purported benefits of java's typing is your editor can find and refactor / swap all usages, so it doesn't seem to me like this distinction has much value. It instead makes me think it's a fetish for object orientedness...

In fact, the only cases I've ever swapped even a HashMap has been to trove, which implements data structures for builtin types rather than reference types. In which case using interfaces everywhere doesn't help.

Re:Diminishing returns of static typing by mattnewton on Monday October 02, 2017 @03:43PM (#15387267)
It’s not about having the difference, it’s about having to explain to Javac what I am using because it’s incapable of doing meaningful type inference.
Re:Diminishing returns of static typing by vkou on Monday October 02, 2017 @04:37PM (#15387709)
Only in the case of generic erasure, which is a Java wart that we will, sadly, never eliminate.
Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @03:02PM (#15386841)
Generics in Java have well known limitations stemming from type erasure (a design decision made to preserve backwards compatibility). Things aren't quite as dire as you made them out to be and in the general case, they work quite well.
Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @02:47PM (#15386674)
>Having to pollute my code with all that crap

What crap? Types?

>deal with a lot of dumb restrictions

Like what?

Re:Diminishing returns of static typing by icebraining on Monday October 02, 2017 @03:42PM (#15387248)
What crap? Types?

Types, especially those that could easily be inferred and that provide no value to the programmer. Writing types down can be useful - Python programmers do it too. Having to tell the compiler every little thing is crap.

Like what?

Type erasure. Having to treat primitives and arrays differently from other types. No first class functions or classes. I won't go on, the arguments are easy to find.

Re:Diminishing returns of static typing by macspoofing on Monday October 02, 2017 @04:32PM (#15387675)
I won't deny that Java had some quirky design decision that the language is paying for (though some of those have been mitigated). But I can't find your criticisms very persuasive in a world where languages like JavaScript and PHP are popular. Even C and C++ have their own idiosyncrasies to contend with.

I am surprised though that you were completely ignorant of the benefits of static typing outside of Java. I would think that simply out of curiosity you would do a language survey just to get an idea of what else is out there.

Re:Diminishing returns of static typing by icebraining on Monday October 02, 2017 @05:32PM (#15388145)
II can't find your criticisms very persuasive in a world where languages like JavaScript and PHP are popular.

Persuading you on the general demerits of Java wasn't really my intention; my point was that if you want get more people on the static typing train, Java is a bad ambassador and might work against you.

I am surprised though that you were completely ignorant of the benefits of static typing outside of Java. I would think that simply out of curiosity you would do a language survey just to get an idea of what else is out there.

Well, back then (early 2000s) I was a self-taught teenager with a poorer grasp of English (I'm not a native speaker), so while my curiosity did lead me to discover a few languages (JavaScript, PHP, Python, Lua and C), anything remotely approaching "academic" - Haskell, OCaml, Oberon, etc - was out of bounds for me.

Since C was the only other statically-typed language I knew, and I also knew it was much older and designed for much slower machines, I assume static typing was mostly for efficiency, like manual memory management.