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.