4 ms·
Did you learn C (or any other programming language) by writing a multi-threaded web server in it ? The Rust book actually ends by showing you how to do that, b
by fluffything 7y ago
Did you learn C (or any other programming language) by writing a multi-threaded web server in it ?
The Rust book actually ends by showing you how to do that, but... there are many reasons why that's the last chapter in the book. Starting there is definitely not the most efficient way of learning Rust.
- tick_tock_tick 7y agoI did for golang. Assuming you know how to program in general it's a very basic task.
- vertex-four 7y agoEhh... it's a basic task as long as you never touch shared mutable state. As soon as you have to do that, you need to work out what the abstraction for dealing with shared mutable state in your language of choice is.
- tick_tock_tick 7y agoI mean most languages you don't. You lock do some stuff then unlock. Rust prevents a whole lot of bugs by not making it this simple but that means if you pick anything with threading as a task to jump into the language your going to have a much harder time.
- fluffything 7y agoRust `Mutex`es are simpler to use than C++ ones.. so if you just `Mutex` your shared state away, writing an app on top of `actix-web` or `hyper` or `tokio` is dead easy once you learn how to use the framework, particularly if you have already done that before in Go.
- fluffything 7y agoDid you just use Go, or did you write your own Go implementation including its goroutines run-time and then write a web-server on top? Because if you did just use Go, in Rust you can just `cargo add actix-web` (or `tokio`, `hyper`, `async_std`, or any other goroutine-like run-time) and write a multi-threaded web-server in approx. one line of code. What the Rust book example shows is how to implement what the Go language uses inside its run-time for running goroutines, which is a much harder thing to do, and very different, even though that's something that every good web-server uses somewhere in its stack. Learning Rust by using `actix-web` to build a simple web-server is ok, but learning Rust (or any other programming language, really) by implementing `actix-web`, is not a very efficient way of learning the language.