go run -e -c 'package main; func main() { println("hello"); }'
This mistake happens very frequently. Presumably it's hallucinating -e and -c because various other tools accept those as flags to indicate the input is on the commandline.
I asked Claude's opinion on this:
--- snip ---
Before you run that command, I'm going to file a bug against go to make your life easier. Which example feels more natural to you for running short go programs: 1) go run -c 'package main; func main()
{println("hello");}' or 2) echo 'package main; func main() {println("hello");}' | go run -
------- snip ----
It replied:
------- snip ----
Option 1 (go run -c '...') is what I instinctively reach for — it matches python -c, bash -c, perl -e. Less pipeline plumbing for quick checks.
------- snip ----
Why not obey the principle of least surprise here, and do what feels natural to this (non-sentient) user?
- Dan
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/0d4be2ed-14a6-4a44-b834-704caede5ef0n%40googlegroups.com.
Surely these AI tools are powerful enough that you can tell them how to run the command rather than changing the language's tools to cover their inadequacies.
# Program coming from stdin
echo 'echo "Hello, World!"' | sh
echo 'echo "Hello, World!"' | pwsh
echo 'print("Hello, World!")' | python3
echo 'print "Hello, World!\n"' | perl
echo 'puts "Hello, World!"' | ruby
echo '<?php echo "Hello, World!\n"; ?>' | php
echo 'console.log("Hello, World!")' | node
echo 'print("Hello, World!")' | lua
#not supported in go
# Program coming from commandline option
sh -c 'echo "Hello, World!"'
pwsh -Command 'echo "Hello, World!"'
python3 -c 'print("Hello, World!")'
perl -e 'print "Hello, World!\n"'
ruby -e 'puts "Hello, World!"'
php -r 'echo "Hello, World!\n";'
node -e 'console.log("Hello, World!")'
lua -e 'print("Hello, World!")'
awk 'BEGIN{print "Hello, World!"}'
echo 'package main; func main() {println("Hello, world!")}' > hello.go; go run hello.go; rm hello.go
It does seem worth supporting, at least to me, as an idiom for quickly printing out constants or running really tiny programs.
- Dan
Here's a little rosetta stone:
...#not supported in go
Usage would be something like
echo 'println("hello world"); fmt.Println("goodbye")' | GORUN
echo 'println(math.Pi)' | GORUN
Or using actual newlines
echo '--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/bbbd40a1-cc54-47a9-83c7-1ebfbcd78c67n%40googlegroups.com.
I've observed people never bothering to do go build.I wonder who these people are and why they would be using GO in the first place? Send to be a very complicated deployment to install GO on every deployment
One version for C (or C++) is a thing of beauty. It's a bit
inconvenient since you need to put the string in the middle of the
command. And you need to name an executable file. This assumes bash.
gcc -o /tmp/run -x c - <<< '#include <stdio.h>
int main() { printf("hello, world\n"); }' && /tmp/run
This proposal won't happen, and for good reasons:
1. The problem is backwards - LLMs hallucinating non-existent Go flags is a training data issue, not a Go toolchain issue. Fixing Go to match LLM hallucinations
sets a terrible precedent.
2. The cost/benefit is poor - Adding inline code execution to go run is non-trivial (argument parsing, stdin handling, module context, error reporting) for marginal
benefit. The pipe workaround works fine: echo 'package main; func main() { println("hi") }' | go run .
3. Flag conflict - go test -c already means "compile but don't run." Overloading -c to mean "inline code" in go run violates consistency.
4. Wrong tool for the job - If you want a Go REPL or quick evaluation, use dedicated tools like gomacro, gore, or yaegi. The go command is a build tool, not an
interpreter.
5. The Pike objection - The reference to "Mr. Pike's objection" likely refers to Rob Pike's general philosophy against adding complexity for convenience when
simpler alternatives exist.
The real fix: Update LLM training to stop hallucinating go run -c. This is a model correction issue, not a language tooling gap.