Rust has more syntactic elements than the C, in this code that’s clear, but cleanliness can mean different things.
Rust has a module system, so no global namespace issues, but does require all of the :: separators.
Rust has cleaner ways of dealing with cross platform compile time switches, thus we don’t see the CPP macros for different platform targets.
To me, those are cleaner, but I’m familiar with Rust and C, which is why I asked.
entrypoint: ”main”
as the argument for a shader program seems like it could be turned into a default.Convention over configuration isn’t always the answer, but some times at least it can help reduce clutter.
In the future the api will perhaps have builders as an option.
&BlaDesc {
bla: 1,
blub: 2,
..Default::default()
}With the builder pattern, you can do so: require them in the builder constructor.
- The types help, seeing "WGPUSwapChainId" tells me exactly what sort of object is returned (a reference to some object held elsewhere), we don't get this in Rust because of type inference.
- Rust doesn't help in this example because it's just a bunch of API calls... so it's a more complex language for nothing. Obviously this doesn't generalize.
- The event handling is much simpler in the C code, this also doesn't generalize.
Check out RLS (the rust language server) to get intellisense like this working in your favorite editor.
I think the solution is for diff viewers incl. those on the web to support something like intellisense, but obviously we are a very long way away from that.
I tend to find, personally, that this kind of thing doesn't interfere strongly with reviewing. I think this is because I have an extensive background in dynamically typed languages and ones with strong inference like Rust, so I'm more used to it, whereas people who don't come from said backgrounds prefer more explicitness. YMMV of course!
-Z unstable-options -Zunpretty=hir,typed
// source
pub fn square(num: i32) -> i32 {
num * num
}
// expanded
use ::std::prelude::v1::*;
extern crate std;
pub fn square(num: i32)
-> i32 ({ ((num as i32) * (num as i32) as i32) } as i32)
You can try on https://rust.godbolt.org/Might be worth mentioning that (AFAIK) type inference is entirely optional in Rust. If you prefer to write explicit types on your decls that's fine. (I suspect there are pathological cases where the type is impractical to write, but you'd have been screwed then anyway.)
This won't help you when reading other people's code, obviously.