Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You 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.



I 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.


This is literally longer than the java version mentioned in the article, and that can be started just as simply with a single command.


I 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.


I 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


I 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.


The 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: