11 comments

[ 2.2 ms ] story [ 30.2 ms ] thread
(comment deleted)
Hmm, so they're just safe pointers with bound checking. Cool, you can actually type safely slice apart an array. They handled that much better than C.

Isn't nearly any implementation of arrays in other languages? E.g. ArrayList in Java or vector in Haskell. If a language uses garbage collection, chances are that views/slices are also supported.

Yes, the slices concept is not new, many languages have them.

It baffles me that so many Go newbies think of them as a Go specific novelty.

I added sliced array projections to Scala back in 2006. Have no idea if they are still there after Martin's collection API overhaul given the focus on immutable data structures and functional behavior.
slices are not arrays in Go. Slices are built on top of arrays. You can still access Go arrays.
also STL vector in C++?
AIUI, multiple Go slices can access the same underlying array, whereas each C++ vector has its own storage. The C++ equivalent to a Go slice would be a pair of iterators. C++'s system is more flexible, though; I think you can only obtain Go slices over arrays, but C++ iterators are used to represent views over all collection types (linked lists, maps, etc).
> C++'s system is more flexible, though

Well you are comparing templates to non-templates...

I think the difference between go slices and java ArrayLists is that go allows you direct access to the underlying array.
I often see this argument coming about. Someone talks about how great language E is because it has feature X. Then someone else comes along and says languages A, B, C, and D also have X. As though that somehow diminishes the value of having feature X in E.

Go doesn't try to be full of fancy new ideas. Most of the ideas come from other languages. Go tries to be the best collection of known ideas that it can be, examining benefits and tradeoffs each step of the way and giving sound reasoning for each decision.

Recently I found myself slightly annoyed that they use hg instead of git. Sure enough, I found an explanation in the FAQ. http://golang.org/doc/faq

Understanding slices :

  - slice.c, http://golang.org/src/pkg/runtime/slice.c
  - Dynamic arrays, https://en.wikipedia.org/wiki/Dynamic_array