3 ms·
I am sure you know enough about Rust to know that writing a linked list in Rust is not a “novice exercise”. It is also not something you require to use the lang
by LeFantome 3y ago
I am sure you know enough about Rust to know that writing a linked list in Rust is not a “novice exercise”. It is also not something you require to use the language.
This is like a C# dev trolling a C developer by say “first novice exercise”, HTML encode a UTF8 string. I mean, it is a single line of code in C# so how hard could it be in C?
Or, it is like a C dev telling a Java programmer that their “first novice exercise” should be to write a fixed binary layout to a device driver or even just to call directly into an OS system call. Both are trivial in C after all. How about using a hash table for something though? Reasonably big job in C but new HashMap in Java.
Rust is designed to prevent exactly the kind of thing you do to create a linked list and it is designed to make it difficult for a good reason. It is a cherry picked example meant to sound smart but, in reality, it is an eye-rollingly dumb thing to say.
In DOS, I can write a program to dynamically overwrite and extend the behaviour of the operating system in RAM. In Linux, I cannot easily do that. I guess that means DOS is more advanced? To me, this sounds like the argument you are making about Rust.
I do it care which language people like. There are pros and cons of each and legit arguments on use one over the other. Why not use one of the valid arguments instead of dumb gotcha comments that only tell us the languages are different and not which one is better.
- appleskeptic 3y ago>This is like a C# dev trolling a C developer by say “first novice exercise”, HTML encode a UTF8 string. I mean, it is a single line of code in C# so how hard could it be in C? It’s not like that at all. The difference you’re identifying is that C# has it in the standard library while C does not. But it’s a conceptually intricate problem and implementing it from scratch in both C and C# would actually be somewhat similar, but C# obviously has some convenience features that would make the code tighter. Linked lists are very simple and GP’s complaint is that Rust makes it very difficult to implement them.
- LeFantome 3y agoThe difference is that both C and C# let you use pointers and make it your responsibility to use them correctly. C# provides the facilities, both in the naked language and in the standard library to not need pointers whereas you need to use pointers to do even trivial tasks and so the standard library makes extensive use of them. Pointers are a core language feature of C so obviously it is trivial to make use of them ( though not at all trivial to use them safely ). Rust’s core principle is that unsafe memory access should be prevented at the language level. Unsurprisingly, a data structure completely reliant on potentially unsafe use of memory will be difficult to implement. Both C# and Rust include features in their standard libraries so that implementing your own linked lists is unnecessary precisely because you are not supposed to. This is “non-idiomatic” as they say. C does not include linked lists in the standard library because this is exactly the kind of data structure you are meant to create when needed as the language makes it completely trivial to implement them. In C, a linked list is completely idiomatic and many, many C projects use them. If you write an OS in C, you will almost certainly create a linked list structure. Linux did. If you write an OS in Rust, you do not need to do that.
- Kwpolska 3y agoWriting a linked list is a novice exercise in most programming languages. It’s also a novice exercise given in first year of CS at universities. It might not be the most efficient data structure, but it’s a really trivial one.
- deleted 3y ago[deleted]
- pavlov 3y agoIn assembly it’s really easy to write self-modifying code. It used to be the norm in fact. But today’s high-level programming languages generally make it impossible, and most operating systems also prevent mutating code in memory (no-execute page protection, etc.) Yet there are still use cases like JIT compilers. The linked list is the data structure equivalent of self-modifying code. It’s easy for a novice to understand, but there’s no great reason for anyone to actually do it today outside of a specialized library.
- bsaul 3y agoYour point would be valid if rust had code examples that was actually simpler to write in rust than in other recent languages. My understanding is that rust provides safety guarantees that no other language matches, but at the cost of pretty much everything else. In that regard, the "linked list" example is a pretty good (although maybe over-pathological) example of the hard parts of the language.
- spease 3y ago> My understanding is that rust provides safety guarantees that no other language matches, but at the cost of pretty much everything else. In that regard, the "linked list" example is a pretty good (although maybe over-pathological) example of the hard parts of the language. The build system is easier to use than any other language I know of. Integrating third-party libraries into a project is night-and-day between C++ and Rust, and the Rust ecosystem benefits tremendously from it. Energy efficiency is also extremely good, as is performance. https://aws.amazon.com/blogs/opensource/sustainability-with-rust/ https://aws.amazon.com/blogs/opensource/sustainability-with-... And as far as code confidence, I don't know of any other language that compares, either. You can dodge memory safety errors in Java or C# thanks to the GC, but exceptions keep flow control from being as explicit as Rust since your function can be silently pre-empted. I see Java or C# as paying a small (and in many cases fully justified) cost to smooth things over so there's less friction to development. Go additionally adopts an extreme focus on keeping the language small and simple so it's easy to learn. Rust declines to pay that runtime cost, but requires you to explicitly address those friction points, while C++ lets you hang yourself. Rust also has a carefully curated standard library and idiomatic patterns, while C++ has addressed the problem of lessons learned by continually adding to the standard library without keeping different features compatible or consistent with each other. So, yes, Rust will have a steeper learning curve, but it levels off long before C++'s does. In addition, the compiler messages are far more helpful in Rust, and the default tooling is far better than C++.
- jandrewrogers 3y agoThe relative learning curve between Rust and C++ is strongly dependent on the type of software you are building. I use both. They each have domains where the other is not particularly close in being equally effective (or safe!) as a programming language. One area where C++ still runs rings around Rust, for example, is modern database kernels. Rust’s safety features largely don’t apply, so no benefit, and Rust has large expressivity gaps that make it more complex and less safe to implement things that are straightforward in C++. Also, the relatively weak generics and metaprogramming features of Rust causes this type of code to balloon in size and invites bugs. But for other types of code, this barely matters at all because you don’t have many uses for these C++ features. Horses for courses.
- jandrewrogers 3y agoI think a few things can be true at the same time. A (doubly-)linked list is an elementary data structure. It is reasonable to expect implementation of such data structures to require no special magic, since they are one of the first data structures many people learn. There is minimal use for these data structures in modern programming so the exercise is a bit academic. Every doubly linked list I have written in vaguely recent memory, and there haven’t been many, used indirect addressing (like indexes) and not pointers. While I don’t think it matters that much in practice for many types of systems software, I think it is fair to recognize that this lack of basic expressivity is occasionally troublesome and an unexpected gap in the context of classical computer science for someone learning Rust.