5 ms·
Correct me if I'm wrong, but I see nothing in the Rust example that couldn't just as well be implemented in C++. A comparison to C would have made more sense.
by codr7 3y ago
Correct me if I'm wrong, but I see nothing in the Rust example that couldn't just as well be implemented in C++.
A comparison to C would have made more sense.
- IshKebab 3y agoIt could, but the comparison to Arduino still makes more sense since that's very well known and is pretty much C. It makes very little use of C++ features. Especially advanced stuff like this - probably partly to avoid difficult error messages for beginners and partly because the Arduino developers (the original ones at least) were shit at API design.
- pjmlp 3y agoYeah, but then the example is anyway flawed, type level programming is also a thing in C++.
- sophacles 3y agoSorry would that be any C++, modern C++ (as described 10 years ago), modern C++ (as described 5 years ago), modern C++ (as described today), a special C++ subset known to MCU folks or something else?
- pjmlp 3y agoSarcasm ignored. Type level programming is possible in C++98. Easy to reach for in most embedded compilers, when people actually use C++ compilers for C++, and not the C subset.
- sophacles 3y agoI see you've made this claim in many places in the thread. Care to provide an example, maybe back your words? I can declare factoring large numbers is "trivial" too, but until I show my work, everyone will rightly declare me a kook.
- pjmlp 3y agoI also provided an example from CppCon, yours to find out which comment, with that attitude. Apparently you missed that one.
- tialaramex 3y agoC++ inherits from C the flaw that it is as Dennis Ritchie put it "Strongly typed but weakly checked". In this case that hurts really badly because it means your C++ compiler is likely to let you do stuff that's nonsense, because checking isn't part of the job description, if you claim this Duck is a Goose the C++ compiler just rolls its eyes, sure whatever, however rustc says that is a Duck, you said it's a Goose but it is not, that's an error. That checking means a hard left shift for such bug finding, which can mean a substantial direct financial saving on QA or an improvement in feature velocity.
- pjmlp 3y agoYeah, copy-paste compatibility is a blessing for adoption, and a curse for herding cats into better coding practices. Same can be told about TypeScript, Groovy or any other language that follows the same adoption model.
- morelisp 3y agoI program MCUs in C++ as a hobby, and I'm not sure how I would do this in C++. Idiomatically I believe you could use move semantics to invalidate a "handle" to a pin when switching its type, but that wouldn't fail at compile-time. With ownership you really have something in your execution that "is" the pin by virtue of only one value of that pin existing at a time. See also https://docs.google.com/document/d/e/2PACX-1vSt2VB1zQAJ6JDMaIA9PlmEgBxz2K5Tx6w2JqJNeYCy0gU4aoubdTxlENSKNSrQ2TXqPWcuwtXe6PlO/pub https://docs.google.com/document/d/e/2PACX-1vSt2VB1zQAJ6JDMa... for the general case.
- codr7 3y agoAs long as your final handle has the correct type, I see nothing mentioned in the article than couldn't be done just as easy in C++. Ownership is a different beast, and definitely more manual/error prone in other languages; but you definitely pay a price for that.
- morelisp 3y ago> As long as your final handle has the correct type Come on. Ensuring that is the whole game!
- codr7 3y agoYeah, and it's trivial in C++, what's your point? The example looks like it's been custom tailored to show how awesome Rust is, but then the post fails to even make the point (however contrived). Why the hell would you want to change the direction of a pin anyway? Just declare it as Pin<Input> or Pin<Output>.
- Warwolt 3y agoThere's no way in C++ to _statically_ guarantee that you don't simultaneously have the floating pin handle and the output pin handle. You cannot do it.
- 3y ago
- pjmlp 3y agoYeah, many posts from Rust Evangelism Strike Force fail to gain appreciation from the target audience, when they clearly show a lack of understanding of C++ capabilities.
- codr7 3y agoI swear: if it wasn't for the eerie woke mob mentality surrounding the language, I might actually give it a second glance; but there's no chance in hell I'll put my energy into something this fundamentalistic.
- shakow 3y agoThe article compares types-assisted programming to ‶raw″ programming. It dumps on the Arduino stdlib, not C++ itself. The example is probably in Rust simply because that's what the author is using.