News for hackers. Stuff that matters.
Re:Why Type Systems Matter by blauditore on Friday August 18, 2017 @02:32PM (#15048620)
I thought this was quite clear, and it's what I've always been missing in languages like Python or JS. Yet I meet many devs, especially coming from such languages, making fun of Java for its verbosity and clumsiness.

On the other hand, it leads to some people abusing the static type system: They just randomly change types until it somehow compiles, without thinking about what their doing.

Re:Why Type Systems Matter by ardit33 on Friday August 18, 2017 @02:54PM (#15048791)
Java is notorious as it has very clumsy syntax. Simple arraylist of dictionaries declaration looks like this:

ArrayList<Map<String,Object>> myArrayList = new ArrayList<Map<String,Object>>();

Could have been just:

ArrayList<Map<String,Object>> myArrayList = new();

or even better:

ArrayList<Map> = new(); <- if you don't care what the type of map is.

Re:Why Type Systems Matter by blauditore on Saturday August 19, 2017 @07:43AM (#15052846)
As others have mentioned, there's the diamond operator which has been around since Java 7.

> if you don't care what the type of map is

You can use raw types, it works perfectly fine (just generates a compiler warning). For explicitly being unspecific, you can also use a type wildcard (`?`).

Re:Why Type Systems Matter by kuschku on Friday August 18, 2017 @03:10PM (#15048931)
That is almost literally what Java does.

ArrayList<Map> myArrayList = new ArrayList<>(); works already today.

Re:Why Type Systems Matter by conwaysgame on Friday August 18, 2017 @02:58PM (#15048831)
Note in Java8, you could just use:

ArrayList<Map<String,Object>> myArrayList = new ArrayList<>();

Re:Why Type Systems Matter by shock on Friday August 18, 2017 @03:05PM (#15048895)
The diamond operator is available since Java 7. Tripped me up too.
Re:Why Type Systems Matter by mcphage on Friday August 18, 2017 @02:44PM (#15048712)
> making fun of Java for its verbosity and clumsiness

Java has a particularly verbose and clumsy type system.

Re:Why Type Systems Matter by shock on Friday August 18, 2017 @03:07PM (#15048915)
What do you mean it has a verbose type system?
Re:Why Type Systems Matter by mcphage on Friday August 18, 2017 @03:20PM (#15048989)
Person myPerson = new Person("My", "Name")

You need to specify the class twice on the same line, because Java can't figure it out on its own.

Re:Why Type Systems Matter by tmstieff on Friday August 18, 2017 @04:08PM (#15049335)
The left hand side only reserves the memory, the right hand side actually initializes the object. A bit redundant I agree, but to the compiler it is two atomic operations.
Re:Why Type Systems Matter by mcphage on Friday August 18, 2017 @04:23PM (#15049436)
It is two separate operations, but in many other languages the compiler is smart enough to figure out that they'll be the same type (and allow you to specify it when they're not)

That's what I mean—Java's type system is verbose and clumsy, because it doesn't bother trying to figure out things it could figure out, forcing the programmer to be redundant and repeat themselves all over the place. The fact that it's 2 separate operations to the compiler shouldn't dictate anything about the language.

Re:Why Type Systems Matter by sqeaky on Friday August 18, 2017 @06:18PM (#15050197)
I agree it could be more clean, but the way it is designed allows for immediately understandable semantics when dealing with inherited types (which everyone though was the future during Java's Formative years).

This makes operations like this intuitive:

    Animal results = new Dog("Lassie");
Re:Why Type Systems Matter by mcphage on Friday August 18, 2017 @11:04PM (#15051422)
It does, but they should have found a solution which allowed that, as well as not be redundant in the more common case where the two classes are the same. Hence Java's type system being verbose and clumsy.
Re:Why Type Systems Matter by andrewflnr on Friday August 18, 2017 @03:34PM (#15049091)
Nice static type systems don't make you write out nearly as much crap as Java's does. It's pretty common for them to be able to completely infer the type of every expression in the program. If you're worried about the mere coherency of the concept of a "verbose type system", well, it was just a clever turn of phrase.
Re:Why Type Systems Matter by captainmuon on Friday August 18, 2017 @04:17PM (#15049394)
> They just randomly change types until it somehow compiles, without thinking about what their doing.

I did that, too, when I was inexperienced with C++. Especially with const, but also with * and &. But somehow it "clicked" at one point and I don't have that problem anymore.

In recent times, I've found static type systems to helpfully nudge me in the direction of correct code. I was pleasantly surprised by TypeScript. Also, in modern C++, if you use unique_ptr, shared_ptr, try to get rid of naked pointers, and use value types and RAII if possible, the code ends up a lot cleaner. I've found a couple of places where ownership was unclear, and I previously had circular references or dangling pointers as a result.

And anecdotically, the way people program in Haskell is basically, write what you mean, and then fix it until it compiles; it will likely also be correct.