Hacker News new | ask | show | jobs
by Zababa 1750 days ago
About Java vs Python, modern Java would be:

    import java.util.ArrayList;
    var cars = new ArrayList<String>();
Python would be:

    cars: list[string] = []
The big difference seems to be that ArrayList is not a "default" data structure in Java, but it is in Python. While I like the Python example better, I'm not offended by the modern Java.
3 comments

The author goes full circle by introducing types in python. Almost every java developer uses an IDE with autocomplete so they would most likely not use a var (where they wouldn't) ..type the interface they want to use, add the assignment operator and then just let the IDE suggest the implementation, add the import and even format the line/file. Such trivialities don't help when attempting to distinguishing the flexibility python bring for arbitrary/quick code
Actually, as a Java dev, I quite like modern Java for data work. Streams + static typing make aggregating data a breeze.

I assume for more advanced work like the one OP mentions you'd still want to stick to Python because of the superior ecosystem, but I was pleasantly surprised by Java.

Can't believe I'm writing this, but I actually like modern Java.

I've only followed Java from far away (last time I used it was Java 7 in college) but modern Java seem like a very nice language. There are also Graal, alternative ecosystems to Spring, good things like that.
That modern Python example scream regression to me. Why not simply cars = []?

This obsession with killing perfectly good languages with strongly typed hints is completely undermining the point.

I think you're in the minority thinking that Python is "killed" by adding static (not strong, Python is already strongly typed) type hints. They are also optional, so you're free to not use them.

To go back to the code example, if you want to express the same thing in Python as in Java, you have to add a type hint to be able to statically check the code. A good thing about Python is that you can choose when and if you want to use a static type hint, while in Java you're forced to use them.

I have work with large python project without types. It's a nightmare. Types are extremelly useful.
Static type information makes it far easier to avoid a whole class of bugs, which becomes more important as your project gets larger.