4 ms·
> Whenever I work in Rust, I find myself having a good time mucking around with the abstractions, but not really getting anything done toward the problem I’m tr
by pcwalton 11y ago
> Whenever I work in Rust, I find myself having a good time mucking around with the abstractions, but not really getting anything done toward the problem I’m trying to solve.
A couple of points:
1. Realistically, this is a programmer problem that no language can solve. If you don't need the abstractions for the code you're writing, don't use them! This is hardly something unique to Rust. A common complaint that experienced Go developers have about new Go programmers is that they overuse channels and goroutines--mechanisms of abstraction (of control flow, broadly construed). But nobody is arguing that Go would be a better language without channels and goroutines. The solution is to train new Go programmers to stop overusing channels and goroutines and to focus on the problem at hand. That's the same advice that I would give to anybody thinking about the perfect generic way to solve their problem in Rust instead of getting the job done.
2. Generics aren't exactly optional in Rust. Let's assume for the sake of argument that generics are a bad feature that languages should not have (something I completely disagree with, but in any case). Even supposing this were true, it's not like Rust would be a better language without them. Rather, the language could not exist, because it would be impossible to satisfy its core goal of zero-overhead, runtimeless memory safety. You couldn't have smart pointers without generics; you couldn't have iterators; you couldn't have Option; you couldn't have any functions that take and return pointers at all because lifetimes are a form of generics. Go is able to get away with not having generics because it leans heavily on having a runtime to support the built-in data structures and on garbage collection to make memory management decisions at runtime. Not so with Rust, which is designed to bake all that information into the compiler to avoid the overhead of a runtime and of garbage collection.
- Veedrac 11y ago> Realistically, this is a programmer problem that no language can solve. > The solution is to train new [language X] programmers There is high demand for software that blocks "procrastination" websites, because people struggle to focus when the whole internet's around. I know someone who's hidden their computer charger in order to stay focused. I've read a surprising number of blogs about aiding writer's block with minimalist text editors. I even know someone who needs to offload finances to another party lest they spent it too quickly themselves. You can tell people they just need training, but if the whole standard library screams "abstraction!", people are going to abstract. A language like Go is the minimalist text editor of the programming world. Sure, some people will scream they need their MS Word macros and floating panes (and it's even more true in CS), but these tools are an effective treatment of the symptom nonetheless. > Generics aren't exactly optional in Rust. Sure, but this doesn't change the trade-off. One should use Rust where the problems it solves best broadly match with the problems you're dealing with. And, IMHO, Rust is an exceptionally high complexity language for small projects.
- pcwalton 11y ago> You can tell people they just need training, but if the whole standard library screams "abstraction!", people are going to abstract. A language like Go is the minimalist text editor of the programming world. Should goroutines and channels be removed from Go then, because new programmers abuse them? I think the right way to look at programming language features is to look at the cost-benefit tradeoff. Generics, to me, are clearly on one side of the line. > And, IMHO, Rust is an exceptionally high complexity language for small projects. I don't think the complexity of Rust is that high, and "small projects" versus "large projects" is the wrong way to look at the value of abstraction anyway. Ruby on Rails is overwhelmingly used for small projects precisely because the abstraction/metaprogramming features of Ruby help small projects so much.
- Veedrac 11y ago> I think the right way to look at programming language features is to look at the cost-benefit tradeoff. Generics, to me, are clearly on one side of the line. The right way is to look at the cost-benefit tradeoff in context. There is no fixed line. Go has goroutines and channels because the designers judge that for the area they're aiming at, the benefit outweighs the cost. Same with generics - don't conflate them being good for you in your circumstance to them being good for everyone in every circumstance. We can argue to the ends of the earth where that line lies, but the fact is that some people in enjoy the simplicity that comes from Go not having them. (You could argue this is just another Blub paradox, but IMHO that would only make sense if the designers weren't proficient in languages including generics, like Java.)
- pcwalton 11y ago> Same with generics - don't conflate them being good for you in your circumstance to them being good for everyone in every circumstance. We can argue to the ends of the earth where that line lies, but the fact is that some people in enjoy the simplicity that comes from Go not having them. You can find some person who enjoys anything. But I think having basic OCaml-style generics has essentially zero downsides and so many upsides that it's essentially an open and shut judgment call for every statically typed language.
- chipsy 11y agoWhen it comes down to it, everyone seems to have their pet abstraction. Everyone except the old grumpy programmers. And YAGNI always applies, to some degree, because you can always build back up to some approximation of the "gotta have" abstraction from cruder primitives. So the benefit of the language design is to make it so that the abstractions you _do_ use play well with everyone's code instead of being a ball of duct-tape and easily broken conventions. I think that is missed when people go looking for a language with power tools. You can already do things too powerful to comprehend in C if you add enough macros and pointer indirection. But if you sit down trying to solve a problem using fewer language features instead of more, you usually come out ahead - because then you're forced back towards first principles about what the project needs and see the abstractions in the proper light. Powerful languages lead to an ecosystem of correspondingly powerful libraries, which drags you into the mire no matter what. While both Rust and Go are at a lifecycle stage where they're dogged by language window-shoppers, Go is actively resisting the people who didn't intend to make a purchase, leading to "Go not powerful" whinge blogs. We end up knowing less about Rust's productivity because most of the early adopters are going to be the kinds of people who seek innovative ways to break compilers - demanding customers, who don't give much back. That doesn't mean that Rust is actually unproductive, as it's quite likely that if you try to write C-style code with few ornaments, you will have little difficulty doing so, and the technology will mostly break in your favor. But it does mean that it'll take longer to work up momentum for a production-ready ecosystem, since the conversation will continue to revolve around "ooh, we've never done that before's" with borrow checking and metaprogramming. And when it's all over, it's likely that simpler ways to do these things will come to light - either in Rust or in another language.
- pcwalton 11y ago> And YAGNI always applies, to some degree, because you can always build back up to some approximation of the "gotta have" abstraction from cruder primitives. What I was saying with point (2) is that this is explicitly not true for Rust.
- chipsy 11y agoYes and no - it's a tradeoff abstraction. The borrow checker is a whole-language design directive, and its strength comes from giving up something in other areas - in this case, having to use generics everywhere. A language, as I said, is mostly made up of these intentional tradeoffs to try to find an appropriate balance. You can still express the abstractions of Rust through another language, though it may take writing another compiler on top to actually do so - they just won't hold the same utility, because the utility of this abstraction is mainly tied to the "zero-cost" implementation method, not to whether it has expressive powers.
- aidenn0 11y agoI would go so far as to say that any static language without some form of generics will eventually get them. Even in C, the preprocessor is often (ab)used for this use.
- MichaelGG 11y agoAnd C11 has _Generic for macros (though it's rather limited and really more just like overloading than generics).
- slantedview 11y ago> If you don't need the abstractions for the code you're writing, don't use them! So much this. Better to have the tools for when they're needed than to swing a hammer at everything regardless of whether it's a nail.