My progress at porting Ladybird, the SerenityOS Browser

Let’s be honest, C++ just isn’t that great of a language, and Swift is indeed a very good replacement for it. It keeps the good ideas from C++ (and Objective-C, the two are quite similar) and solve several of the performance issues and typical errors that C++ makes easy to happen, as well as making the code simpler to write.

Just creating a class in C++, it seems quite simple, right? But you have to remember to disable default copy constructors and assignment operators, since the default generated code most likely won’t work. You have to add “const” everywhere possible because it is not the default (it would make so much more sense to add “mutable” where needed). Using safe pointers (unique_ptr or shared_ptr) is a bit more code than naked pointers. You need to explicitly initialize some things (such as integers) in constructors, but not others (such as objects which have a default constructor). If you use a unique_ptr it will be initialized to nullptr, but if you use a naked pointer, it will have a random value. This is just annoying and tedious.

If I were to start a new project, Swift would definitely be one of the languages I’d consider for it. By reading the documentation, you can see that the people who designed it have been getting hit by the same problems I encounter while working on Haiku and other C++ projects (while Rust was designed by mostly C developers, I think, which have a bit different set of problems to solve).

So, a reasonable and not very surprising choice.

12 Likes