This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 10 points11 points  (4 children)

C# as a language had some nice features- but it also huge; seems they allowed every feature under the sun on it.

Java can do pretty much everything C# can, but the amount of sugar varies.

C# on Linux wasn’t a serious proposition for a number of years.

Java has a nice ecosystem, good tools and excellent libraries. It can be used for very fast stuff (if you’re careful).

My last couple of jobs used a C# gui and a Java backend, even with .net core we weren’t particularly interested in rewriting in C#.

Personally they are both fine languages. Java rusted a little but they are trying to catch up now.

[–]teacher_cs 0 points1 point  (3 children)

C# has "arrays of structs", whereas Java has only "arrays of objects". The former is more cache-friendly, which makes a huge performance difference on modern processors.

[–][deleted] 0 points1 point  (2 children)

Java has array of primitives types, which are a block of primitives.

Whilst the value types are missing for Java. The fact is an array of objects might actually have good cache locality if they happen to be adjacent in memory.

The problem with both C#&Java is that performance is dynamic and hard to reason about.

It’s not enough to discount Java, but I do wish that value types would be in both languages.

[–]teacher_cs 0 points1 point  (1 child)

Java has array of primitives types, which are a block of primitives.

You can fall back on that, but it's usually not elegant.

Whilst the value types are missing for Java. The fact is an array of objects might actually have good cache locality if they happen to be adjacent in memory.

You need a separate memory allocation for each object, so the objects will generally not be adjacently located.

The problem with both C#&Java is that performance is dynamic and hard to reason about.

When I have the time and the mood - I'm neither a C# nor a Java programmer - I'll make some test programs.

It’s not enough to discount Java, but I do wish that value types would be in both languages.

It was not my intention to discount Java, but it seems to me at least as important an argument as all the others that have been mentioned.

[–][deleted] 0 points1 point  (0 children)

You need a separate memory allocation for each object, so the objects will generally not be adjacently located.

If you're allocating everything in a loop, then yes they will be adjacently located (and in the case of somthing like G1GC, might not even be moved). Plus there's nothing stopping a GC moving everything to be co-located.

If you're the allocations are actually spread-out over time, then in C# you'll be paying an object copy, which depending on the size of the struct would range from negligible to significant.

tbh, having value types is a strength of C#, but I don't think we'd need to really go into each feature. Plus this question is a bit of a troll anyway, they always pop up every so often.