
Go Tutorial: Object Orientation and Go's Special Data Types - jemeshsu
http://www.drdobbs.com/open-source/go-tutorial-object-orientation-and-gos-s/240005402
======
jcurbo
Just a note, this is adapted from the author's book Programming in Go.

[http://www.amazon.com/Programming-Go-Creating-
Applications-D...](http://www.amazon.com/Programming-Go-Creating-Applications-
Developers/dp/0321774639/)

This article is second in a series. Discussion of the previous article on HN:
<http://news.ycombinator.com/item?id=4351992>

------
nickpresta
I know you can use the empty interface but it hands off type checking to the
runtime, which neglects the type system for a bit of generality and defeats
the safety of having static typing in the first place.

~~~
georgemcbay
You can also import the unsafe package and mess with pointers directly.
Neither of these are problems.

Go strikes a nearly perfect balance between saving the programmer from
accidentally shooting his foot off and getting the hell out of the way when
the programmer is absolutely sure that the proper solution involves bending
the rules a bit.

~~~
nickpresta
I never said these things were problems. I only brought them up because the
article doesn't even mention them, or type safety at all.

It is one thing to have code for an example or for an introductory paragraph,
but it should be mentioned that `interface{}` is not totally "safe" .

------
e12e
Thanks for this - I've been through the golang wiki tutorial, but this (ab)use
of an empty interface for storing "any"-type in a collection was a great idiom
to be aware of.

~~~
evmar
Another way to look at it is that an interface wraps a type by adding a
pointer to an extra data structure, which identifies the type and functions on
the type that implement the interface. Since interface{} has no functions, all
that it carries is the type; it's concretely represented as a pair of the
value and its type. Which is more or less how any language implements an "any"
type.

(Disclaimer: it still feels awkward to me, but I found understanding the
implementation of it helped me understand the why better. See also
<http://research.swtch.com/interfaces> .)

------
biomechanica
I actually quite like this language. I'm learning C right now and love it, but
I gotta say, Go is really starting to catch my eye.

