Live data from Hacker News

Diving into Go by building a CLI application

eryb.space

61–70 of 124 posts

Re: Diving into Go by building a CLI application

#61

As much as I like Go I don't think it's ideal for CLI apps. IMO Python is the best at creating simple to complex CLI apps due to it being interpreted and simple. It's an overcharged bash.

The problem with Python is that it’s really hard to distribute a Python app to users. Nothing beats Go’s ability to compile into a self-contained binary.

Python is also slow and has poor support for parallelism.

Finally, “Python is simple” only really applies to its syntax. Overall, Go is a significantly simpler language than Python.

Re: Diving into Go by building a CLI application

#64

Earlier quoted context omitted.

This is probably the biggest thing I wish was easier to do in Rust. You can make "newtypes" by wrapping the value in a tuple (that gets compiled away), but it's a fair amount of boilerplate or macros to make the newtype useful. Once you have what you need, it's fine, but it's even less convenient for exploratory programming ;-)

> but it's a fair amount of boilerplate or macros to make the newtype useful. As mentioned in the docs, you can use the Deref facility to have the newtype implement everything that the original type does. Rust just gives you the choice of doing this vs. wrapping with a custom set of impls.

I'm not sure why I didn't recall that :-P Of course you are correct!

Re: Diving into Go by building a CLI application

#65
post #37

Earlier quoted context omitted.

> [Go] is forgiving enough that you can do exploratory programming in it. I agree with most of your post, but I’m not sure I would describe Go as “forgiving”. In fact, it’s well known for being strict. For example, exploratory programming would be significantly easier if the Go compiler could (optionally) ignore unused variables and unreachable code. I’ve also found exploratory programming in Go is hindered by needin…

I maintain a modified compiler ( https://github.com/kstenerud/go/blob/master/README.md#the-go... ) that can issue warnings instead for unused things. I use it as my daily driver for go development. main.go: package main import "fmt" func main() { var start int = 1 breakOuter: // for x := start; x Building: $ go build # example ./main.go:3:8: imported and not used: "fmt" ./main.go:8:5: label breakOuter defined and not…

That's cool! It is so annoying to just try to try something fast, and then the compiler stops you...

Re: Diving into Go by building a CLI application

#66
post #37
post #21

Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python. It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might b…

> [Go] is forgiving enough that you can do exploratory programming in it. I agree with most of your post, but I’m not sure I would describe Go as “forgiving”. In fact, it’s well known for being strict. For example, exploratory programming would be significantly easier if the Go compiler could (optionally) ignore unused variables and unreachable code. I’ve also found exploratory programming in Go is hindered by needin…

When programming in Java, I routinely run code that has compile errors in it.

As long as my execution path doesn't hit any code containing errors, I can run debug and even modify code in the debugger.

That's exploratory programming.

Re: Diving into Go by building a CLI application

#67
Whatever you do, do not use the flag library in a package that might ever, EVER be imported. Google did this in the horribly written glog port to go which until recently was used everywhere in Kubernetes. The only way to determine the value of the "v" flag they define globally for your entire executable is to call the V(n) function with n incrementing until it returns false.

pflag, which is used by cobra, is a much nicer library.

Re: Diving into Go by building a CLI application

#68
post #37

Earlier quoted context omitted.

> [Go] is forgiving enough that you can do exploratory programming in it. I agree with most of your post, but I’m not sure I would describe Go as “forgiving”. In fact, it’s well known for being strict. For example, exploratory programming would be significantly easier if the Go compiler could (optionally) ignore unused variables and unreachable code. I’ve also found exploratory programming in Go is hindered by needin…

When programming in Java, I routinely run code that has compile errors in it. As long as my execution path doesn't hit any code containing errors, I can run debug and even modify code in the debugger. That's exploratory programming.

That's not a general java attribute though, is it? I suspect that's because of the eclipse compiler.

Re: Diving into Go by building a CLI application

#69

My Opinion: The best cli lib I found: https://github.com/urfave/cli For deployment I recommend: https://github.com/goreleaser/goreleaser During development I recommend: https://github.com/golangci/golangci-lint and https://github.com/stretchr/testify

Agreed! urfave/cli is very handy.
Post reply on HN