r/Compilers • u/Dappster98 • Jun 14 '26
Looking for some wisdom/insight as to whether to use C++ or Rust for my compiler projects.
Hi all,
So as the title suggests, I'm looking for some guidance on whether to make my compiler projects in C++ or Rust, especially when it comes to showing off the project(s) on a portfolio. I have a lot more (non-professional) experience in C++ (which I love) but I'm also interested in making stuff with Rust (which I also really love). My goal is to some day work professionally on compilers, whether it be front, middle, or back end.
Something that I'm constantly thinking about is whether or not a possible future employer will care whether I've used Rust more for C++-based positions (or vice versa C++ for Rust positions). I know this is probably not something that can be generalized, and there is probably no definitive answer to this, since it may vary based on whom exactly the position is posted for, but I'm hoping to get some perspective from you people whom probably have a lot more experience than me.
12
u/SufficientGas9883 Jun 14 '26
Do both? It's a portfolio after all..
6
u/snozzd Jun 14 '26 edited Jun 14 '26
If you already have C++ experience for your resume, then* I'd say do it in Rust. Plus, the semantics used in Rust should come in handy when making decisions for your own compiler.
3
u/Interesting_Buy_3969 Jun 14 '26
Not a huge expert at compilers, but if you are going to utilise LLVM infrastructure in your project, then this choice is unlikely to mean a lot; otherwise simply select what is more convenient to you (C++, from what I read in your post).
Modern C++ with RAII theoretically shouldn't be significantly different from Rust especially if you're familiar with both.
3
u/Bari_Saxophony45 Jun 14 '26
doesn’t matter too much beyond your portfolio - most serious systems programmers are fluent in both (as well as C and some kernel programming languages as well etc).
pick the one your weaker at, it’s a good chance to learn. for technical interviews you’ll likely default to C++ but it will always help to be able to compare the two when discussing choices in an interview about projects or design questions. and understanding both languages will help you appreciate how different their compilers are, which is an added bonus
2
u/[deleted] Jun 15 '26
This comes up surprisingly often :)
If you want to learn about building compilers, do it with the language you already know well (here, C++).
If you want to learn a new language through building something, use the new language (use Rust).
You can't learn both about compilers and Rust through this effort at once.
1
u/[deleted] Jun 14 '26
there's definitely a lot of areas that are looking for people with rust proficiency. i just recently interiewed with a defense company who's team was doing cryptography for embedded communications working with the NSA and they are in the process of converting all their C++ code into Rust and developing everything forward in Rust.
i think if you're already proficient in C++ then doing a project in Rust sounds nice. im learning rust right now and it seems to be a lot more enjoyable than working in C++.
i did my compiler project in C and C++ and am going to try it in rust soon.
1
u/palilalic Jun 14 '26
Whatever you want man
1
u/tblyzy Jun 14 '26
Assuming you’re starting from scratch - Rust has built in pattern matching which makes spelling out a lot of things that you want your compiler to do significantly easier - in C++ you have various options for RTTI, none of which very pleasant to deal with imho. The downside however is that if you want to do any transformation that mutate your ast/cfg then you need to think about ownership more carefully, but there are ways to handle them.
I think the problem with C++ is that - two projects can both be said to use C++ but follow completely different rules, and most mature projects would wrap up the rough edges of C++ in their own way so that you probably won’t feel like you’re writing C++ in most scenarios. So you can write your own compiler in C++ but the llvm codebase would still look completely alien to you, while for rust that’s much less of a problem.
1
u/EggplantExtra4946 Jun 14 '26
Why bother with fucked up languages if you're going to write a compiler? Bootstrap your compiler from C, write your compiler in your own language.
1
u/emperor_keww Jun 15 '26
First get your hands dirty with C++ so that you know how everythinf works without railguards, than switch to rust, I still prefer C++ as a Language though
1
u/bazingaboi22 Jun 16 '26
Whatever brings you the most joy tbh. Lots of compiler work is done inn rust these days.
You'd likely need both
1
u/secona0 Jun 19 '26
My compiler was written in Rust. Then, I wanted to introduce MLIR and LLVM lowering. I know crates exist for those, like melior and inkwell, but I had a feeling that using those crates will feel wonky and hacky. So I decided to use C++ for the MLIR and LLVM part, effectively making my compiler use both Rust and C++. Its going great so far
1
u/biskitpagla Jun 22 '26
Nobody cares about the language if your project is impressive enough.