First steps with Rust
docs.microsoft.com
docs.microsoft.com
Also, I would still really like to learn Rust properly, but I don't have any use for it currently either at my day job nor for my side projects.
1. https://docs.microsoft.com/en-us/learn/paths/go-first-steps/ 2. https://docs.microsoft.com/en-us/learn/paths/java-on-azure/
I made a bot library for https://turntable.fm/ in javascript -> https://github.com/alaingilbert/Turntable-API
Then I rebuilt it in go -> https://github.com/alaingilbert/ttapi
Then I tried to write it in rust, but the pattern isn't really good with the borrow checker, I cannot make this work -> https://github.com/alaingilbert/rust-ttapi/blob/47282b7a334d...
So if someone can find a good pattern to use for this type of library, I would gladly want to learn.
Pull requests are welcome, I'm also always on discord if you want to chat.
let bot = Arc::new(bot);
bot.on_speak({ let bot = bot.clone(); move |evt: SpeakEvt| { ... }});
Edit to add: Alternatively, the bot could pass a mutable reference to itself to the callback when it is invoked. bot.on_speak(|bot, evt: SpeakEvt| { ... })Anyway, if you can make it work, I'll study your code religiously !
Yes, async closures are not currently stable, which is a huge pain in the ass: you have to use a regular closure with an `async` block inside, but said async block will usually need to be an `async move` block, which requires more contorsions because you can't just use stuff the closure owns as that'd make said closure FnOnce (the closure's item is moved into the `async move` block meaning the closure is destroyed). This is usually solved by putting the item behind an `Arc` (if it's too costly to be directly copied, or if you want / need to mutate it), this way you can `clone()` the arc so the async move block has its own "copy".
Alternatively, have the closure immediately and only call into an async function or method.
I can't wait for async closures, though, I'm sure others have their own bugbears but that's by far my biggest pain in the ass when using async rust.
It's a bit of boilerplate to define, but then your client code can look something like this:
while Some(event) = bot.try_next().await? {
match event {
Event::Speak { text, .. } => {
bot.speak(&text).await?;
}
_ => {}
}
}But this is just the start of your problems. To use Async, your Fn type should now also return a Future since these async tags will infect all your functions and their returns.
tl;dr: I'll start over and use Channels.
Microsoft don't care if that is a Rust, Java, Python, Visual Basic or PowerShell application. They only care that you choose to do it in Azure (so lets learn the Microsoft centric ways early) though.
- Conway's Game of Life
- Graphics stuff (raytracing, procedural generation, etc)
- Parsers/interpreters/compilers
- Command-line tools
None of these were things I needed exactly, but that's the fun of side projects :)
VS: Code doesn't put you down a particular "Microsoft developer path" at all.
True, but the directions to VSC in this case don't seem to relate to that, as these tutorials do the same for Go and Python. It's part of the strategy of this site. They want you to learn Python with VSC, and Go with VSC, not because they want you to learn Python or Go, but because they want you to use a Microsoft property in the process. Just as they aren't teaching you Git through this site, they are teaching you Git in the context of Github. All arrows are pointing toward Microsoft properties. I'm not saying this is a bad thing or wrong, but people here are asking "What's the catch" and it's all just marketing.
> VS: Code doesn't put you down a particular "Microsoft developer path" at all.
I disagree. Like I said, students emerging from high school are fully steeped in the Java ecosystem. A lot of them think that programming == Java. Many don't even have a concept that there is more than one programming language out there, and don't see a purpose of anything other than Java. The best thing MS can do to get people into .Net land is to get them out of JVM land. VSC is that vehicle. It doesn't matter what language they're using as long as they're using it in a Microsoft branded context. Not to mention half the people (I'm exaggerating of course) who set out to install VSC end up installing Visual Studio Community. I don't think that's intentional on Microsoft's part, but I'm sure they aren't mad at it.
[1] https://msrc-blog.microsoft.com/2019/11/07/using-rust-in-win...
https://docs.microsoft.com/en-us/cpp/code-quality/using-sal-...
1: https://docs.microsoft.com/en-us/windows-hardware/drivers/de...
They are one of the founding member of Rust Foundation, and from the article it seems that they do use Rust in some of their products.
https://opensrcsec.com/open_source_security_announces_rust_g...
https://www.embecosm.com/2021/01/12/gcc-rust-how-it-can-be-a...
This is an entirely new frontend written in C++, that shares no code with rustc (the official rust compiler). It might be merged some day in GCC proper.
But honestly, I'm more excited for rustc_codegen_gcc:
https://github.com/antoyo/rustc_codegen_gcc
It adds gcc as an alternative backend of the official Rust compiler. That way it is much more feasible to stay up to date as the language evolves.
Anyway the former two don't actually work right now. The one that does work today is mrustc, or at least it works for bootstrapping rustc; it doesn't have a borrow checker though (and instead assumes the program is correct). Also, mrustc isn't based on gcc.
https://github.com/thepowersgang/mrustc
(There's a fourth project, https://github.com/sapir/gcc-rust, but it seems abandoned)
The problem is when you have multiple implementations of languages that are effectively defined by their reference implementation, then the alternatives are usually an exercise in frustration.
Not to mention the terrible tooling to make multiple deployment targets possible (webpack, polyfills and whatnot)
Disclaimer : I'm still new and learning Java.
See the History section of https://en.wikipedia.org/wiki/OpenJDK?wprov=sfla1
On the other hand, I use gcc, clang, and MSVC++ on a regular basis. But... I think the reason I care about multiple C++ compilers is mostly because there’s no “one compiler that is ergonomic to use everywhere” and I end up writing better code because of it (eg gcc warning about something clang doesn’t care about).
For Python, I mostly just care that it Just Works everywhere (modulo compiler setup for building C modules)
I'm glad that pypy exists because it forces cpython to do something about performance, but for python overall it's a pretty niche tool.
If that's important, why not pretend that your project is in "Clang C++" rather than C++? Clang compiles to at least all the platforms that Rust does.
> not to mention the whole mess around dependencies in C++ code
Agreed. I feel like the proliferation of header-only libraries is a sign that something's seriously wrong here.
Standards exist to make multiple implementations palatable.
See Python for a stunning example where they botched the standardization effort and ruined the language for good.
My opinion echoed by many top people in reverse engineering industry.
Modern C++ is obfuscated by default due to templates, inlined functions and of course OOP.
For example, Marcus Hutchins famously echoed Boost is a cluster fuck of sadness.
My point is not about obfuscation anyway but it does helps obfuscation to some extent. It's about reverse engineering the optimized code and recover the original non-optimized code which can have a lot of use-cases.
https://www.msreverseengineering.com had a course on this subject. Experienced ones can reverse everything but my point is that it increase the barrier.
https://thephilbert.io/ is the primary developer's blog and has status updates.
I've implemented a basic ML variant before, and maybe half a dozen different lisps. Rust is only BARELY functional. A C++ guy ought to know better!
Believe me, I'm not interested in Rust for Rust's sake. If there were a GNU implementation, I could see writing code generators for Rust a little less cumbersome than trying to target C or LLVM IR or Wasm.
Realistically, I see Zig winning the fight that Rust is trying to fight, and C++'s headaches being replaced with Rust's headaches.
There is no fight. There is made-up flame-war. Every war happen at HN and Reddit's Echochamber not at Real World.
Every languages has headaches. You won't find a perfect language ever.
You can't do serious Rust if you don't understand functional aspects.
I know C++, Haskell and Rust. Like many says Rust is a functional language disguised as imperative. There were case studies on Rust where a one with Haskell background more like to learn it faster than a one with C++ background.
The Rust book don't show you the functional parts at beginning to build your intuition but once you drive deeper you will realize what I meant.
https://ceronman.com/2020/09/17/is-rust-a-functional-languag...
Rust does have a lot of nice ideas borrowed (hehe) from functional programming, but it's far from being FP!
On a tangent: you're comment about learning a FP before learning Rust is great advice, but not for the reasons you initially intended perhaps. Learning FP in general is great, since it teaches you a different way of thinking from the "classical" way programmers think. So, it's great to learn FP for anyone, regardless of whether it's for Rust's sake (it will help a bit with reasoning about some Rust concepts and idioms, though), or not.
Graydon Hoare mentions Rust as linear ML in C++ clothing.
https://twitter.com/graydon_pub/status/1154476823557754880
I empathized the can't deny relationship between Rust and FP. It doesn't means Rust is a pure FP language. I always said same thing about C++ templates too.
"Until then, you can think of String data as string data that can change as your program runs, while &str are immutable views into string data that do not CHANGES as your program runs."
// Instantiate a tuple struct by passing the values in the same order as defined. let origin = Point2D(0, 0) // Missing ;
Not clear why one would choose this over the official rust documentation and tutorials.
Oh and also - it’s a trap. Microsoft are not friends of free software.
Please don't make vague accusations. If you have something substantive to add - describe it.
Open source has "won" in the meantime. Why would Microsoft be interested in turning back the clock now that the money is in services, no longer in software.
I don't agree with the GP comment, but, i doubt they'd make this mistake again even if they believe it.
How does a freely available tutorial on a programming language have anything to do with someone's position on free software?
Would I call it a trap? No, but MS hasn't shown well enough that they are friends to free software.
> For example, if your distribution uses the GNOME desktop, locate the Show Applications icon (a grid of dots) docked on the left side of the screen, usually near the bottom. This icon opens a full-screen list of all applications installed on your system.
Why would they be teaching Linux beginners how to use GNOME if that was their opinion?