4 ms·
On the contrary, I feel rust could be a great language for students because the borrow checker will slap sense into them from early on and each error it throws
by allisdust 4y ago
On the contrary, I feel rust could be a great language for students because the borrow checker will slap sense into them from early on and each error it throws teaches them a little more on memory, data safety.
- nneonneo 4y agoI already teach borrowing and ownership semantics as ways to avoid memory issues in C. While Rust is a more complex language on the whole, the fundamentals of borrowing and ownership are more broadly applicable concepts.
- nyanpasu64 4y agoBeing allowed to mutate an integer (or object) through two different pointers on the same thread is perfectly safe and even useful (in the general case, for non-tree-shaped problems) on a CPU. Rust adds unpleasant syntax to achieve it through Cell, unpleasant syntax and undefined behavior footguns to do it through raw pointers, and guaranteed undefined behavior to do it through aliasing &mut, so I no longer treat Rust as a general-purpose programming language. And when teaching beginners, this would give the incorrect impression that it's somehow undefined behavior to access memory through multiple pointers on the same thread (rather than merely a tradeoff which increases code flexibility at the cost of local reasoning). And on a more personal level, I dislike the Rust community (and language, eg. for loops depend on trait resolution)'s heavy use of functional, generic, and higher-order function abstractions (rather than explicit imperative code amenable to sequential reasoning). I feel heavy use of generics is confusing in a language used to teach programming to students (and I think usefully learning mainstream programming revolves around algorithmic reasoning from the level of memory and bytes through structured programming, rather than pure functions and iterator combinators).
- zozbot234 4y ago> Being allowed to mutate an integer (or object) through two different pointers on the same thread is perfectly safe Not safe in the presence of variant records (i.e. enums in Rust), since one pointer might be used to derive a pointer to a field of one variant, and the object might concurrently be switched to a different variant. This is why Cell<> only relies on explicit get and set methods in the general case, where the entire object gets replaced. It's a well-known problem in temporal safety.
- nyanpasu64 4y agoI find that Rust prefers to prevent programmers from committing undefined behavior, rather than giving them the tools required to achieve tasks, when these requirements come in conflict (unsafe code is built to allow implementing general functionality with unchecked code, but is more difficult to write without UB than the equivalent operations in safe Java or unsafe C++, partly because mutating a & or aliasing a &mut is instant UB)
- deleted 4y ago[deleted]
- pkulak 4y agoYou have a very odd definition of a general purpose language. All the functional ones are out, because immutability doesn’t let you mutate through any pointer.
- nyanpasu64 4y agoIn my observations, immutability-focused functional languages are generally either non-Turing-complete and built as configuration/declarative languages, or find niche usage and do not replace JS/C++/Java/C# for mainstream programmers building a spreadsheet or word processor (and aren't built for low-level programmers to replace C++ for a browser engine or video game or non-allocating real-time audio engine).
- samgranieri 4y agoRust 101 would definitely be a weed out class for students trying to get a CS degree! Context: I took C++ back in college in 1999 and 2000. There were students who struggled with it then who dropped CS as a major. Later on I heard that Java took over as a 101 class. Now I think it’s Python.
- hdhrufjdi 4y agoAnd why would that be the case?
- zozbot234 4y agoHeap allocation doesn't really come up all that much in "101" programs, though. You have Strings of course, but that's about it. So I think teaching Rust could work, people just haven't gotten around to trying it. Most intros to Rust including the official book explicitly assume familiarity with some other programming language, and often fail to explain other things (at either the "low" or "high" level of semantics) that a 101 student wouldn't know.