32 votes

Ladybird chooses Swift as its successor language to C++

I've copied the full tweet below (it's from August, I missed this news somehow):

We've been evaluating a number of C++ successor languages for @ladybirdbrowser , and the one best suited to our needs appears to be @SwiftLang đŸȘ¶

Over the last few months, I've asked a bunch of folks to pick some little part of our project and try rewriting it in the different languages we were evaluating. The feedback was very clear: everyone preferred Swift!

Why do we like Swift?

First off, Swift has both memory & data race safety (as of v6). It's also a modern language with solid ergonomics.

Something that matters to us a lot is OO. Web specs & browser internals tend to be highly object-oriented, and life is easier when you can model specs closely in your code. Swift has first-class OO support, in many ways even nicer than C++.

The Swift team is also investing heavily in C++ interop, which means there's a real path to incremental adoption, not just gigantic rewrites.

Strong ties to Apple?

Swift has historically been strongly tied to Apple and their platforms, but in the last year, there's been a push for "swiftlang" to become more independent. (It's now in a separate GitHub org, no longer in "apple", for example).

Support for non-Apple platforms is also improving, as is the support for other, LSP-based development environments.

What happens next?

We aren't able to start using it just yet, as the current release of Swift ships with a version of Clang that's too old to grok our existing C++ codebase. But when Swift 6 comes out of beta this fall, we will begin using it!

No language is perfect, and there are a lot of things here that we don't know yet. I'm not aware of anyone doing browser engine stuff in Swift before, so we'll probably end up with feedback for the Swift team as well.

I'm super excited about this! We must steer Ladybird towards memory safety, and the first step is selecting a successor language that we can begin adopting very soon. đŸ€“đŸž


Nitter link:

https://nitter.poast.org/awesomekling/status/1822236888188498031

Original post:

https://x.com/awesomekling/status/1822236888188498031


Some of Kling's replies in that thread are also pretty interesting:

My general thoughts on Rust:
- Excellent for short-lived programs that transform input A to output B
- Clunky for long-lived programs that maintain large complex object graphs
- Really impressive ecosystem
- Toxic community

In the end it came down to Swift vs Rust, and Swift is strictly better in OO support and C++ interop.


The September monthly report for Ladybird released the day after I posted this. It provides basically the same information:

This Month in Ladybird September 2024

The section about Swift:

Successor language search progress

Over the past year, our core contributors have been exploring potential safe languages to complement or succeed C++. We evaluated several options, including Rust, Swift, Fil-C, and others. While some languages offered compelling features, many fell short in either C++ interoperability or providing the level of memory safety we needed.

After extensive testing and discussion, Swift emerged as the top choice among our core developers, thanks to the new Swift 6 interoperability features and its growing cross-platform support. As a result, we’ve decided to adopt Swift as our C++ successor language.

That said, this will be an incremental shift. The existing C++ codebase is deeply embedded in the project, and a complete rewrite would be impractical. Instead, we’ll be gradually introducing new components in Swift, carefully integrating them with our existing C++ code over time. Look forward to a dedicated blog post on the topic soon.

16 comments

  1. [10]
    creesch
    Link
    Interesting choice overall, I do wonder what it means for the short term future of the browser on various non Apple platforms. Even though the language might support more platforms now, I am...

    Interesting choice overall, I do wonder what it means for the short term future of the browser on various non Apple platforms. Even though the language might support more platforms now, I am willing to bet that the majority of developers still are Apple oriented ones.

    Overall, I don't think it matters that much. The browser is still far removed from prime time, so over time I am sure the language will attract a wider array of developers some of who will also contribute to the project.

    • Toxic community

    Huh, that is something that could use some more context. I am not active in either community, but so far from what I have seen everyone talking about RUST seems nice and helpful to each other.

    14 votes
    1. [9]
      ogre
      (edited )
      Link Parent
      I think the large community and surge in popularity has led to some Blub elitism. Of course that’s going to be any PL community but that elitism has peaked in the last couple of years for Rust....

      Toxic community

      I think the large community and surge in popularity has led to some Blub elitism. Of course that’s going to be any PL community but that elitism has peaked in the last couple of years for Rust.

      Though I still wouldn’t generalize the entire community as toxic.

      Edit: I believe I unintentionally gave credence to some of the uglier generalizations about the Rust community with my speculation about the origin of Kling’s criticism. In this speculation I gave Kling the benefit of the doubt and while I still think that’s fine I wasn’t aware it would stir more unsavory opinions out of the woodwork.

      3 votes
      1. [7]
        Lexinonymous
        Link Parent
        I don't use Rust or consider myself part of the community. Rustoceans are some of the friendliest people I know. They can be passionate about their language, but having been around when C++, Java,...

        I don't use Rust or consider myself part of the community.

        Rustoceans are some of the friendliest people I know. They can be passionate about their language, but having been around when C++, Java, and Python were the hot new languages with fanbases, their fans don't hold a candle to any of them.

        The large majority of the "toxicity" I've seen is actually out of the people complaining about Rustoceans, which range from "gotcha" level debunking of arguments to actual conspiracy theories. There are also some cases where someone posts an obnoxious comment about Rust, only to look into their post history and see that they actually don't like the language at all and are just stirring the pot.

        I have no way of knowing this for a certainty, but I have a pet theory that part of the issues stem from the fact that Rust was one of the earliest projects to embrace a Code of Conduct.

        14 votes
        1. wirelyre
          Link Parent
          Sorry for the necrobump — I have had this exact suspicion for a while now. It makes sense that the "toxic community" meme could germinate and spread from interactions where someone violates the...

          I have no way of knowing this for a certainty, but I have a pet theory that part of the issues stem from the fact that Rust was one of the earliest projects to embrace a Code of Conduct.

          Sorry for the necrobump — I have had this exact suspicion for a while now.

          It makes sense that the "toxic community" meme could germinate and spread from interactions where someone violates the code of conduct and is told off. The residual negativity, justified or not, is bound to be pointed somewhere.

          Ironic, of course, because in my experience the code of conduct has been incredibly effective. Like you say, the toxicity I can remember has disproportionately come from snide, clearly nontechnical or otherwise bad-faith criticism of the language or its community. And it feels so unfair to me that the "toxic" idea seems to arise from the outside and is still attributed to the inside.

          Honestly I'm kinda ambivalent about even writing this because it sounds like such an uncritical defence. "See? Rust lemmings can't even take criticism."

          I know that's ridiculous, but I actually have participated in Rust discussions on Reddit and IRC and stuff before, and every time I read "toxic" or "evangelism" or whatever I have to remind myself to roll my eyes rather than second-guess my own experiences and actions.

          I dunno. I'm a people watcher. I like trying to see the social tides. (A sociologist??) And in person I like to consider myself a people greaser. I lube them right up so they can fit together better. (A mechanic???)

          On a more positive note, to the extent that Rust community discussions are nontoxic, I wonder if that's due partly to the type checker being so strict. It's like a shared villain. Everybody loves a good villain.

          6 votes
        2. [5]
          spidicaballero
          (edited )
          Link Parent
          I’m not part of any community, but believe me the “rusteaceans” are the most obnoxious people I have ever seen(on twitter) and that’s saying much. At least with the racist you know that most of...

          I’m not part of any community, but believe me the “rusteaceans” are the most obnoxious people I have ever seen(on twitter) and that’s saying much. At least with the racist you know that most of them are trolling. But “rustaceans” are just incredibly awful people. I mean I’m trying not to generalize, and I know that’s not everyone from that community, but they tend to be really insufferable and no, I’m not guiding myself from a “meme”

          2 votes
          1. [2]
            ogre
            Link Parent
            Man, I was about to go to bed No. Your comment is putting Rustaceans beneath racists on twitter and that is plain wrong. You are generalizing and to a harmful extent. I normally wouldn’t dignify...

            Man, I was about to go to bed

            At least with the racist you know that most of them are trolling

            No. Your comment is putting Rustaceans beneath racists on twitter and that is plain wrong. You are generalizing and to a harmful extent.

            I normally wouldn’t dignify this with a response but I feel partially responsible for my comment earlier in the tree proceeding this. I disagree with everything you are saying and I think you should consider just how drastic of a false equivalence there is between racism and programming language elitism.

            10 votes
            1. spidicaballero
              Link Parent
              I will admit that it was drastic and maybe not the best way to express what I wanted to say, in my defense I was irritated and sleepy. The mentions about “rustaceans” toxicity didn’t come out of...

              I will admit that it was drastic and maybe not the best way to express what I wanted to say, in my defense I was irritated and sleepy. The mentions about “rustaceans” toxicity didn’t come out of nowhere and not just for technical reasons, anyway I tried to express too that I was not trying to generalize but I saw this behavior in many “rustaceans”, even the core team is just


              I’m not sure if I could call what they do “elitism”. Saying to people to the programming language they’re building should not exist, because we already have rust and they’re just wasting their time and blah blah, and in my comment you can see just how much I hate it, and is not only one person doing it, that why there are so much friction between “communities”, I think recently is not that bad

          2. [2]
            Minori
            Link Parent
            Maybe this is a difference between online and IRL communities? Every rustacean I've coincidentally met offline has been extremely nice and helpful (in general, unrelated to Rust). Kinda sounds...

            Maybe this is a difference between online and IRL communities? Every rustacean I've coincidentally met offline has been extremely nice and helpful (in general, unrelated to Rust).

            Kinda sounds like Twitter being Xitter. I'd expect most rustaceans to use BlueSky or Mastodon for technical reasons.

            4 votes
            1. spidicaballero
              Link Parent
              I started to think that every community has two sides, one when you try to enter and learn the language and other when you say that you don’t like something( and I mean valid criticisms) they do...

              I started to think that every community has two sides, one when you try to enter and learn the language and other when you say that you don’t like something( and I mean valid criticisms) they do things way way different than “usual”, specially the rust community that behaves like a cult basically, and again I’m not saying this because of a meme I’ve seen it from afar and it’s really disgusting. That why I mentioned that even for twitter standards, it is not nice, and still most of the community still is in twitter at least most known members.

              And I understand what you say, and I know is true, but men at some point it’s just tiresome to watch. And I kinda like the language, but at the same time I wouldn’t have to like to deal with that.

              Ironically this is the nicest rust user I know or at least the less toxic: https://x.com/DrawsMiguel

              1 vote
      2. wirelyre
        Link Parent
        In the interest of hopefully judoing this into a better discussion: Not only are these really good points, I think the second one is one of the greatest weaknesses of the language. Rooting...

        In this speculation I gave Kling the benefit of the doubt

        In the interest of hopefully judoing this into a better discussion:

        
 Swift is strictly better in OO support and C++ interop.
        
 [Rust is] clunky for long-lived programs that maintain large complex object graphs

        Not only are these really good points, I think the second one is one of the greatest weaknesses of the language.

        Rooting ownership in a stack frame, like Rust does (both stack- and heap-allocated values), ties object ownership to the call stack hard; also the way references project into other references implies a tree structure for data which simply doesn't work for more general graphs.

        I guess I should have known better than to necromance this one though, sorry about that. :-/

        4 votes
  2. arqalite
    Link
    I'm genuinely surprised Swift is so good outside the macOS ecosystem. I've been hearing about their desire to distance from Apple and become truly cross-platform which is delightful. I'm...

    I'm genuinely surprised Swift is so good outside the macOS ecosystem. I've been hearing about their desire to distance from Apple and become truly cross-platform which is delightful.

    I'm disappointed Rust didn't make the cut, but to be fair I do think Rust's C/C++ interop leaves a lot to be desired. You can fairly easily call C functions from Rust, but doing the opposite (which I assume the Ladybird team needs a lot more) can be literal hell to figure out.

    Also yes, toxic community 😭

    9 votes
  3. donn
    Link
    I hope this inspires more people to use Swift for systems programming - the current situation is a nightmare. I spent a solid hour googling how to make a threadpool with a number of max concurrent...

    I hope this inspires more people to use Swift for systems programming - the current situation is a nightmare. I spent a solid hour googling how to make a threadpool with a number of max concurrent workers yesterday and StackOverflow helpfully told me that I shouldn't worry about it and just let Grand Central Dispatch handle it.

    The computer ran out of memory.

    8 votes
  4. ignorabimus
    Link
    I think Swift is a pretty underrated programming language. I know a few people who argue "we need a higher-level Rust" (by which they usually mean "we need better tooling and not worse-is-better...

    I think Swift is a pretty underrated programming language. I know a few people who argue "we need a higher-level Rust" (by which they usually mean "we need better tooling and not worse-is-better language design"); I think this already exists and Swift kind of provides this.

    There's also some notes from the original Rust implementer here: https://graydon2.dreamwidth.org/5785.html

    4 votes
  5. ogre
    Link
    I wasn’t aware of Swift 6’s effort to offer better support for Linux and Windows, that’s really cool. I still need to read through the 5->6 changes to see what they’ve done to improve memory...

    I wasn’t aware of Swift 6’s effort to offer better support for Linux and Windows, that’s really cool. I still need to read through the 5->6 changes to see what they’ve done to improve memory safety and concurrency.

    Having recently learned more about Zig, I wonder if that was one of the languages they evaluated as a C++ replacement. It’s still underbaked right now but there are a few projects making good use of Zig in production. Is there a longer write up anywhere discussing all the languages they evaluated?

    • Clunky for long-lived programs that maintain large complex object graphs

    The Zed editor is great counter-example but I still agree it’s much harder to bootstrap complex applications in Rust. (Coming from a novice Rust programmer).

    4 votes
  6. [2]
    thismachine
    Link
    It's been my experience, at least, that the lack of Core Foundation and Foundation frameworks on anything other than macOS has led to a gap in what would otherwise be considered Swift's standard...

    It's been my experience, at least, that the lack of Core Foundation and Foundation frameworks on anything other than macOS has led to a gap in what would otherwise be considered Swift's standard library.

    4 votes
    1. ButteredToast
      (edited )
      Link Parent
      These gaps are being filled with the open source rewrite of Foundation, though, which should put Swift in a reasonably usable state for cross-platform work pretty soon. Even now it's dramatically...

      These gaps are being filled with the open source rewrite of Foundation, though, which should put Swift in a reasonably usable state for cross-platform work pretty soon.

      Even now it's dramatically more usable for that purpose than Objective-C ever was, with there being several Linux server packages (e.g. Vapor) as well as a Chromium UI for Windows (Arc) built with it.

      3 votes