tpxl parent
`var a = Set.of(1, 2)`
works just fine in Java.
Impressively simple - though there being three ways of doing something is a complexity in itself.
Perhaps I’m being too critical.
Not if only one is the right one in all cases.
In python you can also do
s = set()
s.add(1)
s.add(2)
and s = set(x for x in [1, 2])
But I wouldn't call that having three ways to do the same.Disclaimer: I don't know java well, just commenting based on the comments above and my python knowledge.
In python, those give a mutable set, which is what I was referring to above.
Also not to put too a fine a point, you'll never see python code like that in the wild, but even in code reviews these days, it's common to find Java code written like in my example because the syntax for sets in Java came after Java 8
Thanks for specifying, as I said I'm not a java programmer. I stand corrected.
>it's common to find Java code written like in my example because the syntax for sets in Java came after Java 8
So I think we went full circle back to GP claim:
> The language itself is quite beautiful when used properly and with modern features
:)
My bad on the mutability. As far as code like that written in Java, I don't think I've ever seen something like that in anything non-toy and I started with Java 7.
I think that's fair. As with good UI, I appreciate when I can navigate via intuition. The solution in Python is intuitive, readable, and memorable. When working in Java, I frequently felt compelled to read and review pages of docs in search of a straightforward solution. I'm a sucker for Python's syntactic sugar.
I've never seen a language have a single way to do something. It's part of Python's mission statement, but it doesn't appear to even have been a consideration in practice.
I mentioned "mutable" in my comment