clipperhouse/gen

Pull in typewriter package

clipperhouse opened this issue · 6 comments

See the typewriter branch for context.

On this branch, we split out a typewriter package which subsumes most of gen’s core functionality.

I think the name is good and the concept is clear, but it doesn’t need to be in a separate package, does it? I suggest we just bring all that functionality back into the main gen package.

The types and concept remain, they’ll just be gen.TypeWriter instead of typewriter.TypeWriter. gen will be an install and an import.

It’s one less thing to keep in sync, too.

Individual typewriters (“codecs”) remain their own packages and can live anywhere.

Thoughts?

Seems reasonable. I was thinking it seemed like there was an extra package somewhere in the new layout.

It appears this is a no-go – a gen package with a main() (that is, a package intended to be installed as a binary) cannot also be used as an import.

At least, not in my experiments. Is the above true?

You can import a package named main with a main() func, but you must name the import:

$GOPATH/src/a/main.go:

package main

import b "b" // just `import "b"` won't work here - try it

func main() {
    println("a")
    b.Hi()
}

$GOPATH/src/b/main.go:

package main

func main() {
    println("b")
}

func Hi() {
    println("hi")
}

$ go run $GOPATH/src/a/main.go
a
hi

You could also do something like go get github.com/clipperhouse/gen/gen for the binary w/ main--you'd have to put it in a subfolder though. This is also necessary for the gopkg.in router--had to do it for https://github.com/wfreeman/pj

@mjibson @wfreeman Thanks, I suspected the workarounds would look like that. I think both are a bit error-prone for clients of the package, though the subfolder offends me slightly less.

I think a subfolder for the binary is def a no-go from a design perspective. A simpler URL for installers wins, since they are the majority of users.

So then the library is the thing. Do we ask people to import clipperhouse/typewriter or clipperhouse/gen/gen?

The typewriter package is still separate, but part of the main gen repo. Good enough for now.