25 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.

7 comments

  1. [3]
    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.

    11 votes
    1. [2]
      ogre
      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.

      1 vote
      1. 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.

        6 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 😭

    6 votes
  3. 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

    2 votes
  4. 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.

    2 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).

    2 votes