6 ms·
Can you tell us about how you use Go in the small? I like Go, but it doesn't strike me as particularly nimble for scripty use cases like this - error handling i
by tmiku 2y ago
Can you tell us about how you use Go in the small? I like Go, but it doesn't strike me as particularly nimble for scripty use cases like this - error handling is part of it, but I know that's fixable with the Must() pattern.
- mongol 2y agoI just write a small Go program. I agree that error handling is a weak point, but the tooling is well integrated. The article mentions that Java does not know about Maven. The go tool is much more versatile in that sense. Also, go run is almost like running a script.
- ricardobeat 2y agoYou can quickly whip up a single-file go program anywhere, without any boilerplate or setup: package main import "fmt" func main () { fmt.Println("hi") } // go run file.go You can write this in any text editor, but using one with LSP support means that `import` statement is added automatically, and with CoPilot or another assistant, the `main` function writes itself as well as any `if err ...` statements. Go is extremely well suited to code generation due to how predictable it is. Adding dependencies with `go mod` is uneventful. It will never be as 'scripty' as JS or Ruby, but the readability, safety and performance are totally worth it.
- Capricorn2481 2y agoI don't really see how this is different from `dotnet run`, `python main.py`, or `lua main.lua`. Like the commenter, I don't find Go very nimble. Is limited features (Go) gonna be better for AI generation then breadth of examples? (C#). I'm not sure.
- yxhuvud 2y agoI see 3 or four lines of boilerplate in your example, depending on if the closing brace is counted or not. Compare with the following equivalent program in ruby or crystal (it is valid in both): puts "hi" And the crystal version is just as typesafe and performant as the go version. I also find it more readable, but that is a very individual metric.
- mongol 2y agoI don't think minimal examples are so useful. I reach for Go when bash is insufficient. That means there is a minimal starting size that is large enough that package and imports boilerplate are insignificant, all things considered
- ricardobeat 2y agoI love Crystal and have been a sponsor for a long time, but it's not comparable yet. Compiling is much slower, you have to manually add dependencies to shards.yml, cross-compilation is not as simple. And when it comes to scripts and tools, popularity / stability is a main concern.
- gf000 2y agoThis is literally longer than the java version mentioned in the article, and that can be started just as simply with a single command.
- ricardobeat 2y agoThe question I responded to was 'how you use Go in the small', not a comparison to the post. As I mentioned, yes, it's verbose, but simple and worth the effort and peace of mind. My primary language is JS, I've written a fair share of shell and Ruby but would still choose go a lot of the time, just because it doesn't pull in any extra complexity.