4 ms·
I think this misses the problem. Should you write your own data-structures? Not unless absolutely necessary. But mostly everyone knows that. So why are people
by ianbertolacci 10y ago
I think this misses the problem.
Should you write your own data-structures?
Not unless absolutely necessary.
But mostly everyone knows that.
So why are people complaining about data-structures?
For me, writing the data-structures is the canary in the mine.
It's the next step from hello world when trying to pick up a new language.
Most importantly, trying to write a few simple data-structures hints at the difficulty that will be encountered writing a 'real' program.
For people like me, if writing trivial data-structures in Rust is a great challenge, it shows that writing other, less trivial things in Rust will be much more challenging than might be preferred.
Hand waving the comment "writing data-structures in Rust is hard" with "well you shouldn't be doing that anyway" misses, I think, the point that Rust (while very neat) is generally a difficult language to pick-up.
[Edit]
Again, the issue isn't data-structures or about them.
The issue is: Can I write something in scratch in this language 1) at all and 2) with some amount of daily progress.
Writing data-structures is a test case of my ability to thing and program in the context of Rust. It serves to answer the question: Can I write a program that implements a well defined, well understood construct so that I may learn the building blocks of rust?
This leads up to an application, the behavior and design of which may not be extremely well defined in the context of Rust and requires more thinking when working out the data-structure in rust.
If the answer to "can I write a data-structure in Rust" is "Ya totally got this makes sense" then writing an application will be relatively easy.
However if the answer is "Wow I did it but there were a lot of pain points and I still have no idea if I've done it in the right or canonical way" then writing an application is going to be very difficult.
- ecnahc515 10y ago> For people like me, if writing trivial data-structures in Rust is a great challenge, it shows that writing other, less trivial things in Rust will be much more challenging than might be preferred. And this is the real issue, because your assumption doesn't really have any real basis. I don't mean to belittle your point, I can completely understand where you're coming from, but assuming that because writing data structures in Rust is hard, that "real" problems will be difficult as well, is wrong. There's nothing to back this up. Data structures are a very specific domain, often very far away from what you'll be doing in the average "real" program. There's a reason common data structures are often implemented and included in the stdlib of most languages. What I find is that it's more common that writing data structures in other languages is easy, because most of the time, people aren't implementing them correctly, or safely. 99% of the linked lists I see in C++ fail to even implement the copy constructor, meaning they're going to be broken the moment you do a copy of the list.
- ianbertolacci 10y agoAgain, the issue isn't data-structures or about them. The issue is: Can I write something in scratch in this language 1) at all and 2) with some amount of daily progress. Writing data-structures is a test case of my ability to thing and program in the context of Rust. It serves to answer the question: Can I write a program that implements a well defined, well understood construct so that I may learn the building blocks of rust? This leads up to an application, the behavior and design of which may not be extremely well defined in the context of Rust and requires more thinking when working out the data-structure in rust. If the answer to "can I write a data-structure in Rust" is "Ya totally got this makes sense" then writing an application will be relatively easy. However if the answer is "Wow I did it but there were a lot of pain points and I still have no idea if I've done it in the right or canonical way" then writing an application is going to be very difficult.
- dbaupp 10y ago> If the answer to "can I write a data-structure in Rust" is "Ya totally got this makes sense" then writing an application will be relatively easy. > However if the answer is "Wow I did it but there were a lot of pain points and I still have no idea if I've done it in the right or canonical way" then writing an application is going to be very difficult. I feel like one of implicit points of the OP is that this isn't obviously true: writing a data structure is often a very different type of programming to writing a normal application. Most of the code I write isn't like a data structure, and is definitely not like a really good data structure: I can just glue together such code that others have written (or even I personally wrote once, a while ago) without having to worry about the details that it packages up/manages for me. (This is true in both Rust and C++, the latter of which I use day-to-day.)
- ehsanu1 10y agoThe issue is: Can I write something in scratch in this language 1) at all and 2) with some amount of daily progress. Writing data-structures is a test case of my ability to thing and program in the context of Rust. The point is that it's not the best test case. A better test case would be writing the programs you generally write. It'll still be hard to be honest, but really not quite as hard. I have enough familiarity with Rust to write application code myself, but I'd probably still struggle a lot with writing a data structure if I tried.
- kibwen 10y ago> For people like me, if writing trivial data-structures in Rust is a great challenge, it shows that writing other, less trivial things in Rust will be much more challenging than might be preferred. I understand the source of the sentiment, but also disagree with it. I've been writing Rust code for years and have never had occasion to write my own custom data structure, and (discounting FFI) I've reached for the `unsafe` keyword like twice (which I think I ended up removing anyway, because I was trying to be too clever). But then again, my background is in higher-level languages (Java, Python) where writing data structures isn't your usual beginner task. I sympathize with C programmers to whom a linked list is the go-to toy learning program, but the urge to resort to unsafe shenanigans to implement self-referential data structures doesn't reflect the typical experience of using the language. And for those who still wish to persist, may I recommend the book "Learning Rust With Entirely Too Many Linked Lists": http://cglab.ca/~abeinges/blah/too-many-lists/book/ http://cglab.ca/~abeinges/blah/too-many-lists/book/
- ianbertolacci 10y agoIve made a comment below, that I'm sure I'll make again (since I want to make it here). So I've added to my original comment.
- adrianN 10y agoCreating complex object graphs is also not trivial in Haskell, yet that language seems to do fine with real-world problems.
- sjolsen 10y agoHaskell is also garbage-collected, and lazily evaluated to boot. It's not really an apples-to-apples comparison.
- adrianN 10y agoOf course not. Haskell is a purely functional language and Rust is an imperative systems language. It can hardly be more Apples to Oranges.
- jstimpfle 10y agoIs it doing fine? There's lots of "cool" stuff, but in my perception it's still a long shot to "fine with real-world problems". What's a complex real-world program written in Haskell? It seems to be good for trees (compilers like GHC, although it is kind of slow). Is there a non-toy graphics or graph-ical application that is both performant and written in Haskell? Not denying that it's possible to write C-style in it, of course... only it's not fun.
- pka 10y agoAt my previous company we used Haskell for a very complex, edge-case ridden, algorithm heavy path finding and pricing backend. For other uses, [0]. [0] https://wiki.haskell.org/Haskell_in_industry https://wiki.haskell.org/Haskell_in_industry
- jstimpfle 10y agoOf course it would be nice to have examples that we can actually look at. Also that webpage is known to mostly not point to easy to find information.
- sjolsen 10y ago>if writing trivial data-structures in Rust is a great challenge, it shows that writing other, less trivial things in Rust will be much more challenging than might be preferred. Data structures are exactly the abstractions built on top of raw memory. Rust is not really geared toward working with raw memory; it's geared toward working with abstractions that hide the raw memory (i.e., data structures). That's why writing data structures in Rust is hard, and it's also why that fact doesn't imply that "other things" (i.e., code that is not part of a data structure implementation) are hard. In other words, the fundamental flaw with the assumption that there is a relationship between the difficulty of implementing data structures in Rust and the difficulty of writing applications in Rust is that the two involve very different programming models, and Rust has much more ergonomic support for one than the other.
- Manishearth 10y ago> For me, writing the data-structures is the canary in the mine. It's the next step from hello world when trying to pick up a new language. Most importantly, trying to write a few simple data-structures hints at the difficulty that will be encountered writing a 'real' program. You're missing the point of the post here, and drawing the exact correlation that the post is warning against. Just because something is easy in C++ does not mean that it must be easy in other languages. In fact, writing good data structures in C++ is hard too (try writing an actually safe std::vector clone, it gets tricky), just that C++ will happily let you have an unsafe API; Rust will complain. This is the old "grade the intelligence of a fish by its ability to climb a tree" problem. There is no intrinsic reason why the difficulty of writing datastructures should correlate with the difficulty of writing actual code. It is an easy task in C/C++, and thus it is often an early part of the learning experience.
- andrewflnr 10y agoIf it's really not about data structures, then pick a different canary. A more accurate one. That's basically all we're asking.