Remix.run Logo
meisel 7 hours ago

Why did Ladybird even attempt this with Swift, but (I presume) not with Rust? If they're going to go to the trouble of adding another language, does Rust not have a better history of C++ interop? Not to mention, Swift's GC doesn't seem great for the browser's performance.

mlinksva 7 hours ago | parent | next [-]

https://x.com/awesomekling/status/1822236888188498031 https://x.com/awesomekling/status/1822239138038382684 "In the end it came down to Swift vs Rust, and Swift is strictly better in OO support and C++ interop."

ckcheng 4 hours ago | parent | next [-]

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

Why not D?

throwaway27448 3 hours ago | parent [-]

Why not rust? It's popilar, in wide adoption, with wide support, without the baggage of C++. What'e the downside?

user205738 3 hours ago | parent [-]

It is not backward compatible, the library system is immature, and there is no variety of different compilers for the language.

refulgentis 7 hours ago | parent | prev [-]

> Swift is strictly better in OO support and C++ interop

Fascinating.

They've shown the idea it is better on C++ interop is wrong.

I don't know enough to say Rust has same OO support as Swift, but I'm pretty sure it does. (my guess as a former Swift dev: "protocol oriented programming" was a buzzy thing that would have sounded novel, but amounted to "use traits" in rust parlance)

EDIT: Happy to hear a reply re: why downvotes, -3 is a little wild, given current replies don't raise any issues.

zozbot234 7 hours ago | parent | next [-]

Rust has straightforward support for every part of OOP other than implementation inheritance, and even implementation inheritance can be rephrased elegantly as the generic typestate pattern. (The two are effectively one and the same; if anything, generic typestate is likely more general.)

9rx 5 hours ago | parent | next [-]

> Rust has straightforward support for every part of OOP other than implementation inheritance

Except the only thing that makes OOP OOP: Message passing.

Granted, Swift only just barely supports it, and only for the sake of interop with Objective-C. Still, Swift has better OO support because of it. Rust doesn't even try.

Not that OOP is much of a goal. There is likely good reason why Smalltalk, Objective-C, and Ruby are really the only OOP languages in existence (some esoteric language nobody has ever heard of notwithstanding).

zozbot234 5 hours ago | parent [-]

You just need to define a trait, then you can use dynamic dispatch.

9rx 4 hours ago | parent [-]

You can, but then you don't get any of what OOP actually offers. Message passing isn't the same thing as dynamic dispatch. OOP is a very different paradigm.

anonymars 3 hours ago | parent [-]

I think you are both unknowingly talking past each other: my understanding is that Smalltalk-style "object-oriented programming" ("everything is a message!") is quite distinct from C++/C#/Java/Rust "object-oriented programming" ("my structs have methods!")

3 hours ago | parent [-]
[deleted]
rvz 7 hours ago | parent | prev [-]

I think we have seen enough since the best example of a Rust browser that is Servo, has taken them 14 years to reach v0.0.1.

So the approach of having a new language that requires a full rewrite (even with an LLM) is still a bad approach.

Fil-C likely can do the job without a massive rewrite and achieving safety for C and C++.

Job done.

EDIT: The authors of Ladybird have already dismissed using Rust, and with Servo progressing at a slow pace it clearly shows that Ladybird authors do not want something like that to happen to the project.

tomjakubowski 6 hours ago | parent | next [-]

Until just a couple years ago, Servo had been a pure research project with no goal of ever releasing a full browser (and it was abandoned by Mozilla in 2020).

Igalia had five engineers working full time who turned that science project into v0.0.1 in less than two years.

josephg 6 hours ago | parent | prev | next [-]

> Fil-C likely can do the job without a massive rewrite and achieving safety for C and C++.

So long as you don't mind a 2-4x performance & memory usage cost.

satvikpendem 6 hours ago | parent | prev | next [-]

Servo was essentially integrated into Firefox. It was not a browser in itself until it was put into a foundation on its own.

tvshtr 6 hours ago | parent | prev | next [-]

The RUST ecosystem barely just started getting into shape on the GUI toolkits frontend... So perhaps save your criticisms for something that wasn't born out of the vacuum.

bigyabai 6 hours ago | parent | prev [-]

> Fil-C likely can do the job

> Job done.

Seems like you forgot a few stops in your train of thought, Speed Racer.

7 hours ago | parent | prev [-]
[deleted]
gardaani an hour ago | parent | prev | next [-]

Here's Andreas Kling's 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

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

diath 6 hours ago | parent | prev | next [-]

> Why did Ladybird even attempt this with Swift, but (I presume) not with Rust? I

Probably the same reason why Rust is problematic in game development. The borrow checker and idiomatic Rust do not go well together with things that demand cyclic dependencies/references. Obviously there are ways around it but they're not very ergonomic/productive.

lukeh 7 hours ago | parent | prev | next [-]

Swift actually has excellent C++ interop [1] (compared to other languages, but, I guess, not good enough for Ladybird).

[1] https://www.swift.org/documentation/cxx-interop/

palata 7 hours ago | parent [-]

I actually looked into that recently (calling C++ from Swift), and I was surprised by the amount of limitations.

Said differently: the C++ interop did not support calling the C++ library I wanted to use, so I wrote a C wrapper.

gmueckl 5 hours ago | parent | next [-]

Binding to C++ is an extremely difficult and complex problem for any language that is similarly rich and has lots of (seemingly) equivalent features. The number of subtle incompatibilities and edge cases becomes nearly endless. It's not surprising that some C++ code can't be bound properly.

zadikian 5 hours ago | parent | prev [-]

I did this a long time ago as Swift calling Objective-C++ which can call C++ libs, in that case OpenCV. So it wasn't awful but did require making an ObjC++ wrapper, unless I did something wrong which is also possible.

jll29 6 hours ago | parent | prev | next [-]

Andreas Kling said Rust lacks OO, which he says is useful for GUI coding.

He even made an attempt at creating his own language, Jakt, under SerenityOS, but perhaps felt that C++ (earlier with, now without Swift) were the pragmatic choice for Ladybird.

stingraycharles 6 hours ago | parent [-]

But wasn’t Rust designed specifically for being a language for developing a rendering engine / web browser?

diath 6 hours ago | parent | next [-]

Rust initially started as a hobby project of a person who happened to be a Mozilla employee and later got sponsored by the foundation however it was not a language that was specifically designed with browsers in mind.

estebank 6 hours ago | parent | next [-]

The language's largest project before it hit 1.0 was Servo. The language wasn't designed for browsers, but it certainly was informed by them and their struggles with maintaining and developing Firefox.

throawayonthe 6 hours ago | parent | prev | next [-]

a lot of early rust design was driven by Servo - an internal mozilla project, and firefox component prototypes

hollerith 6 hours ago | parent | prev [-]

How could browsers not be on his mind when his job was to contribute to Firefox as a dev?

diath 6 hours ago | parent [-]

Do your hobbies revolve around the benefits for your employer? I don't mean it in a snarky way either, but given that Rust was initially written in OCaml, you could see how it could go like "I like programming, I like type systems but I want something procedural over functional so let me give it a go".

hollerith 6 hours ago | parent [-]

It can be described as a hobby project only in the sense that his employer would probably prefer that he spend all his time working on Firefox.

Tools to do X better are often designed by people who get paid a lot to do X and worry about losing their job if they are not good enough at X.

If he were to tell me that he didn't imagine Rust's helping with browser dev when he designed Rust, then I'd believe him, but the "circumstantial" evidence points strongly in the other direction.

LeFantome 4 hours ago | parent | prev | next [-]

> Rust designed specifically for being a language for developing a rendering engine

Rust was born at Mozilla, sort of. It was created by a Mozilla employee. The first "real" project to put it into action was Servo of which parts were adopted into Firefox. While Rust may not have been developed "specifically" to create a browser, it is a fair comment.

That said, Ladybird was started as part of the SerenityOS project. That entire project was built using C++. If the original goal of Serenity was to build an opeerating system, C++ would have felt like a reasonable choice at the time.

By the time Ladybird was looking for "better" languages than C++, Ladybird was already a large project and was making very heavy use of traditional OOP. Rust was evaluated but rejected because it did not support OOP well. Or, at least, it did not support integration into a large, C++ based, OOP project.

Perhaps, if Ladybird had first selected a languge to write a browser from scratch, they would have gone with Rust. We will never know,

We do know that Mozilla, despite being the de facto stewards of Rust at the time, and having a prototype web browser written in Rust (Servo), decided to drop both Rust and Servo. So, perhaps using Rust for browsers is not as open and shut as you imply.

stingraycharles 3 hours ago | parent [-]

I stand corrected, I was always under the impression that Rust was created specifically for Servo; TIL.

greazy 6 hours ago | parent | prev | next [-]

No. It was developed as a general purpose language.

I think you are conflating the development of Servo with the design and development of Rust.

steveklabnik 4 hours ago | parent | prev | next [-]

As someone who was on that team for a long time, we took that into consideration, but it was never specifically for that. There was some stuff the Servo team would have liked us to have implemented that we didn’t.

5 hours ago | parent | prev | next [-]
[deleted]
heavyset_go 6 hours ago | parent | prev [-]

Might not be the best choice for browser chrome, where an OOP paradigm for GUIs might make sense.

password4321 6 hours ago | parent | prev | next [-]

It will be interesting to see any further justification; I believe Rust was rejected previously because of the DOM hierarchy/OOP but not sure IIRC.

20240810 https://news.ycombinator.com/item?id=41208836 Ladybird browser to start using Swift language this fall

bergheim 7 hours ago | parent | prev | next [-]

I so wholeheartedly agree. You are making a new web browser - akin to a new OS - and you want it open source for everybody but you choose swift not rust?

rvz 7 hours ago | parent [-]

This experiment has shown that both are actually bad choices.

josephg 6 hours ago | parent [-]

Oh? They tried rust?

Lots of people seem really committed to OOP. Rust is definitely a bad fit if you can't imagine writing code without classes and objects. I don't think this makes rust is a bad language for the problem. Its just, perhaps, makes rust a bad language for some programmers.

zadikian 5 hours ago | parent [-]

It doesn't seem uncommon for someone to generally like Rust but still want to use something OO for UI. I'm in that boat. Never liked OOP much, but it makes sense sometimes.

antonvs 43 minutes ago | parent [-]

What OO features are you thinking of that Rust doesn't have?

Traits give you the ability to model typical GUI OO hierarchies, e.g.:

    trait Widget {
        fn layout(&mut self, constraints: Constraints);
        fn paint(&self, ctx: &mut PaintCtx);
        fn handle_event(&mut self, event: Event);
    }

    struct Button { ... }
    struct Label { ... }

    impl Widget for Button { ... }
    impl Widget for Label { ... }

    let mut widgets: Vec<Box<dyn Widget>> = Vec::new();
Implementation inheritance can be achieved with good old shared functions that take trait arguments, like this:

    fn paint_if_visible<W>(widget: &W, ctx: &mut PaintCtx)
    where
        W: HasBounds + HasVisibility,
    {
        if widget.is_visible() {
            ctx.paint_rect(widget.bounds());
        }
    }
You can also define default methods at the trait level.

This all ends up being much more precise, clear, and strongly typed than the typical OO inheritance model, while still following a similar overall structure.

You can see real world examples of this kind of thing in the various GUI toolkits for Rust, like Iced, gpui, egui, Dioxus, etc.

sparky4pro 31 minutes ago | parent | prev | next [-]

Swift != GC

elcritch 6 hours ago | parent | prev | next [-]

Also I believe one of the core LadyBird devs was an ex Apple employee on WebKit which has been using Swift as well.

LeFantome 4 hours ago | parent [-]

The Ladybird founder was one of the original KHTML devs and worked on Safari at Apple.

carefree-bob 7 hours ago | parent | prev [-]

The ladybird developers tried Rust and Swift both and voted to adopt Swift.