Live data from Hacker News

Go run

breadchris.com

11–20 of 173 posts

Re: Go run

#11
post #8

Earlier quoted context omitted.

Most of these examples don’t automatically fetch the dependencies. Having come from Python, Go’s tools are notably simple.

> Most of these examples don’t automatically fetch the dependencies. Quite frankly, I don't want to automatically fetch dependencies at the same time I am running the code . IMO those should be separate steps, and combining them together in one is not a good idea.

Why not ?

Re: Go run

#12
post #6

I don't think it's simple. Just `go run` would be far more simple. Right now I first have to figure out if its `go run .` or `go run cmd/main.go` or some other thing.

This one was voted down but there is a good point here. There is no way to figure out what binaries there are (maybe you could make `go list` show all the `package main`s?, not sure).

Beyond that there's no way to discover what build flags may be needed to give you the binary that the developer intended. Be it tags, ldflags, cgo support.

Re: Go run

#13
post #8

Earlier quoted context omitted.

Most of these examples don’t automatically fetch the dependencies. Having come from Python, Go’s tools are notably simple.

> Most of these examples don’t automatically fetch the dependencies. Quite frankly, I don't want to automatically fetch dependencies at the same time I am running the code . IMO those should be separate steps, and combining them together in one is not a good idea.

"go mod download && go run ."

What's the point in making `go run` error out when it already knows what dependencies to get and how to get them.

Re: Go run

#14
It's not really a Go thing but a build system thing. It's useful to have your build system know what is an "executable target" and how to run it.

Bazel does this for _all_ languages. I'm sure most other modern generic build systems do too.

AFAIK "go run" is trivial and for single-file scripts it's fine. But for more complex cases (like the NPM equivalent thing) I actually think it's a bit of a shame that it's even needed. I don't really know why we have per-ecosystem build systems (Maven, Go, cargo, whatever the hell you're supposed to do in Python these days, the nebula of web front-end tooling, etc etc).

Admittedly I do not really know the ins and outs of any of these systems in detail. I'm sure there are some good reasons why they exist under the hood.

Re: Go run

#15
combined with gosh - a golang shell interpreter it's pretty easy to create scripts that run on all the platforms and architectures, even future targets

      go run mvdan.cc/sh/v3/cmd/gosh@latest -c ' go run github.com/mikefarah/yq/v3@latest n foo.bar.hello world | go run github.com/cezarsa/glolcat@latest'

Re: Go run

#16

`go run main.go` breaks if your `main` module is divided into multiple files. Use `go run .` instead - it's shorter and it works with multiple files

great point, this is the one thing that I wish was more intuitive. You don't have to do this if main.go is the only file in the main package and all other code is referenced by a package.

Re: Go run

#17
post #8

Earlier quoted context omitted.

> Most of these examples don’t automatically fetch the dependencies. Quite frankly, I don't want to automatically fetch dependencies at the same time I am running the code . IMO those should be separate steps, and combining them together in one is not a good idea.

Why not ?

What happens when the dependency are updated and not compatible anymore ?

Re: Go run

#18

`go run main.go` breaks if your `main` module is divided into multiple files. Use `go run .` instead - it's shorter and it works with multiple files

This is a good tip! It also captures what has been frustrating about golang for me. The language feels a bit stuck between simple default cases and allowing complexity.

I feel like there are two relatively distinct populations of go developer: those who love how easy it is to start (true!) and those who are frustrated by the compromises the language has made to allow for more complex cases (required!). There's also a hidden third population of people who no longer sing the praises of golang as a simple, straightforward language but accept its compromises and write productive code with it. Those people, I think, write fewer viral blog posts.

Re: Go run

#19
post #17

Earlier quoted context omitted.

Why not ?

What happens when the dependency are updated and not compatible anymore ?

A Go module specifies the exact versions of its dependencies. These versions do not change unless the author explicitly updates them.

Re: Go run

#20
post #6

I don't think it's simple. Just `go run` would be far more simple. Right now I first have to figure out if its `go run .` or `go run cmd/main.go` or some other thing.

This is what Rust does with `cargo run`; I think Poetry for Python tries to do the same thing but I haven't used it in awhile.
Post reply on HN