4 ms·
But why (1)? If a `fishTank` is a `container[fish]` what is the benefit of requiring it to be cast again?
by hiptobecubic 4y ago
But why (1)? If a `fishTank` is a `container[fish]` what is the benefit of requiring it to be cast again?
- morelisp 4y agoWhen people say Go is not an OO language, this is what they mean. Concrete type declarations define storage, not is-a hierarchies. A fishTank is not a container[fish], any more or less than it is any other `{ string, []fish }`.
- sidlls 4y agoAnd yet OO-isms are replete throughout implementations in go. `interface{}` all the things is another of the worst things about go. It practically begs for engineers to engage in all the worst practices of OO-ism and unit test zealotry.
- throwaway894345 4y agointerface{} isn’t pervasive in Go, it doesn’t tend to get abused often in practice, it has nothing to do with OO at all, and it doesn’t lead to any particular ideology about unit testing. It seems like you are mistaken on all counts.
- masklinn 4y ago> But why (1)? If a `fishTank` is a `container[fish]` But a `fishTank` is not a `container[fish]`. In common parlance type T Thing is newtyping. T has the same implementation as the underlying type, and Go allows conversions back and forth, but they are otherwise unrelated, and the new type does not share the interface (method set) of the original. It is, in a way, a shorthand for type T struct { _0 Thing }
- hiptobecubic 4y agoOh I misunderstood `type T Thing` to be an alias and not a haskell-style newtype. $ ghci GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help Prelude> class HasField a where { field1 :: a -> Int } Prelude> data Foo = Foo Prelude> instance HasField Foo where { field1 f = 2 } Prelude> field1 Foo 2 Prelude> newtype Bar = Bar Foo Prelude> :t Bar Bar :: Foo -> Bar Prelude> field1 (Bar Foo) <interactive>:7:1: error: • No instance for (HasField Bar) arising from a use of ‘field1’ • In the expression: field1 (Bar Foo) In an equation for ‘it’: it = field1 (Bar Foo) Prelude> type Baz = Foo Prelude> field1 (Foo :: Baz) 2
- morelisp 4y agoThere's an unfortunately-close syntax that does define type aliases in Go, type T = Thing