This seems like a nice guide and I'll certainly peruse it further.
But I'm just going to add my personal observation as a lifelong embedded C developer: I hate the Rust language syntax.
I'm not sure what it is but just trying to grok Rust code grinds my cognitive gears. I'm sure it all serves a purpose and I'm just a cranky old dude that will be left beind someday but, jesus, it just doesn't flow for me.
I don't mind the syntax, the bigger issue for me is that a lot of necessary features have been locked into nightly forever, like inline asm. If the language can ever mature enough to have these features in stable I would use it in a heartbeat. Well, that and the usual issue with it having a severely limited back-end selection compared with gcc.
My secondary peeve is that Rust is still evolving. I get that all languages do this at some velocity, C++ being one of them, but the fact this 'safe' language is adding 'unsafe' feedbags on the spec just gives me an uneasy feeling about the ecosystem.
Good news! Inline assembly will be available in stable starting next month. In fact, it's available in beta (which is a lot less bleeding-edge than nightly, with a lot fewer bugs) right now.
The rustc_codegen_gcc project aims to solve the backend-availability problem.
most of inline asm is being made available, but not all. My embedded project still needs stuff that's not stable yet. Still extremely excited that it's shipping.
You're not the only one. Been coding for 15 years in C and I had an easier time getting into Python, Assembly, Java, and Go. There is something about Rust that just seems harder than it should be.
I think since it's close to C, my mind wants to read it like C. It's a problem with my brains prefetcher.
I've heard this from quite a few people, and I believe that it's an experience they're having, but I'm having a hard time understanding it. If you could try to give some impression of what you find difficult and how, even it's subjective or fuzzy, I'd appreciate it as a way to get a better understanding.
(Exception: Rust's syntax for closures is terrible and I don't know anyone who defends it.)
Rust's syntax for closures is extremely close to Ruby's; the only bad thing about it is that it's extremely close but not identical, hahah. (Only said half seriously. I think the syntax is fine, and possibly the best syntax possible, but understand others may not agree and that's fine.)
Okay, I suppose it has any defenders. I still don't like how || can be either logical-or or the parameters of a nullary closure, especially with move closures since "move" looks like an identifier. Personally, I would have gone with Java's or JavaScript's syntax.
I'm not going to get into nitpicking because then it becomes a chain of "well maybe you're too stupid to get it", which I probably am but considering you're hearing from a few people then maybe there's something else going on.
For starters, the reference/borrow checking stuff is opaque. The tick is a lousy visual choice of operator as is 'mut'. The idea that some statements need semicolon terminators while others do not? I don't even want to explore what that's about.
I started learning Go and Rust simultaneously. With Go I was up and running in a week, had real non-trivial projects done in a few months. With Rust it took many months to get started and im still not very productive.
Admittingly Rust solves a harder problem. But I think a huge part of this is also Go language and libraries being very well designed, which Rust could learn a few things from.
Anyway, why did I mention all that? Because Rust makes me feel "well maybe im too stupid to get it" all the time, and now I have realised that a large portion of that is due to ba design choices made by the Rust team and not my own stupidity.
We largely had similar experiences, but formed different conclusions.
Like you, with Go I was up and running rather quickly. I didn't have to think very hard. It was easy because I didn't have to pick up new concepts, only new syntax.
With Rust I had to learn some new concepts and internalize them, new concepts I generally find much harder than new syntax, but I believe I became a much better programmer (including when writing Go) as a consequence.
Now the journey is majority complete in both languages, and my conclusion isn't that Rust or Go made a pile of bad design choices, rather that the languages made different trade offs that appeal to different people in different circumstances.
Go pushes a lot of expectations of behavior during runtime onto the author while writing (don't share mutable state between threads without appropriate care, always remember to manually free your (not memory) resources, don't deref a null pointer, don't use a returned value if err != nil, etc).
Rust pushes a lot of expectations of knowledge onto the author while writing just to get the project to compile (ownership, lifetimes, sum types, address all the above mentioned Go expectations).
It's been years since I started using both languages, and I've spent months dealing with bugs in Go. I believe a lot of those bugs could have happened in any language, but also a lot wouldn't have made it past rustc.
Which is the winner for specific type of situation? I don't think we can know for a long time, studying such things is very difficult and takes a lot of time.
In the mean time, we gravitate towards our personal preferences, believing them to be superior for $reasons.
As a cranky (but not old) embedded C developer, I'm with you. Rust has a lot of great ideas, and it's a hell of a lot more readable than modern C++, but it's still like reading hieroglyphics sometimes.
1) Really short keywords and basic type names - pub, mut, fn, impl, i8/i16/i32, etc. They're not hard to understand on their own, but in practice they make the language visually choppy.
2) Maybe it's because I learned Kotlin and Typescript shortly before taking on Rust, but "->" feels inconsistent with the rest of the language. It should be a colon.
3) Rust's if statements follow the normal "if <condition> { <result> }" syntax. Yet, for some reason, each branch of a match statement goes "<condition> => <result>." What would have been wrong with "case <condition> { <result> }"? I know it's more characters, but putting a keyword at the beginning of the block would help to visually separate each branch.
4) Rust's closure syntax looks strange (and I've used Ruby before). Maybe that's just me, though.
Rust isn't perfect, but I don't want to discourage other embedded C programmers from giving it an honest shot. The embedded library support isn't really there yet, but the language itself is a huge upgrade over C and C++.
Is there really any mystery to why someone would prefer a language they know and are comfortable with. I'm more concerned why that seemed provocative enough to require inquiry. Rust is a very interesting language for sure, but there's an extremely robust c ecosystem that one would lose by transitioning at this point. And for library creators, there's much more to lose.
I felt this comment was incongruous, like it was a response to a question no one asked. I wanted to understand this better. I didn't interpret it as provocation. You seem to be reading a criticism of the C ecosystem into my question, as if everyone should drop C and learn Rust, but that is not what I meant nor what I believe.
Being comfortable with C is just fine, but doesn't satisfy me as an explanation. Eg, if I try to put myself in their shoes, being comfortable with C doesn't lead me to post this comment.
I saw something I didn't understand and wanted to understand better. Not much more to it.
23 comments
[ 3.5 ms ] story [ 64.1 ms ] threadIt reads like a diff, and is very effective, I'd say, for any programmer.
But I'm just going to add my personal observation as a lifelong embedded C developer: I hate the Rust language syntax.
I'm not sure what it is but just trying to grok Rust code grinds my cognitive gears. I'm sure it all serves a purpose and I'm just a cranky old dude that will be left beind someday but, jesus, it just doesn't flow for me.
The rustc_codegen_gcc project aims to solve the backend-availability problem.
I think since it's close to C, my mind wants to read it like C. It's a problem with my brains prefetcher.
Also, finding ` on a non-US keyboard is a pain. Not really related to embedded, but I just had to get it off my chest
(Exception: Rust's syntax for closures is terrible and I don't know anyone who defends it.)
For starters, the reference/borrow checking stuff is opaque. The tick is a lousy visual choice of operator as is 'mut'. The idea that some statements need semicolon terminators while others do not? I don't even want to explore what that's about.
Admittingly Rust solves a harder problem. But I think a huge part of this is also Go language and libraries being very well designed, which Rust could learn a few things from.
Anyway, why did I mention all that? Because Rust makes me feel "well maybe im too stupid to get it" all the time, and now I have realised that a large portion of that is due to ba design choices made by the Rust team and not my own stupidity.
Like you, with Go I was up and running rather quickly. I didn't have to think very hard. It was easy because I didn't have to pick up new concepts, only new syntax.
With Rust I had to learn some new concepts and internalize them, new concepts I generally find much harder than new syntax, but I believe I became a much better programmer (including when writing Go) as a consequence.
Now the journey is majority complete in both languages, and my conclusion isn't that Rust or Go made a pile of bad design choices, rather that the languages made different trade offs that appeal to different people in different circumstances.
Go pushes a lot of expectations of behavior during runtime onto the author while writing (don't share mutable state between threads without appropriate care, always remember to manually free your (not memory) resources, don't deref a null pointer, don't use a returned value if err != nil, etc).
Rust pushes a lot of expectations of knowledge onto the author while writing just to get the project to compile (ownership, lifetimes, sum types, address all the above mentioned Go expectations).
It's been years since I started using both languages, and I've spent months dealing with bugs in Go. I believe a lot of those bugs could have happened in any language, but also a lot wouldn't have made it past rustc.
Which is the winner for specific type of situation? I don't think we can know for a long time, studying such things is very difficult and takes a lot of time.
In the mean time, we gravitate towards our personal preferences, believing them to be superior for $reasons.
1) Really short keywords and basic type names - pub, mut, fn, impl, i8/i16/i32, etc. They're not hard to understand on their own, but in practice they make the language visually choppy.
2) Maybe it's because I learned Kotlin and Typescript shortly before taking on Rust, but "->" feels inconsistent with the rest of the language. It should be a colon.
3) Rust's if statements follow the normal "if <condition> { <result> }" syntax. Yet, for some reason, each branch of a match statement goes "<condition> => <result>." What would have been wrong with "case <condition> { <result> }"? I know it's more characters, but putting a keyword at the beginning of the block would help to visually separate each branch.
4) Rust's closure syntax looks strange (and I've used Ruby before). Maybe that's just me, though.
Rust isn't perfect, but I don't want to discourage other embedded C programmers from giving it an honest shot. The embedded library support isn't really there yet, but the language itself is a huge upgrade over C and C++.
(edit: I, for one, like the 'lifetimes.)
I saw something I didn't understand and wanted to understand better. Not much more to it.