loading...

re: Benefits of Rust VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Generics. This might not be something I use myself, but because of generics, it's possible for the standard library to add slightly higher function...
 

You seem to be undervaluing Rust's type system. Generics aside, one of the biggest complaints I see Rust users having when they try Go is how there's no middle-ground between using exact types and using interface{}.

Go has interfaces beyond interface{}, and you should use them exactly for that. They allow you to refer to things based on what functions they provide instead of what someone wrote in an inherits or similar.

package main

import "fmt"

type Fooer interface {
    foo()
}

type Bar struct {
}

func (b Bar) foo() {
    fmt.Println("foo")
}

func useFooer(f Fooer) {
    f.foo()
}

func main() {
    useFooer(Bar{})
}
 

Good point. That was a big phrasing mistake on my part. A better expression of what I was thinking would be "insufficient middle-ground".

I'm sure at least some of it is that we've been spoiled by Rust's excellent support for using sum types (enums containing data... A.K.A. compiler-verified tagged unions) to extend the compiler's ability to catch mistakes in variably-typed fields.

(The name "sum type" refers to the set of possible combinations. A tagged union is the sum of the possible combinations of its values. A struct is an example of a product type because its possible combinations are the set product of the possible combinations of its members.)

...but then the Rust community are overachievers that way. They've been working hard to design a viable system of Pi/Dependent types. (Types where, as in Ada, you can say that type Rating is "Type u8 where the value is in the range '1 through 5'" and get various kinds of compile-time goodness from it.)

Code of Conduct Report abuse