r/programming • • 4d ago

Java4Shell is a reason to use Java

https://mccue.dev/pages/11-18-26-java4shell
42 Upvotes

49 comments sorted by

View all comments

86

u/KryptosFR 4d ago

Such a weird flex and weird take. Tries to make C# look bad by linking to something entirely unrelated: inline assemblies which a C/C++ MSVC specific feature and only supported on x86 (which is being phased out in . NET).

The coping is hard on that one.

40

u/Professional_Price89 4d ago

"Faster than C", then show a 71% slower than C table.

10

u/za3faran_tea 3d ago

Some guys on the JDK team benchmarked the caffeine caching library (written in Java) with a similar one Moka (written in Rust), and Java had lower CPU usage and lower latencies at the same throughput

7

u/coderemover 2d ago

Do you have a link? A benchmark without information how to reproduce is just an ad.

0

u/za3faran_tea 2d ago

I don't, but here's the chart: https://imgur.com/a/LUG597k

4

u/coderemover 2d ago

It’s garbage. It doesn’t even say what allocator was used and what size of objects. I did benchmark mimalloc against ZGC using a high residency database-like workload and Rust ran circles around Java in all aspects, including CPU spent on memory management.

-39

u/bowbahdoe 4d ago

It can be faster, but 71% slower is still competitive

40

u/gredr 4d ago

You have a weird definition of "competitive".

5

u/coderemover 2d ago

71% slower by wall clock. What about CPU and memory usage?

-23

u/bowbahdoe 4d ago edited 4d ago

Is it being phased out? I'll admit to being out of the loop somewhat. I know there are memory-unsafe features like https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/unsafe-code

I think the core criticism that "C# dependencies can quietly bring in memory-unsafe code" holds.

Correct me if I'm wrong though.

23

u/KryptosFR 4d ago

First link has nothing to do with .NET.

And yes you can use unsafe code so what? It's a needed feature for interop and it must be enabled with <AllowUnsafeBlocks>true</AllowUnsafeBlocks>.

6

u/bowbahdoe 4d ago

Do you need to enable it for dependencies too? Like if you don't have <AllowUnsafeBlocks>true</AllowUnsafeBlocks> you know no dependencies are using unsafe code?

And yep, my bad. Replacing it with a more appropriate link.

13

u/KryptosFR 4d ago

You need it if you call directly API that are marked unsafe. Note that the new model makes it more explicit so even with dependencies you will likely need it more often.

That doesn't make C# unsafe or dangerous. Rust use a similar contract where unsafe code can be wrapped by safe code and code calling the safe version isn't considered unsafe.

4

u/bowbahdoe 4d ago edited 4d ago

Okay but there are still dependencies where the unsafe-ness is something you don't know about unless you read their code?

Like is this a new thing for "directional" safety? And yeah rust does something similar. But people do end up accepting unsafe if it "feels audited" or "feels neccesary." I didn't touch on Rust because I feel like all these -5s on my comments would be -50s if those folks get awakened, but it is a similar criticism

8

u/_choam_ 4d ago

I mean, the way rust does "unsafe" is the right trade off for that type of language. I dont agree with that people just end up accepting unsafe as being audited

4

u/_choam_ 4d ago

You also can block unsafe in your own code and dependencies (not sure about the stdlib and compiler builtins though)

1

u/simon_o 3d ago

That doesn't make C# unsafe or dangerous.

No, just less safe and more dangerous then Java, which is the point OP wanted to make.

--enable-native-access works transitively, and at runtime, which means the person executing the code sees if anything shady might be going on and where, and needs to explicitly acknowledge it.

This is way more useful than a compiler option like AllowUnsafeBlocks that is only relevant at build time.