Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I joked the other day to a co-worker, currently working full time in Python, that you get used to the list comprehension and other nice things of Python so much, that you'll never be able to go back to gnarlier languages like Java/C. It's just too nice. You can get python to run really fast nowadays and if you can't, you still got nim.


C# and Java 8 (I believe) provide functional patterns. e.g. in C# the ToLower function which takes a string and returns a string can be used like:

  var lowercaseIds = ids.Select(ToLower)


You believe correctly, but naturally, it's a lot more verbose:

  var lowercaseIds = ids.stream().map(String::toLowerCase);
and an additional

  .collect(Collectors.toList())
if you don't want a Stream instance. (var is Java 10, though I believe it should not be used in production code, ever)


> var is Java 10, though I believe it should not be used in production code, ever

Is that your opinion of var in general, or something about Java's implementation of it? If the former, I'm really curious why, as a C# dev who's used it for many years.


Unless you are using a constructor to fill the var, it makes reading/exploring/understanding source code more difficult. If the value comes from a method, enjoy chasing it down in your VCS. In your IDE you only need to hover it, but it's still an unnecessary extra step.

Sometimes I explore source code on GitHub, excessive use of var makes reading it very uncomfortable.

Turning it around, what are the benefits of var? Slightly increased typing speed. More time is spent reading source code than writing it and var makes reading harder and writing easier, so it's not worth the trade in my opinion.


I'd actually argue that var makes it easier to read and understand code. Most of the time, an explicit type on a variable declaration is just noise, because it's a repetition of what we already know from the same line of code. The main place where this doesn't apply is when the variable is initialized from a method call, but even then I tend to find that it's usually quite easy to infer the result type based on context (variable or method name), even without using IDE features. It's definitely different and requires some getting used to, but I personally see a lot more positives than negatives from it.

RE your sibling comment about dynamic: I primarily use it with json. It's useful for things like one-off error responses where you just need to grab a message or code to return/throw and there's really no benefit from introducing a class for that one usage. I did once work on a project where that was attempting to re-use some awful legacy code in a new app, and they leaned on dynamic a lot to make the legacy code work without to re-architect it correctly. It was about as terrible as you're imagining.


I find that it's rare that I need to know the exact type of a variable when I'm reading code, and that the var speeds up reading as well as writing.


I'm not a java dev, and I don't anything around introduction var into java.

But I am a c# dev, and in the early days when var was introduced a lot of people avoided var because of misunderstanding of how it works. People thought it was dynamic rather than inferred, is it the same here?


Java does not have anything that can be used like C# dynamic. If you want to replicate it, you'd have to use several lines of reflection.

See my reason for not using it above.

As someone who holds no mastery over C#: Is it appropriate to ever use dynamic anywhere besides horrifying interop code?


Almost nobody uses dynamic, but they do use var


Useless, unless you can Rust it into Ethereum with a Koltin to Typescript transpiler.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: