Swift (and other programming languages)

First a bit of context. As a follower / user of Haiku I became aware of Serenity - another hobbyist operating system - with its own browser called Ladybird. There have already been efforts to port this browser to Haiku. It was then announced that this browser will be forked from the main operating system which was seen as promising because the author of Serenity (Andreas Kling) specialised in browser design. Although Haiku already has its WebPositive browser, it languishes behind other web browsers. As with the rest of Serenity, Ladybird was written in C++ just like Haiku (and indeed Genode). So far so good.

However it was inevitable that many would ask whether C++ was an appropriate choice to write a new browser given the fad for “safe” languages. Whereas it might seem that language choice nowadays could be summed up as “the answer is Rust, now what was the question”, Ladybird decided to road test a few languages and - in a surprise development - announced that Swift worked best for them and they would adopt that in future.

This has led to a long and stimulating thread on Haiku forum about bringing Swift to Haiku. As far as Genode / Sculpt is concerned the benefits of being able to build Ladybird would seem to justify porting Swift, and these benefits would accrue with any further projects that use that language.

With the above in mind, has there been previous interest in bringing over Swift to Genode? Has much consideration been given to the benefits and the challenges in doing so? Would it provide a more accessible language for novices - like myself - than native C++ or the already established Rust?

I’ll be following responses to this topic with interest, as a possible user of Ladybird, and (even more so) in my quest for information on potential “C++ successors”.

Not much information I can provide myself, on the port potential and on the interest for laydbird. Looking at their FAQ I see they expect to have a first usable beta only in 2026, and not sure how big their team is, how experienced they are, and what “notch” they are aiming at: are they aiming at being as good as Falkon ? Or do they aim higher and want to actually go top notch and be better than even FireFox ?
To be honest, I can understand people shaking their head at the whole “web rat race” crazyness, with browsers becoming more complex than OSes, and people suggesting ‘we’ change course.
Sometimes I wish I had time to look into the Gopher and Gemini worlds, as alternatives to the http/html world ^^. But that’s to be expected since I’m also the type to look at NNTP as an alternative to modern forums, lol.

Re Swift, in my few years as a Genodian I don’t recall seeing Swift mentionned as a port candidate. Would need to take another look at it too, it’s been years since I did, I vaguely remember checking it out and dismissing it as “too bloated for what it brings to the table” or some such, don’t remember for sure.

If you’re trying to get your feet wet with programming, and feel shy asking for help doing C++ ^^, then I would give a fairly high recommendation to V (vlang.io)
After a one year hiatus, I’m myself going to get back into it. for a potential contract job. Will probably start this coming week on Debian. Some day it might even get ported to Genode and SculptOS (by the look of it, I’ll be the one doing the port, the compiler/interpreter is so simple and compact that I might even pull it off semi-easily).

It might not be a replacement for C++ at scale (I’m still dubious at their choice re. ctors and dtors, among other things), despite their targetting the language as fit for writing an Operating System (Vinix) and a web browser, but it sure beats the cr@p out of C++ when it comes to deployment, ease of use, intelligible compiler warnings and errors, and a whole host of other things ^^ Too many to list here, just take a look at their landing page.

Let’s hear it for more suggestions and questions!

1 Like

The Ladybird browser is certainly a long term project and it is not inconceivable that by the time it comes about we will all be using Servo driven browsers anyway. I agree with your sentiment that writing a programme to look at kitten pictures on other computers should not be a multi year project and that in an ideal world we would use a much simpler protocol like Gemini.

Thank you for the recommendation of V. My initial thought is that it might be the language that 9Front (fork of Plan 9) are looking for. Go was written by former employees of Bell labs, is seen by much of the Plan 9 community as building upon that tradition, and V positions itself as a better Go. It also compiles to C (used by Plan 9) rather than C++ (used by, say, Genode and Haiku). But I digress.

Rust by comparison strikes me as an overcomplicated language for an overcomplicated paradigm of computing. Its deployment seems to be driven by the diktats of big capital, just look at the corporate sponsors of Rust, a who’s who of the cloud computing megacorps.

9front: indeed – apart from the odd “no OOP” (uh?) requirement, I see a lot in common with V, in that wish-list of theirs.

Porting V to Haiku was not too much trouble a few years back BTW (and thus might still be feasible), if you do make the jump to coding and decide that you’d rather code there instead of on a Linux host.

Adding some sort of bindings to V to make it ‘talk’ to the Genode or Be APIs would be an interesting twist for sure. I have quite limited experience in V bindings, mainly related to ImGUI, Nuklear, SDL, if even that… But those are ‘custom’ widgets toolkits, whereas using native widgets would have my preference.


When it comes to picking technology and evaluating corporate sponsors one has (unfortunately) to be pragmatic… At least if you want to put food on the table. But I can think of at least one instance when my “penny-less tree-hugger” side was right ^^ .
That instance was when I was thinking of jumping ship from “Be2” and looking for a new home, and pondering the gap between Fuschia/Zircon and Genode/Nova. The former had some things going for it, on the rational and emotional side (several ex Be engineers were heading it, it had some conceptual ideas that seemed nifty, etc). But I eventually settled with Genode as it was more “here and now” (no hype/vaporware, no need for a VM: download, compile, test on actual bare metal, run classic Doom and so on ^^) and had concepts that were even more revolutionary, as I paged through the Genode Foundations PDF doc. Fuschia is pretty much dead now, so obviously I’m glad my “luddite” side won that inner debate back in 2018 ^^

1 Like

Perhaps also related to “gut feelings”, V looks promising, but I became aware of a possible whiff of toxic leadership surrounding the project. Nim by contrast seems to fill a similar niche and often comes up in discussions with those seeking an easier alternative to C++ within Haiku. I would probably be more likely to have a go with that.

Wow, is that a hostile article ^^
If I wasn’t already maintaining a (small) vweb project (to be migrated to veb soon) that would definitely drive me away from it screaming, never to look back again ^^
Beneath all the ad hominems the author does seem to have a point (or ten) though. Well that should be easy to validate since he gives his homework (repro examples and version of V used to repro). If they repro then that’d be a show stopper for using it in production: memory management must be flawless IMHO.

Anyway that’d confirm the first impression I had a few years ago: the V language can be the first choice for some people and some (small) projects, including for learning programming, but is not ready for prime time/production. As the versioning implies, it’s at 0.4, not 1.0… V will definitely need heroics to implement all of its roadmap and to fix all its bugs, no contest here. And heroics are not in the cards in the “brave new world” that is unfolding in the West, I’m afraid. People are more and more into survival mode. One can’t be excessively altruistic with an empty stomach.

And even if they reach version 1.0 and hit all their design goals, their design choices might not allow them to scale to big projects (I want deterministic ctors and dtors gosh dang it, not “ersatz” !).


Re. Nim, I guess you can’t go wrong with any newer language that has decent support on your target OS. Well one risk which is common to ‘hobby’ languages is, will they still be around in five years ?

There’s a comparison of Nim and V at the bottom of this page: It seems that Nim is not quite in the same family as V and Go, it has a different philosophy. I’d have to check what exactly “significant whitespace” means – it could be something scary or something harmless. If you are okay with the Nim ‘way of things’ then you might very well have a blast (or at least “have a good time”, let’s not make it sound like programming is more sexy than it really is ^^). Whichever way to go, learning to code with a modern language is never something you get to regret as completely wasted time, because the fundamentals are more or less the same for most programming languages. You can take (part of) the learned knowledge to other languages later in your coding life. Don’t procrastinate too much on the choice of language and start writing your first lines of code, you might get hooked (and learn enough to then decide exactly which language is for you).

2 Likes

I found that testimonials from a number of people such as yourself who have obviously kicked the tyres of V and found it good seem to balance the negative experiences of others. As for Plan 9 community we mentioned up thread (yes, I was sad enough to ask!), whilst divided on the subject of V, many think the new language Zig has promise.

It was that comparison which made me paint Nim is a natural competitor for V. Nim is meant to be similar to Python, which is in turn meant to be a good language for noobs such as myself. As for the criticism that Nim outputs ugly C code - isn’t that just the present compiler, rather than intrinsic to the language itself?

The Permacomputing wiki has an assessment of how languages align with that movement’s goals, with a short list of candidates, and this includes Nim - although no-one has written the accompanying article yet. My attraction to alternative OS’ is driven perhaps by my sympathy with these goals.

As for Swift, perhaps justification beyond a Ladybird browser might be assisting the mobile aspirations of Sculpt on Pinephone by making it easier to import iOS apps?

1 Like

In the below I’m veering far off topic, it’s a good thing we’re posting only once or twice per week! Anyway here goes:
Never thought I’d see Permaculture mentionned in the IT world… Next thing I know, Colin Campbell and Jean Lahérrère will get a mention too ^^ Their site even mentions cornucopianism… Not surprised to see Collapse OS mentionned as that one is directly related.

Anyway it seems you’ve somewhat retraced my own steps a little, and ended up shortlisting the same three languages (Nim, Zig, V), except you seem to have done more ‘due diligence’ than I. (for instance I don’t know whether Zig is written in Zig, or if Nim is written in Nim, I just know that V is written in V, and can be bootstrapped from C). I’ll be curious to see where that leads you.

Kinda enjoyed the 9fans thread, some colorful language in there ^^ And also some more sober observations:

I tried for about a year to like Zig but the language never
resonated with me.

That’s kinda like (part of) the way I feel about this whole thingamadokie: I’ve invested so many years of my life to C++, that I feel if I ever “jump ship” then I have to ‘fall in love’, it has to be to a language which I feel cannot be improved upon. In terms of syntax obviously (since adapting to a syntax is what takes a lot of time when you’re used to the C++ syntax). I have this ‘feel’ with V (call me uneducated if you want, after all back at the uni my marks were not so high in the compiling/machine-code/LALR grammar/syntax parsing courses :grin: ). I don’t have that feeling with other languages. Anyway you get what you pay for, and this posts comes for free :wink: Of note though, a newbie will not have the same problem as I have, newbies are more keen on experimenting and discovering the world. In fact, why choose a language, try to get fluent in all 3 for a few months, and then choose ^^


A general observation which, despite sounding very abstract, might resonate with some: as I grow older, I tend to gravitate toward projects which are less “black box” like, that is to say, projects in which I could conceivably go “under the hood” and repair myself, in case the author(s) stop maintaining it. At a time I was fine with using GCC, even though it’s ultra complex inside and no one could possibly hope to improvise a fix without prior experience in the compiler universe. Indeed when GCC is buggy, I 100% rely on the GNU team to fix the bug. But as new languages appear, now I know of a language whose innards I could conceivably understand (okay that might not be the best example, given I’m weak on my uni compilation courses as mentionned). Same thing for the OS: I went from OS’es I had no control of, to Haiku, where I understand part of the code base (except the critical, crashy, kernel-land), to Genode, whose code base (unlike previous examples) I might hope to understand more widely or maybe even 90% some day, which would be unprecedented. I could cite additional (and more realistic) examples: going from gmake to jam, from git to fossil, and so on.
All those examples draw back to the “permacomputing” page cited above, which resonates with the concept of ‘shrinking the complexity onion’, to peel some layers so to speak, so thanks for that.
Anyway, that’s the gist of it: my chance of ever understanding some code bases is a big fat zero, whereas it’s non-zero for smaller, better written projects, and I lean towards the latter.

2 Likes

There’s also Odin, which seems to converge with V on some aspects but is mature and in actual production:

It is not (and does not attempt to be) object-oriented though, so no public/protected/private methods, a bit of a deal breaker for me… And no constructors, yikes (not sure how to create a UI widgets library without that – which makes me questions V as well).

1 Like

I saw an article on Odin on OSNews also this morning and briefly read about it.

Unable to comment on its relative merits but the homepage suggests it is heavily inspired by Pascal and other Wirth languages. Oberon was one of these and also used for an eponymous operating system, surely a rare example of the “whole stack” of language and OS being indigenous to Europe rather than the USA?

At University I played with Pascal for one semester and whilst too long ago to remember much, like you must be to have posted, my own interest was also piqued by Odin.

There is no article on Odin on Wikipedia which surprises me in this day and age.

Why Not OOP?

I’ve been around the block looking at alternative languages more than most and classical OOP needs to die a horrible death so it can be resurrected in a different form.

The only advantage of OOP is code reuse but the low-level underpinnings of vtables full of function pointers causes execution to become needlessly slow on some instances. Worse, there is no mechanical way for a code optimizer to detect unnecessarily virtualized functions and devirtualize them.

Virtual functions, otherwise referred to as using dynamic dispatch, require a vtable lookup and an indirect jump instruction for every function call. Nonvirtual functions use a single jump that needs no indirection.

My Background

As the primary maintainer of EEC, I’ve preferred AmigaE to C on my old Commodore Amigas as well as on MorphOS. AmigaE is object oriented but lighter than C++ in that it requires no name-mangling. This allows much simpler interoperability with C based operating systems.

“What’s wrong with that?” you might ask. It’s OS specific to the Amiga-like systems, using native function calls instead of anything portable. It cannot be made 64-bit friendly without breaking the APIs. Ultimately, Amigas are only programmed to show off what 30 year-old technology can do and as such, most people program Amigas in 68000 Assembly code to avoid even the slightest inefficiency. Nobody still uses AmigaE but myself and the members of my small team.

Other Things That Have Been Tried

Borrow Checking and Traits

Rust uses trait inheritance instead of classical inheritance. This allows inheritance to use static calls from generics, I think. The name mangling of Rust and C++ are not mutually compatible, however. Once you’ve mastered Rust’s borrow checker, you can apply what you’ve learned about variable lifetimes back to C++ and forget using Rust. The borrow checker is really all it brings to the table besides traits, in my estimation.

RAII

C++, like Rust, uses reference counting to do its deallocations when using RAII. This means accessing a stale value that’s no longer in the cache every time the program needs to know when it needs to deallocate an object or merely decrement the use count. This is not good cache usage.

Generational References

Vale seems to be the first programming language to use generational references in its memory management. It may be what I’ve been looking for for many years (despite high hopes in Rust and C++). If successful, it may be both fast and modular like Rust, C++ and AmigaE but more efficient still. The jury is still out since Vale hasn’t been completed yet.

3 Likes

Some of this is above my pay grade, I can only comment on these:

Interesting Amiga background! I remember from my AmigaDOS manuals that part of it was coded in something called BCPL (?) instead of C, but hadn’t really heard of E until now.

In C++, methods are not virtual by default, only if you add the virtual keyword do they consume a vtable pointer (and enable polymorphism). Optimization wise there is also final to tell the compiler to optimize away the look-up (?), didn’t start using that in my code yet though. Name-mangling, FBC (fragile base class) etc problems are pains indeed, they’re a (small) part of the reasons for my keeping an eye out for new languages to pop up during the last ten years or so.
RAII probably means different things to different people. Could be related to ref counting for some people. For me, RAII refers (among other things) to locking: an important example is the mutex-guard object’s idiom: the ctor locks the mutex, the dtor unlocks the mutex. I do a lot of multi-threaded programming in my apps, and locking is critical in that context… And that idiom is a big part of it. I know newer languages have alternative ways to lock/unlock safely… But there are many more similar idiomatic uses of RAII, beyond just locking/unlocking a mutex, which can also be addressed with a ctor/dtor pair. So I need a language with deterministic ctor/dtor (or, I need to be explained how to do it another way :slight_smile: )

Will take a look at Vale.

EDIT: looks interesting, might make it to my ‘shortlist’. The goal to eliminate heisenbugs seems super ambitious. Seems the compiler is written in a mix of… Scala (somehow that word makes me think of Dave Haynie ^^) and C++. On second thought, maybe Vale is written in Vale and github is simply unable to parse that.

3 Likes

Just to muddy the water, the most recent Vale blog (Crossing the Impossible FFI Boundary) names even more languages who they see as comparable:

But what if you’re a low-level, memory-safe language like Vale, Austral, or Ante? There’s no existing ecosystem of fast, memory-safe code to use.

Austral? Ante?

I could not help but click through to the Githubs of these three, and comparing the number of forks and contributors of each. On that crude measure all three languages seem to be getting similar traction. Austral may have some interesting ideas such as linear types - and capabilities like Genode! - whereas Ante seems to be an attempt to address the critiques of Rust, and higher level.

I don’t know how well it works in practice, but the capabilities metaphor in Austral would perhaps be something desirable when Genode develops its own systems language :grinning:. Austral is an endangered language in Polynesia so perhaps the project is a tad insensitive to appropriate the name?

1 Like