3 ms·
>Rob Pike wrote a bit about it in "less is exponentially more". Which is wrong. >Go focuses on composition Clearly false.
by vmchale 8y ago
>Rob Pike wrote a bit about it in "less is exponentially more".
Which is wrong.
>Go focuses on composition
Clearly false.
- majewsky 8y agoHow is this false? I agree with this assertion after having used Go extensively for some time. Where Go really shines is when the stdlib offers a nice abstraction (io.Reader, io.Writer, http.Handler) and you can compose your programs from building blocks that use these abstractions. For example, from the http.Handler interface follows directly a middleware interface: type Middleware interface { Wrap(http.Handler) http.Handler } without requiring any generic types. For comparison, the same thing in Rust would rely on type polymorphism: //assuming that Handler is a trait trait Middleware<T: Handler> { type Result: Handler; fn Wrap(handler: T) -> Result; } //NOTE: Not using impl-trait here to make it clear that //two type variables are involved (one type parameter //and one associated type). You could mimic the Go behavior if you box all your traits, which Rust does not like to do because it's not zero-cost: trait Middleware { fn Wrap(handler: Box<Handler>) -> Box<Handler>; }