An unofficial, read-only Hacker News reader.

Marginalia Search, Money, C++, Rust, AI, Stuff (opens external site)

228 points by Curiositry 4 days ago | www.marginalia.nu | 84 comments on HN

View full thread · View on Hacker News

Comment thread (17)

  1. At the risk of being one of those people shouting "but why not language X?", I'd suggest giving modern C# a serious look. Given the background in C++ and Java, it should feel fairly familiar, while being arguably much more expressive than either and offering excellent language and runtime support for writing allocation-free code.

    We've recently ported two large projects to C#, one from Java and another from C++, and seen performance improvements ranging from 30% to 300% faster, largely by focusing on eliminating allocations rather than doing anything particularly clever algorithmically.

    Replies (4)
    1. Outside of .NET itself, C# is one of those rare things Microsoft got disgustingly correct. It's entire runtime is cross-platform and MIT licensed.
      Replies (4)
      1. I was going to learn C# then I realize it's probably the only language that still has commercial, non domain specific paid library. (eg. Paid react component is fine for me, but a paid circuit breaker library is not)
        Replies (1)
        1. Nah, C, C++, Java, Ada, PL/I, NEWP, COBOL, Fortran, RPG,.... have enough commercial libraries to chose from.
      2. > It's entire runtime is cross-platform and MIT licensed

        It does not run on OpenBSD. And I think it only got recently ported on FreeBSD. Yes, they are “small” platform, but lot of languages are there.

        Replies (1)
        1. Also embedded, mainframes and micros.

          There is Meadows for embedded, and the oldie .NET Compact Framework, but it isn't the same regarding capabilities like real time processing.

      3. Partially, if only the first AOT story wasn't like NGEN, and stuff like Span, and all the low-level improvements since C# 7 were already there in version 1.0.

        Unfortunately even today their Windows team keeps being quite dismissive, pushing C++ instead.

        Even the new Windows ML stuff has, yet again, better C++ and Python story than C# (WIP at the Ignite sessions time).

        Unlike how Apple uses Objective-C and Swift, or Google Java and Kotlin, managed runtimes have an hard upsell on Windows division.

        While Azure nowadays rather push open source projects in Go, Rust, Java than .NET.

        Yeah it is a great development stack, yet its own creator has some issues pushing its adoption even internally.

        Replies (1)
        1. I don't disagree, I do feel .NET could be drastically miles ahead, for example, it was painful to learn that Windows uses React for the Start Menu.... WHY??? I would prefer to hear that .NET is taking a more prominent place in Windows, it would have been a great opportunity for C# to shine as the new driving force behind the start menu on Windows.
          Replies (1)
          1. Now they want to push React like coding on WinUI.

            https://devblogs.microsoft.com/ifdef-windows/microsoft-ui-re...

            If Windows was under a similar management like Android, Longhorn would not have failed, because instead of the internal politics of C++ folks being proven right .NET wasn't up the job, the whole team would have doubled down like on Android, come hail or high water, that thing would ship and perform.

      4. You can probably blame both on Anders Hejlsberg (https://en.wikipedia.org/wiki/Anders_Hejlsberg), who started off with Turbo Pascal and Delphi (both still held in high regard) and then, after getting poached by Microsoft, where he (co-?) led the development of .NET, C# and then TypeScript.
        Replies (1)
        1. He was not poached by Microsoft, rather ex colleagues via the usual referral practice, and C# only happened due to J++ lawsuit.

          The first job Anders Hejlsberg had at Microsoft was working on J++.

          Here from the man himself, regarding how he joined Microsoft,

          https://behindthetech.libsynpro.com/001-anders-hejlsberg-a-c...

    2. > largely by focusing on eliminating allocations rather than doing anything particularly clever algorithmically.

      Did rewriting it in C# make this easier, or did rewriting make this easier?

      Replies (1)
      1. I've of course not tried rewriting it in other languages, so take that with a grain of salt. But the code is by design required to stay aligned with the source codebases as the ports are continuously updated with upstream improvements, so I don't think the gains are coming from being a very different rewrite. What I see is just how much easier it is to express efficient code in c# without loosing expressiveness, with a really nice to use low level support (Span/ReadOnlySpan, stackalloc, built in intrinsics support, easy to use pooling, etc) so you can refactor where it matters.
        Replies (1)
        1. I think GP was asking if the speedup was due to eliminating allocations (maybe by doing them upfront?), not if the expressiveness of efficient code is easy.
    3. I'd claim this is the rewrite done by people that know what they're doing that is responsible for most of the gains vs. C#'s compiler to magically make things run faster.

      Sure the C# compiler is great and mature; and .NET Jit probably great too. But these massive gains can only be explained by "do less stoopid stuff".

      Replies (1)
      1. That plus having a strong language that makes it easy to express safely efficient code. Most of the performance gains come from how easy it is to measure and refactor code where it matters without impacting readability, which is something that I find a lot more difficult with other programming languages, even in this era of AI.
    4. If I was in charge of Java applications, I'd rewrite them all to C#, Rust, Zig, or even Golang which I don't praise, even if that meant for them to be slower than the original Java, only to escape the Oracle hell.