Skip to content
Mark edited this page Jul 21, 2014 · 7 revisions

Welcome to the underscore-go wiki!

The approach I took for porting Underscore.js to Go leaves much to be desired. Really, it was a first crack at

  • writing a larger amount of Go than I had previously
  • understanding the commonality among languages and libraries in renewed interest in functional programming.

For that second point, here's a stackexchange link that asks about the rise of functional programming in relation to hitting the wall described by Moore's Law.

And then I found a now defunct Iterable package within exp and some rather lengthy threads that conclude with write specific collection iteration code for your data with Go's range or other other operators/syntax and don't use a generic library that attempts to iterate over any collection.

With that said, the mere process of going through and porting Underscore.js was a great learning experience and by far the most amount of Go code I have written to date.

I am left with some observations:

  • it's better to write many small files instead of one large underscore.go file. I learned that prior to this effort, but bad habits snuck in and was easier to just go this route. I would say though, that keeping as one large file made the porting process easier as Underscore.js is one large file. I could have both open side-by-side in my editor and it kept me from missing parts of the API to port.

  • if I attempt a better port of this code, I would start by creating an Underscore interface with embedded interfaces for the underlying functionality. Maybe something like this:

   type T interface{}

   type Eachable interface {
        Each(collection T, func(value T,index T,collection T)
   } 
   type Mapable interface {
        Map(collection T, func(value T,index T,collection T) T
   } 
   type Underscorable interface {
         Eachable
         Mapable
   }

But, this approach just starts to look like the defunct exp.iterable interface again. The goal is to have a small, easy interface for you to implement your own Each and Map so as to make your collection Underscorable...but that feels like you'll just be re-implementing very similar Each / Map code for each type.

Clone this wiki locally