How low-level is Rust?


#22

Oh ok thanks bro.


#23

Beacause most very low level code (whatever it means) in the world is written in C and FFI is actually exposing symbols in way that C does it.


#24

So in other words we can’t use Rust syntax without C, right?


#25

No - Rust’s syntax is parsed by rustc (written in Rust) and compiled to the same binary format as any other compiled language (ELF, for example). The symbols produced and their format in that binary are the same regardless of the compiler that produced them - it’s all just machine code (except maybe for the issue of name mangling, but you don’t need to worry about that at this stage too much). Rust is not fundamentally dependent on C in any way - for example, I’m currently building a microkernel in Rust - there’s not a single line of C in the entire project.


#26

Technically most compiler checks are not suspended. The only difference is that you can now dereference raw pointers as well as call other functions marked unsafe. Everything else works the same.


#27

There is an entire operating system written in Rust: https://www.redox-os.org/ so for all practical purposes Rust can be as low-level as C and C++.

If you compare C, C++ and Rust feature-by-feature you will find some differences, but these aren’t “oops, it can’t do that, game over!” situations, but just different approaches/solutions. They can solve all the same problems in general.


#28

Are you using FFI by any chance?

Also are you working on Redox OS?


#29

Yes, but only to functions written in assembly, not C.

Nope, I work on Pebble. Redox has a slightly different approach - I don’t think any of their code is written directly in C any more, but they provide a libc written in Rust. This allows them to run C code directly under Redox, whereas Pebble does not provide any C runtime support at all and is not POSIX compliant. This means porting stuff is going to be much more difficult, but is more ‘pure’ imo

More on-topic: Rust is as good / better at everything C can do, low-level wise. You can mess around with how stuff is linked, lay memory out how you want, do raw pointer arithmetic, and emit assembly directly when you need to. Zero-cost abstraction is not a lie in Rust - while it feels like you’re writing code at a much higher level, that is all just abstraction. Whether you like that approach (for one, I love it), is personal preference, but I don’t think it’s possible to objectively say C is lower-level than Rust.


#30

Worth mentioning that some stuff, like inline asm emission, will require using a nightly compiler which comes with potential headaches (i.e. breakage).

Although it’s natural to compare Rust to C, a better comparison is against C++. And currently C++ has some features that, although not showstoppers, are missing in Rust; const generics is likely the one that sticks out the most but there are others (e.g. custom allocators, placement new, etc).

But Rust will eventually get there, it’s just a matter of what you want to have today.


#31

Without leaping to conclusions about your friend, I can say from experience that there a lot of people who make statements (often strongly positive or negative) about Rust without actually understanding enough of the language to support those statements.

I don’t know if your friend actually falls into that camp, and in fact I don’t actually know what he meant by that statement, but if he has questions about Rust, please encourage him to come and ask on this forum, as you have!


#32

Is Pebble an OS right? Is it supposed to be better than Redox?

How does Rust feel like a high level programming language when you are doing low level programming exactly?


#33

He hasn’t used Rust and he did say he thinks this is the case.


#34

You said you have not previously programmed in a low-level language, correct? I think you will need some experience programming in (any) low-level language before fully understanding this question, let alone understanding the answer!

But to give a very abstract explanation:

  • In a technical sense, “low-level/high-level” refers to how much control the programmer has over the behavior of the runtime environment, and how close that runtime environment is to “bare metal” (i.e. the actual CPU/GPU hardware). Rust is low-level because it provides low-level capabilities. This means that a program written in Rust can (depending on how and where it’s run) have full control over the hardware on which it is being executed.
  • In a less technical but still commonly used sense, “low-level/high-level” refers to how strong the abstractions are over the low-level capabilities of the language. By “strong abstractions” I mean two things: both that the API for performing tasks is convenient, and that the abstraction does not “leak” (meaning, essentially, that there is no need for the programmer to understand what’s “underneath” the abstraction in order to use it correctly). Rust feels (or can feel) high-level for two reasons:
    • The syntax and semantics provided in the core language and standard API are, for the most part, “strong abstractions” in above sense.
    • Rust provides very good tools to create new APIs that are “strong abstractions” in the above sense.

Note that in the second definition, “low level” languages can still have “high level” libraries, since those libraries form a new API on top of the syntax of the language itself.

I have used all three. C and C++ are, in my opinion, relatively easy to use but nearly impossible to use correctly; they are, moreover, a “necessary evil” of a bygone era. The form in which they currently exist is something of a historical accident: there are good reasons for most of their design oddities (/problems), and good reasons for not “fixing” these issues in future language versions, but that does not mean that they are “well designed” when compared to a language like Rust that was designed with the benefit of decades’ worth of language-design “lessons learned” from which to draw. This, I think, is more or less what people mean when they talk about “modern” language. Rust is in this sense a “modern” language; C and C++ are simply not.

(Some would probably argue that C11 and C++17 are “modern” languages distinct from C89 and C++98. I would argue that the attempts at backwards compatibility in the “modern” versions keeps them from actually becoming truly “modern”.)

Yes, it’s an OS. Define “better”! :laughing: don’t know much about Pebble, but its goals are very different from those of Redox, and it is not nearly as far along in its development. Both of these aspects should be immediately clear from the READMEs of the respective projects.

Sorry, he thinks what is the case, exactly?


#35

Oh ok that is cool,

So I am going to learn Rust then and use it in robotics and game development (which is what I plan to do in the near future). Is it all the time that the user will feel like they are using a high level programming language?

My friend thinks that with Rust you can’t “differentiate between different types of memory addresses”


#36

I’m not quite sure how to answer that. Do you have any experience with high level programming languages? If so, which ones? Rust will almost certainly not “feel” like whatever language(s) you’ve previously used, but if you tell us what languages (if any) you’re familiar with, we can explain in what ways Rust will feel less “high level”.

If you are not familiar with any programming languages yet, then I think you should stop worrying about “high level” versus “low level” and just start learning some languages. I don’t think it’s possible to understand the distinction between “high level” and “low level” in any meaningful way without some background.

(And to reiterate something said above: it is good to learn multiple languages. Moreover, it’s widely agreed that the more languages you learn, the easier it is to learn new ones; yes, some languages, including Rust, have some “strange” aspects that make them harder to learn in some ways than others, but most of the general principles of computing and programming are the same between languages, and many languages share a lot of similar syntax and keywords.)

As someone just starting out in game development, you actually do not necessarily want a “low level” language. Just because a language can provide direct hardware control that other languages can’t doesn’t mean that you want that level of control when writing a program.

For game development, you will need some kind of game engine/framework (unless you’re writing a text adventure). These exist in Rust but are generally less mature than their C++ counterparts, because the language itself is less mature and less widely used.

Because Rust is low-level, it’s a great candidate language for writing a new game engine, but that’s not generally part of “game development” unless you’re a AAA studio creating the next Unreal Tournament (hence, the “Unreal Engine”).

That said, you certainly can write games in Rust; here are the resources you’ll need: http://arewegameyet.com/

As a C++ programmer who understands many (though not all) of the “dark corners” of the language, I don’t know what your friend means by this. From some of the comments above, you can see that other forum members don’t understand this statement either. For us to explain how Rust and C++ compare in this regard, you will need to get a clearer explanation from your friend of what he means by this. However, I don’t believe C++ has any features that provide some kind of low-level functionality with no equivalent functionality in Rust. (The alloca thing mentioned above hasn’t made its way into the C++ standard yet, and possibly never will.)


#37

I’m not quite sure how to answer that. Do you have any experience with high level programming languages? If so, which ones? Rust will almost certainly not “feel” like whatever language(s) you’ve previously used, but if you tell us what languages (if any) you’re familiar with, we can explain in what ways Rust will feel less “high level”.

So I have done a bit of Java and C# before through University so yes I have experience with programming. I have tried a bit of C++ but that is only with basic stuff such as using methods, variables etc. Are there times where the user would have to use low level stuff in Rust while it does not feel like they are using high level stuff?

There is a FOSS game engine that is soon bringing Rust support to it so I might want to try it out. I thought Rust can feel like a high level programming language plus it has a lot of safety that is why I would want to use it over C++.

I don’t get my friend either, he did do computer science so maybe what he was talking about was very low level stuff.


#38

The one major piece of functionality that may currently be better supported in C++ than in Rust (though I wouldn’t necessarily call it “low level”) is compile-time evaluation (CTE). (What that means isn’t terribly relevant to this discussion, so I won’t provide a summary.) Rust does provide some CTE functionality, but I believe it’s not yet quite as full-featured as what’s in C++14 (i.e. available in C++ compilers that have full support for the 2014 version of the language standard). I do expect, however, that Rust will get much better CTE support over the next year or two.


#39

That’s ok if it gets better overtime that is awesome


#40

Would it be fair to rephrase this as “are there times when the language will feel more cumbersome than C# or Java?” If so, then I would say yes, you should probably expect the language to feel somewhat more cumbersome.

Or, if you’re asking whether it’s common for programmers to be forced to use the “low-level” features when they’d rather use a high-level abstraction, I may not be the best person to answer that (not having seen much production Rust code), but from afar, and from what I’ve seen of code samples, etc., that certainly does not seem to be the case.

I (and I imagine many others on this forum) also have academic CS experience! :smiley: So please do encourage him to come and ask his question here.

That’s hardly unique to Rust; even Fortran is scheduled to have a language update released later this year!


#41

I wonder if Rust will feel as cumbersome than C at times, its ok if you don’t know.

I could encourage my friend to come over here but he doesn’t at the moment have interest with Rust since he has learnt C++.

What is Fortran like, is it as low level as C and Rust?