4 ms·
Being 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
by nyanpasu64 4y ago
Being 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).