Live data from Hacker News

Java: Missing Features

infoq.com

11–20 of 54 posts

Re: Java: Missing Features

#11
post #4
post #2

What I would love to come over from C# is: * Auto-Properties - Get rid of all those ugle getters and setters cluttering up POJOs * Object and Collection Initialisers - https://msdn.microsoft.com/en-us/library/bb384062.aspx

might want to checkout lombok. https://projectlombok.org/

I just stumbled on this today (before coming here), looks really nice to rid some boilerplate. Regardless for some reason I still love Java...

Re: Java: Missing Features

#12
post #4
post #2

What I would love to come over from C# is: * Auto-Properties - Get rid of all those ugle getters and setters cluttering up POJOs * Object and Collection Initialisers - https://msdn.microsoft.com/en-us/library/bb384062.aspx

might want to checkout lombok. https://projectlombok.org/

Just keep in mind that some of the features are a bit iffy. If you use their vals IntelliJ will syntax highlight it as an error in red for the simple reason that it's non-compliant with the Java language spec. Also, you'll usually need a new version on Lombok every time a new version of Java comes out, otherwise what used to compile with the previous java version will no longer compile. If you use the auto constructor you're going to have fun finding usages since there's nothing to click on, and changing the order of fields in your class will silently change the ordering of parameters in your constructor - double the fun of the fields are of the same type. You'll also be left wondering why you went to all the trouble of adding dodgy language extensions instead of just using a language which provides those features anyway. That and your code (subjectively) looks really ugly plastered with annotations everywhere. Some people like Lombok, just make sure it's a choice you make going in with your eyes open.

Re: Java: Missing Features

#13

I've been bitten by the "Long indices for arrays" lack once before. But then again, I had no reason for storing a String of length greater than MAX_INT in memory in the first place. Streaming it was the better approach in my case. Honest question: is there ever an acceptable case for having such a long String in memory?

So would this affect all flat memory allocation? Say if you wanted to allocate 100GB for a bloom filter, would you need to break it into chunks?

Re: Java: Missing Features

#14
> The issue of primitive specialisation of generics is only tangentially related to type erasure, and run-time visible generics are actually much less useful than Java folk wisdom insists.

Run-time visible generics are pretty important because it lets us avoid boxing everything. In .NET, they don't have this problem, and as a result primitive dictionaries are ~17x faster [0]. Java folk wisdom seems pretty accurate to me in this case.

[0] - http://fsharpnews.blogspot.com/2010/05/java-vs-f.html

Re: Java: Missing Features

#15
post #14

> The issue of primitive specialisation of generics is only tangentially related to type erasure, and run-time visible generics are actually much less useful than Java folk wisdom insists. Run-time visible generics are pretty important because it lets us avoid boxing everything. In .NET, they don't have this problem, and as a result primitive dictionaries are ~17x faster [0]. Java folk wisdom seems pretty accurate to…

He's talking about reification versus specialization. The .NET runtime is specializing generics for value types and that's how you avoid boxing. For normal classes though, specialization would not have any benefit and the boxing argument goes away.

Interestingly, specialization can be done at compile-time and doesn't necessarily have to be a runtime feature. Here's a Scala compiler plugin doing that: http://scala-miniboxing.org/

Re: Java: Missing Features

#16

I've been bitten by the "Long indices for arrays" lack once before. But then again, I had no reason for storing a String of length greater than MAX_INT in memory in the first place. Streaming it was the better approach in my case. Honest question: is there ever an acceptable case for having such a long String in memory?

So would this affect all flat memory allocation? Say if you wanted to allocate 100GB for a bloom filter, would you need to break it into chunks?

Yes, you'd need 6 arrays of 2147483648 longs (max int), plus one array of 536870912 longs, so a total of 7 arrays. Not that bad really.

Re: Java: Missing Features

#18
post #14

> The issue of primitive specialisation of generics is only tangentially related to type erasure, and run-time visible generics are actually much less useful than Java folk wisdom insists. Run-time visible generics are pretty important because it lets us avoid boxing everything. In .NET, they don't have this problem, and as a result primitive dictionaries are ~17x faster [0]. Java folk wisdom seems pretty accurate to…

He's talking about reification versus specialization. The .NET runtime is specializing generics for value types and that's how you avoid boxing. For normal classes though, specialization would not have any benefit and the boxing argument goes away. Interestingly, specialization can be done at compile-time and doesn't necessarily have to be a runtime feature. Here's a Scala compiler plugin doing that: http://scala-min…

> He's talking about reification versus specialization.

It's neither according to the usual (C++-inherited) lingo where specialisation is the userland override of generics reification. Refinement may be a better term for what the article is talking about (runtime-optimised instances without reified types).

And refinements should already be doable in java today with no static type information, Pypy does it with list strategies, I expect Objective-C's hidden classes could also enable it (though I'm not aware of such a use).

> Interestingly, specialization can be done at compile-time

That's where they started...

Re: Java: Missing Features

#19
post #2

What I would love to come over from C# is: * Auto-Properties - Get rid of all those ugle getters and setters cluttering up POJOs * Object and Collection Initialisers - https://msdn.microsoft.com/en-us/library/bb384062.aspx

If there's no logic in the getter and setters, just make the properties public.

Re: Java: Missing Features

#20
post #2

What I would love to come over from C# is: * Auto-Properties - Get rid of all those ugle getters and setters cluttering up POJOs * Object and Collection Initialisers - https://msdn.microsoft.com/en-us/library/bb384062.aspx

If there's no logic in the getter and setters, just make the properties public.

Huh? Then they're just fields and not properties, maybe I'm misunderstanding what you're trying to say. And there are numerous reasons that Properties are preferable to Fields.

Unless someone else can help me, I think this is really bad advice for a C# developer.

Post reply on HN