News for hackers. Stuff that matters.
Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @02:07AM (#38022217)
I rather use compiled managed languages like Swift, D and C# instead, they provide enough low level coding knobs for C and C++ style coding, while being high level productive.

Would add Go to the list, but only when I really have to.

Nim and Crystal could be alternatives, but don't seem to have big enough communities, at least for what I do.

However I do agree with the conclusion, Rust is a great language for scenarios where no form of automatic memory management is allowed, kernels, specific kinds of drivers, GPGPU programming, as general purpose, there are more productive alternatives, equally safe.

Re:Was Rust Worth It? by hiAndrewQuinn on Thursday October 26, 2023 @02:29AM (#38022374)
C# is underrated by the HN crowd, I find. I quite like how mid sized firms (100-1000 employees) use it.
Re:Was Rust Worth It? by eddtries on Thursday October 26, 2023 @02:35AM (#38022415)
I've always found those sort of firms with C#, in my experience, have the best architected code. Proper domain-driven design, onion architectures, clean testable code... Some have legacy issues where they might not have the most cutting edge CI/CD pipeline or high automated test coverage, but the code itself can be very nice. I've never really experienced that with a different language/company size.
Re:Was Rust Worth It? by tkubacki on Thursday October 26, 2023 @02:47AM (#38022498)
I used to be .NET dev and don't agree. Couple of reaons:

1) Modern Java is almost as good as C# with some things I can't give up in Java (static imports => succint code, Groovy Spock => succint tests)

2) Kotlin is better than C#

3) JVM has much much bigger ecosystem (almost all the apache projects are JVM oriented) and default web framework is much less code to type (SpringBoot) is much more productiv

4) JVM has wider variety of langs

For those reasons IMHO if you are small-mid company (or startup) it's wiser to choose JVM.

Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @03:28AM (#38022764)
Kind of, maybe you need to do some low level coding and don't want to wait for Valhala, or make use of JNI and native libraries, GraalVM/OpenJ9 still aren't as integrated as .NET Native or Native AOT, e.g. writing native shared libraries.

Also Java lost the attention span of the gaming industry, besides Android casual games and Minecraft, there are hardly anyone else paying attention to it.

Re:Was Rust Worth It? by Ygg2 on Thursday October 26, 2023 @04:23AM (#38023114)
To be fair, C# is ok for game dev, but not great. C# libraries are lagging heavily behind Java.

Want a fastest possible library? It's in C++, and not portable to Win/Mac. So good luck with wrap + porting it.

Want a decent implementation of an algo? It usually exists for Java but not for C#. Hope you like writing it from scratch.

Want a C# implementation of an algo that doesn't allocate to the Nth degree. Again, write it yourself.

But ok, maybe Unity has a good ecosystem... And they fucked it over a barrel.

Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @04:40AM (#38023221)
It is widely better recieved in the AAA gaming developer community than Java, and that is what matters.

I also like Java, but c'mon no decent algorithms being implemented in C#? That is already approaching zealotry.

Re:Was Rust Worth It? by Ygg2 on Thursday October 26, 2023 @05:26AM (#38023486)
I didn't say no decent algorithm in C#, but for each performance sensitive algorithm/data structure there is a C and Java implementation at the least ( in my case Roaring Bitmaps).

In C# the solution is half baked or archived or abuses allocation.

I think Unity has way more with C# adoption in game dev than innate C# qualities.

Re:Was Rust Worth It? by neonsunset on Thursday October 26, 2023 @05:44AM (#38023579)
This is a classic case of goalpost moving. The reason why so many algorithms are written in Java especially closer to academic side is because most curriculums in comp-sci often straight up not allow using anything else except Java, Python or sometimes C++. Having C# as an alternative in these is a luxury. There are also more people using Java in general. However, this does not make it a better language at solving these tasks, nor it is any suitable for writing high performance implementations for advanced vectorized algorithms which would push hardware, which is actually what you want when you start caring about such scenarios, which C# excels at.
Re:Was Rust Worth It? by Ygg2 on Thursday October 26, 2023 @10:15AM (#38025883)
I'm not moving the goalpost. I explained my examples in another reply. Want to write an engine mostly from scratch in C# and you need libraries that are low on allocation and for niche data/algorithms that games need? You're going to have a bad time(TM).

Sure you could use YAML parser, but it allocates everyone and their mother. Can you find a Fluent localization in C#? Sure, but its outdated and archived. Ok, but basic RoaringBitmap implementation? The repo is archived and not fully complete.

Why C# is used in game dev is incidental. It has more to do with Unity and XNA/FNA than any concrete quality of language modulo value types (but then again, most C# libraries don't focus on avoiding allocation and are just as happy as Java to construct a complicated hierarchy of classes).

Re:Was Rust Worth It? by mpawelski on Thursday October 26, 2023 @04:58AM (#38023335)
Java is surely keeping up but I can't name single Java feature that I miss in C# or is implemented better in Java. I haven't used Java in a long time though, just occasionally I read about new Java features and I've never said to myself "cool, I wish I had it in C#".

Static import are also available in C# for quite some time now (c# 6, released in 2015, and in C# 10 you can even make this import global for for project).

I haven't used Kotlin, is there any killer feature compared to C#? (except more succinct code in certain cases?)

Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @05:50AM (#38023606)
Depending on how you look at it, better extension everything support on Kotlin's case, and a way to do DU, while it keeps being discussed for C#, people should just add F# to their codebase, but alas.
Re:Was Rust Worth It? by tkubacki on Thursday October 26, 2023 @02:50PM (#38030098)
Kotlin is younger and made better choices by default, like immutable "val" as default option.

Also since it's Jetbrains - IDE integration is superior compared to anything C# can have (including Rider...)

Re:Was Rust Worth It? by lenkite on Thursday October 26, 2023 @05:20AM (#38023456)
Also with JDK 21 - you can use virtual threads. No need for async/await which IMHO is a design mistake. Java copied Go here instead of C#.
Re:Was Rust Worth It? by metaltyphoon on Thursday October 26, 2023 @09:19PM (#38033630)
Which makes C interop worse, just like Go
Re:Was Rust Worth It? by Const-me on Thursday October 26, 2023 @08:16AM (#38024526)
I think Java is only good for long-running servers.

Java doesn’t support C interop. For many desktop and embedded projects this is a showstopper, here’s an example https://github.com/Const-me/Vrmac/tree/master/VrmacVideo That C# code directly consumes V4L2 and ASIO Linux kernel APIs, and calls unmanaged user-mode DLLs like libfdk-aac.so and liba52-0.7.4.so.

Native stack and value types in C# reduce load on GC, and the number of complicated tricks required from JIT compiler. This in turn helps with startup performance. This is critical for command-line apps, and very desirable for desktop apps.

Another thing missing in Java is intrinsics support, both scalar like popcnt, bitscan, BMI, etc., and SIMD like SSE and AVX.

Re:Was Rust Worth It? by generichuman on Thursday October 26, 2023 @12:29PM (#38027957)
Projects Panama & Valhalla seems to solve all your complaints:

> Java doesn’t support C interop. For many desktop and embedded projects this is a showstopper, here’s an example https://github.com/Const-me/Vrmac/tree/master/VrmacVideo That C# code directly consumes V4L2 and ASIO Linux kernel APIs, and calls unmanaged user-mode DLLs like libfdk-aac.so and liba52-0.7.4.so.

Part of Panama: check out the "Foreign Function & Memory API" [0]. The official docs [1] say it is a preview in 21 but it got stabilized in Java 22 (isn't out yet).

> Another thing missing in Java is intrinsics support, both scalar like popcnt, bitscan, BMI, etc., and SIMD like SSE and AVX.

Also part of Panama: see the "Vector API" JEP [2].

> Native stack and value types in C# reduce load on GC, and the number of complicated tricks required from JIT compiler. This in turn helps with startup performance. This is critical for command-line apps, and very desirable for desktop apps.

This is part of Project Valhalla [3], they're adding value types and actual generics, among other things.

That said, most of these are not done / not in a stable LTS Java release yet. We'll see how much better it'll be compared to C# (if at all) once they land.

[0] https://openjdk.org/jeps/454

[1] https://docs.oracle.com/en/java/javase/21/core/foreign-funct...

[2] https://openjdk.org/jeps/460

[3] https://openjdk.org/projects/valhalla/

Re:Was Rust Worth It? by Const-me on Thursday October 26, 2023 @01:23PM (#38028775)
> Part of Panama

Most real-live C APIs are using function pointers and/or complicated data structures. Here’s couple real-life examples defined by Linux kernel developers who made V4L2 API: [0], [1] The first of them contains a union in C version, i.e. different structures are at the same memory addresses. Note C# delivers the level of usability similar to C or C++: we simply define structures, and access these fields. Not sure this is gonna be easy in Java even after all these proposals arrive.

For a managed runtime, unmanaged interop is a huge feature which affects all levels of the stack: type system in the language for value types, GC to be able to temporarily pin objects passed to native code (making copies is prohibitively slow for use cases like video processing), code generator to convert managed delegates to C function pointers and vice versa, error handling to automatically convert between exceptions and integer status codes at the API boundary, and more. Gonna be very hard to add into the existing language like Java.

> "Vector API" JEP

That API is not good. They don’t expose hardware instructions, instead they have invented some platform-agnostic API and implemented graceful degradation.

This means the applicability is likely to be limited to pure vertical operations processing FP32 or FP64 numbers. The rest of the SIMD instructions are too different between architectures. A simple example in C++ is [2], see [3] for the context. That example is trivial to port to modern C#, but impossible to port to Java even after the proposed changes. The key part of the implementation is psadbw instruction, which is very specific to SSE2/AVX2 and these vector APIs don’t have an equivalent. Apart from reduction, other problematic operations are shuffles, saturating integer math, and some memory access patterns (gathers in AVX2, transposed loads/stores on NEON).

> most of these are not done / not in a stable LTS Java release yet

BTW, SIMD intrinsics arrived to C# in 2019 (.NET Core 3.0 released in 2019), and unmanaged interop support is available since the very first 1.0 version.

[0] https://github.com/Const-me/Vrmac/blob/master/VrmacVideo/Lin...

[1] https://github.com/Const-me/Vrmac/blob/master/VrmacVideo/Lin...

[2] https://gist.github.com/Const-me/3ade77faad47f0fbb0538965ae7...

[3] https://news.ycombinator.com/item?id=36618344

Re:Was Rust Worth It? by tkubacki on Friday October 27, 2023 @12:11AM (#38034604)
Well maybe you should use C++ or Rust instead of Java or C# in that case?

My point is if you are doing business (especially web) apps. Use one of JVM langs insted of C# because ecosystem is much bigger (and it has fresher langs as well like Kotlin - if that's what you care about)

Re:Was Rust Worth It? by Const-me on Friday October 27, 2023 @09:09AM (#38037946)
> use C++ or Rust instead of Java or C# in that case?

Despite having to spend extra time translating C API headers into C#, the productivity gains of the higher-level memory safe language were enormous.

Another example, I have shipped commercial embedded software running on ARM Linux, and based on .NET Core runtime. The major parts of the implementation were written in idiomatic memory-safe C#.

> doing business (especially web) apps

Well, these business web apps are precisely the long-running servers I have mentioned. Still, the software ecosystem is not limited to that class of problems, and due to different tradeoffs Java is not great for anything else.

Re:Was Rust Worth It? by hiAndrewQuinn on Saturday October 28, 2023 @12:56AM (#38047265)
#1 => agree

#2 => don't know enough about Kotlin to comment

#3 => agree but quality > quantity

#4 => not terribly important to me (Clojure is cool but it's not "switch to the JVM" level cool)

Re:Was Rust Worth It? by hutattedonmyarm on Thursday October 26, 2023 @03:18AM (#38022692)
Is it? Every time I see C# being mentioned here people agree how awesome it is. Not that I'm complaining, I love C#
Re:Was Rust Worth It? by GuestHNUser on Thursday October 26, 2023 @04:01AM (#38022979)
Agreed. I feel C# is appropriately rated on HN and other programming forums. It has perfomant memory options that other GC languages lack, and great builtin packages to use. Overall, it is a good language.

My biggest issue with C# though is how badly exceptions are handled given that it is a statically typed langauge. I wish functions explicitly defined the exceptions it can throw since a minor package bump could add an exception without your compiler warning you that it isn't handled. I much prefer Rust, Go and Zig's error handling to C#'s since those kind of issues don't happen.

Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @04:43AM (#38023232)
> It has perfomant memory options that other GC languages lack, and great builtin packages to use.

As clarification for the audience, it isn't the only GC enabled language with C and C++ like capabilities, in fact there are several examples since the early 1980's.

The adoption push for Java and scripting languages distorced the understanding of what was already available out there.

Re:Was Rust Worth It? by Rapzid on Thursday October 26, 2023 @04:40AM (#38023222)
Well, I see it as lack of fanboyism which is interesting and almost unique to the Java/C# ecosystem. A lot C# experts(and I mean REAL, low level experts) seem to also have very high Java expertise..

And those that have Java expertise but not C# seem to demur to those that do; image!

But it's still niche(around here and in the startup world) and gets lumped in with Java and together they are not "hip" or "agile" or whatever.

Re:Was Rust Worth It? by leeman2016 on Thursday October 26, 2023 @04:22AM (#38023105)
C# is a lovely language to work with.

The only issue I have is with the .NET ... that is, building self-contained binaries to distribute.

For comparison:

* Hello World win-x64 binary self-contained in .NET 7 is around 70 MB

* The same for Go results in 1.2 MB

Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @04:25AM (#38023122)
Usually that means you aren't using trimming, .NET speak for dead code removal during linking.

Also remember that standard .NET runtime does a little bit more than Go's runtime, so it might happen that even with trimming, for basic applications Go ends up having an upper hand on file size.

On the other hand, I have had Go static binaries grow up to 200 MB and being require to use UPX to make it manageable, e.g. trivy.

Re:Was Rust Worth It? by leeman2016 on Thursday October 26, 2023 @04:27AM (#38023145)
You're right. But even with trimming I get around 10x the size of the Go binary
Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @04:33AM (#38023175)
Since I edited my comment, see my additional remarks regarding runtime capabilities, and the counterpoint of big Go binaries.

Also note that triming only works properly if the libraries have taken the effort to be trimmable, as the linker errs on the safe side and won't trim unless certain that it is really dead code, and not called via reflection.

Re:Was Rust Worth It? by neonsunset on Thursday October 26, 2023 @05:06AM (#38023381)

    dotnet publish -c release -p:PublishAot=true
Re:Was Rust Worth It? by neonsunset on Thursday October 26, 2023 @05:03AM (#38023362)
This is an unfair comparison of apples to oranges by building the binary with the wrong flags. .NET produces smaller binaries than Go with NativeAOT (despite including more features).
Re:Was Rust Worth It? by leeman2016 on Thursday October 26, 2023 @05:16AM (#38023432)
Yea, I missed trimming. But still NativeAOT results in 10x the size of the Go binary in Windows (win-x64)
Re:Was Rust Worth It? by neonsunset on Thursday October 26, 2023 @05:22AM (#38023462)
Two aspects:

- There is no point in chasing smallest possible binary size if it trades off performance and features one wants to use in production scenario, or comes with other tradeoffs that sacrifice developer productivity. I don't see anyone complaining about the size of GraalVM native images. As long as binaries are reasonably sized, it's not an issue.

- dotnet publish -c release -p:PublishAot=true definitely produces smaller binaries than Go as of .NET 8 (and no, you cannot use the argument that it's not released yet - it's in RC.2 which is intended for evaluation for adopting .NET 8 scheduled for release next month)

Re:Was Rust Worth It? by leeman2016 on Thursday October 26, 2023 @05:25AM (#38023477)
That's awesome, honestly. Can't wait.
Re:Was Rust Worth It? by leeman2016 on Thursday October 26, 2023 @05:24AM (#38023470)
Let me give a real world example from my own experience.

I have built a Win32 desktop app with its core logic in Go; and then re-built from scratch using .NET (v7). The core logic involved a fairly complicated keyboard input processing based on bunch of config files.

- Final binary of .NET ~ 14 MB

- Final binary of Go ~ 2 MB

Re:Was Rust Worth It? by benibela on Thursday October 26, 2023 @08:32AM (#38024670)
I was making Windows 98 apps with Delphi 4, and they were 350 KB large

And I was upset that they were so big. Sometimes I used UPX. Or I kicked out all Delphi GUI libraries, and created the GUI with the Win32 API calls directly. I got 50 KB Hello Worlds.

Re:Was Rust Worth It? by Borg3 on Thursday October 26, 2023 @12:43PM (#38028182)
50kB hello worlds? Uhm.. thats still big.

15k May 3 2019 quickrun.exe*

Win32 GUI Application that spawns Window and ask for alias to run. Pure Win32 API, written in C (Mingw).

I literaly looled at 11MB hello world of .net or 1.2MB Go..

Re:Was Rust Worth It? by benibela on Friday October 27, 2023 @08:13AM (#38037465)
Well, it is what I remembered

I do not have Windows 98 anymore. But I still have Delphi 4 installed under Wine, so I just tried it out.

Just showing a messagebox from windows gives 16k

Using the sysutils unit though, puts it at over 40k. And with classes, it becomes 57k. Not sure what they pull in. sysutils contains number/datetime parsing and formatting, and exception handling. classes has basic containers and object oriented file handling.

Re:Was Rust Worth It? by Borg3 on Friday October 27, 2023 @12:16PM (#38040461)
Ahh, Delphi. Then I suppose its all right for it. Still, much better compared to Go or Java :D
Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @01:04PM (#38028517)
If only Borland's management didn't decide to focus mostly on enterprise customers.
Re:Was Rust Worth It? by metaltyphoon on Thursday October 26, 2023 @09:22PM (#38033650)
Idk the last time you tried but a hello world in C# using .Net 8 is smaller than a Go hello world, for what it’s worth.
Re:Was Rust Worth It? by Ygg2 on Thursday October 26, 2023 @04:30AM (#38023158)
C# is fine, but it feels like a slightly better Java, just without the huge ecosystem of libraries.
Re:Was Rust Worth It? by Rapzid on Thursday October 26, 2023 @04:36AM (#38023196)
Slightly... The difference in type erasure is pretty huge IMHO.

But what libraries are you lacking?

Re:Was Rust Worth It? by Ygg2 on Thursday October 26, 2023 @05:31AM (#38023520)
Type reification is planned and so is value types.

And type erasure isn't as negative as you seem to make it.

Bunch of really obscure use cases - fluent localization, roaring bitmaps and so on.

Re:Was Rust Worth It? by ninkendo on Thursday October 26, 2023 @10:05AM (#38025748)
> compiled managed languages like [...] C#

I've been out of the windows development game for a long time, so I haven't used C# since it strictly required a VM... what's pre-compiled C# development like nowadays? Are there major caveats? If you can emit plain old binaries in C# with no runtime dependencies, that would make it a truly compelling language IMO.

And as another question, what's the cross-platform (mainly Linux) support like in AOT-compiled C#? If it's just as good as in Windows and emits plain executables, I would probably consider it the best place to start for any new project. (Something tells me it's not...)

Re:Was Rust Worth It? by pjmlp on Thursday October 26, 2023 @02:00PM (#38029329)
C# supports AOT since forever, NGEN was present in .NET 1.0. Not many people used it, because it requires signing binaries and only supports dynamic linking, with a performance profile towards fast startup.

On Microsoft side the Singularity and Midori experiments used AOT.

They influenced the AOT toolchains for Windows 8 store apps with MDIL (Singularity/Bartok), and Windows 10 store apps with .NET Native (Midori/Project N).

Now there is Native AOT, which supports CLI and native libraries,.NET 8 extends that to EF and ASP.NET frameworks. For GUI applications, maybe only fully on .NET 9.

Mono AOT has had support for ages, being used on iOS, Android, and Blazor.

Finally there is IL2CPP and Burst compiler from Unity.

Re:Was Rust Worth It? by neonsunset on Thursday October 26, 2023 @09:03PM (#38033545)
In 8, NativeAOT also supports iOS (and even Android reportedly?) for, I assume, MAUI target to do away with Mono. Documentation on this definitely needs work, and there are projects that made it working with WPF, Windows Forms and Avalonia back in .NET 7. Arguably, none of those were particularly user-friendly but generated COM interop project for 8 was done specifically to improve this on Windows as well.