The Go standard io library has a Reader interface:
type Reader interface {
Read(p []byte) (n int, err error)
}
a Writer interface: type Writer interface {
Write(p []byte) (n int, err error)
}
and a ReadWriter interface which uses type embedding to combine both: type ReadWriter interface {
Reader
Writer
}
Idiomatic Go will break interfaces up into pretty discrete bits of functionality and use type embedding to build up more complex interfaces. The article does show this a little bit with its seekable interface but fails in some other areas and I kind of wish it just used the real io package interfaces or else examples of something not covered better by the actual Go standard library.Anyway I think we agree on the general issue, but actually I suspect go's approach _does_ solve some bad design issues that crop up in common OO, namely the fragile base class one.
I just don't think it impacts the misspecification one.
It wouldn't be surprising to have a ReadOnlyFile type and a ReadWriteFile type. This can easily be justified because an individual file object doesn't need to change its read/write property after it has been created. But conceptually, files can be written to, just not always.
Another example makes that clearer. Adults can do things that minors can't. So, for instance, a signContract() method would have to go on the Adult type not on the Person type. But people grow older, so at any point in time some objects conceputally change their type from Minor to Adult.
Technically this is not a difficult problem to solve. But it shows the disconnect between our natural language concepts and the ever more type centered way of modelling we use in modern software design.
FP does not imply static types. See Lisp and its dialects. Don't confuse the Haskell way of doing things with FP in general.
More imporantly though, what FP does in both its dynamically and statically typed incarnations is to prefer (and sometimes enforce) immutability.
Immutable objects support a much more type centered view of the world. Theoretically, you could have something like a VehicleAtFullSpeed type (dynamic or static) because the speed attribute of an individual object never changes.
For example, given the article's GO code:
my first thought was: wait, not all files are writable, that interface is ill specified.I do think subtyping and subclassing should be different things, but it's not a panacea against bad specifications.