News for hackers. Stuff that matters.
Re:Go and Rust – objects without class by riffraff on Saturday May 04, 2013 @02:53AM (#5654310)
I am not sure the issue of “I don’t make sense in this derived class” is solved by decoupling types and inheritance.

For example, given the article's GO code:

    type file interface {
	Read(b Buffer) bool
	Write(b Buffer) bool
	Close()
    }
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.

Re:Go and Rust – objects without class by georgemcbay on Saturday May 04, 2013 @03:21AM (#5654359)
That interface isn't great, but that interface isn't coming from Go. I realize you aren't claiming it is, and you're absolutely right that Go's interfaces don't automatically "solve" issues of bad design. Programmers are free to come up with bad interface designs in Go just as easily as they came up with bad class designs in Java or C++. This is just to avoid confusion for people who aren't generally familiar with Go but read this article.

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.
Re:Go and Rust – objects without class by riffraff on Saturday May 04, 2013 @10:33AM (#5655062)
Well, sure, but Reader and Writer are interfaces existing in java too :)

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.

Re:Go and Rust – objects without class by fauigerzigerk on Saturday May 04, 2013 @06:16AM (#5654622)
I think this points to a seperate issue as well: Often times we have a choice to express the same thing through types or through state. As the influence of functional languages grows, we tend to choose types more often.

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.

Re:Go and Rust – objects without class by mseepgood on Saturday May 04, 2013 @07:18AM (#5654700)
> As the influence of functional languages grows, we tend to choose types more often.

FP does not imply static types. See Lisp and its dialects. Don't confuse the Haskell way of doing things with FP in general.

Re:Go and Rust – objects without class by fauigerzigerk on Saturday May 04, 2013 @07:44AM (#5654751)
My point isn't a formal one but rather an observation about software design trends.

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.

Re:Go and Rust – objects without class by riffraff on Saturday May 04, 2013 @10:25AM (#5655053)
yeah, I really liked the idea of using typestate to model exactly this in rust, but it was apparently a failed experiment :(