News for hackers. Stuff that matters.
Re:Teach Yourself Programming in Ten Years (1998) by zozbot234 on Monday January 15, 2024 @05:14PM (#39006783)
I wonder who's going to write the "Teach yourself Rust from scratch in 21 days" book. If C and even C++ can be learnt effectively as a first programming language, there's little reason why Rust couldn't be. And if not Rust, maybe Golang could play that role.
Re:Teach Yourself Programming in Ten Years (1998) by sn9 on Monday January 15, 2024 @05:22PM (#39006873)
The Rust book is basically that. An hour per day would probably get you through it in good time.
Re:Teach Yourself Programming in Ten Years (1998) by zozbot234 on Monday January 15, 2024 @05:41PM (#39007050)
TRPL assumes familiarity with some existing programming language, such that much of its focus is how Rust differs from more common languages. A true "from scratch" book would probably first teach idiomatic Rust as something not too different from a pure functional language (in that the default approach in Rust is to pass objects by value and forbid all shared mutable state, just like FP languages do) and introduce interior mutability subsequently as a way of supporting more "imperative" patterns of coding.
Re:Teach Yourself Programming in Ten Years (1998) by josephg on Tuesday January 16, 2024 @02:42AM (#39010555)
Golang yes, but not rust. I think rust is a terrible beginner language. Despite having decades of experience it took me about a month to feel productive in rust and stop “fighting the borrow checker”. I learned Go in about 12 hours.

Let beginners cut their teeth on stuff like Python and Go. Rust can wait.

Re:Teach Yourself Programming in Ten Years (1998) by zozbot234 on Tuesday January 16, 2024 @06:33AM (#39012135)
Yes but that's the thing, if you pass everything by value or read-only reference you don't have to deal with the borrow checker, and that's quite acceptable when you're first writing code. That's why I think Rust is almost a FP language in disguise with imperative features added after-the-fact - and it could be taught as such.
Re:Teach Yourself Programming in Ten Years (1998) by diarrhea on Tuesday January 16, 2024 @08:31AM (#39013051)
You’re not wrong, but precluding tons of concepts not suitable for beginners. “Just .copy() everything” shouldn’t need to be mentioned in an introductory book.
Re:Teach Yourself Programming in Ten Years (1998) by josephg on Tuesday January 16, 2024 @08:52AM (#39013250)
Yep; and cloning boxed objects everywhere often leads to slower rust code than the equivalent javascript or Go. And if you only teach a subset of rust without references, people can't read code snippets online, or most of the standard library documentation.

In comparison, Python, Go, Javascript and C# are all much easier to teach and leave students more able to make real software.

Re:Teach Yourself Programming in Ten Years (1998) by fl0ki on Tuesday January 16, 2024 @10:56AM (#39014763)
This only gets you so far. In today's software landscape, somebody is going to want to hit a HTTP JSON API to automate something in their second week, and they'll have a really rough time with how async Rust works today. Try explaining to a total beginner why they need Arc<Mutex<T>> and why the payload struct needs to be :Send+Sync+'static.

For all of Go's faults, "just send it over a channel bro" is easy to explain for trivial cases even if it often risks deadlocks and data races. To avoid the worst risks of this kind of code, Rust makes even trivial cases a big exercise. Go has an opportunity here to become more resistant to bugs without becoming less simple, but resistance to bugs doesn't appear to be a priority even for the Go team itself (e.g. even recently https://github.com/golang/go/issues/64474 )

Re:Teach Yourself Programming in Ten Years (1998) by fl0ki on Tuesday January 16, 2024 @10:48AM (#39014649)
I completely agree but do feel it needs qualifying. The problems beginners run into aren't usually the same as the problems experienced devs run into when adopting a language new to them, but where I see the two overlap I know something is a serious hazard in a language.

Java as a first language: won't like the boilerplate but won't have any point of comparison anyway, will get a few NPEs, might use threads and get data races but won't experience memory unsafety.

Go as a first language: much less boilerplate, but will still get nil panics, will be encouraged to use goroutines because every tutorial shows off how "easy" they are, will get data races with full blown memory unsafety immediately.

Rust as a first language: `None` // no examples found

I think Go as a beginner language would be better if people were discouraged from using goroutines instead of actively encouraged (the myth of "CSP solves everything"), otherwise I think it needs much better tooling to save people from walking off a cliff with their goroutines. And no, -race clearly isn't it, especially not for a beginner.

And in one respect I've found Go more of a hazard for experienced devs than beginners: the function signature of append() gives you the intuition of a functional programming append that never modifies the original slice. This has literally resulted in CVEs[1] even by experienced devs, especially combined with goroutines. Beginners won't have an intuition for this and will hopefully check the documentation instead of assuming.

[1] https://github.com/grafana/grafana/security/advisories/GHSA-...

Re:Teach Yourself Programming in Ten Years (1998) by lelanthran on Tuesday January 16, 2024 @05:27AM (#39011680)
> If C and even C++ can be learnt effectively as a first programming language, there's little reason why Rust couldn't be.

You must not be very familiar with Rust.