Hacker News new | ask | show | jobs
by integralid 285 days ago
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.

1 comments

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.