Go Away Python

(lorentz.app)

78 points | by baalimago 3 hours ago

12 comments

  • hamishwhc 57 minutes ago
    The author’s point about “not caring about pip vs poetry vs uv” is missing that uv directly supports this use case, including PyPI dependencies, and all you need is uv and your preferred Python version installed: https://docs.astral.sh/uv/guides/scripts/#using-a-shebang-to...
    • meander_water 29 minutes ago
      Actually you can go one better:

        #!/usr/bin/env -S uv run --python 3.14 --script
      
      Then you don't even need python installed. uv will install the version of python you specified and run the command.
    • benrutter 50 minutes ago
      I thought that too, but I think the tricky bit is if you're a non-python user, this isn't yet obvious.

      If you've never used Clojure and start a Clojure project, you will almost definitely find advice telling you to use Leiningen.

      For Python, if you search online you might find someone saying to use uv, but also potentially venv, poetry or hatch. I definitely think uv is taking over, but its not yet ubiquitous.

      Ironically, I actually had a similar thing installing Go the other day. I'd never used Go before, and installed it using apt only to find that version was too old and I'd done it wrong.

      Although in that case, it was a much quicker resolution than I think anyone fighting with virtual environments would have.

      • houzi 37 minutes ago
        Do you think a non-python user would piece it together if the shebang line reveals what tool to use?
  • PaulRobinson 43 minutes ago
    Mad genius stuff, this.

    However... scripting requires (in my experience), a different ergonomic to shippable software. I can't quite put my finger on it, but bash feels very scriptable, go feels very shippable, python is somewhere in the middle, ruby is closer to bash, rust is up near go on the shippable end.

    Good scripting is a mixture of OS-level constructs available to me in the syntax I'm in (bash obviously is just using OS commands with syntactic sugar to create conditional, loops and variables), and the kinds of problems where I don't feel I need a whole lot of tooling: LSPs, test coverage, whatever. It's languages that encourage quick, dirty, throwaway code that allows me to get that one-off job done the guy in sales needs on a Thursday so we can close the month out.

    Go doesn't feel like that. If I'm building something in Go I want to bring tests along for the ride, I want to build a proper build pipeline somewhere, I want a release process.

    I don't think I've thought about language ergonomics in this sense quite like this before, I'm curious what others think.

    • dingdingdang 33 minutes ago
      Talking about Python "somewhere in the middle" - I had a demo of a simple webview gtk app I wanted to run on vanilla Debian setup last night.. so I did the canonical-thing-of-the-month and used uv to instantiate a venv and pull the dependencies. Then attempted to run the code.. mayhem. Errors indicating that the right things were in place but that the code still couldn't run (?) and finally Python Core Dumped.. OK. This is (in some shape or form) what happens every single time I give Python a fresh go for an idea. Eventually Golang is more verbose (and I don't particularly like the mod.go system either) but once things compile.. they run. They don't attempt running or require xyz OS specific hack.
  • emersion 4 minutes ago
    The following would probably be more portable:

        ///usr/bin/env go run "$0" "$@"; exit
    
    Note, the exit code isn't passed through due to: https://github.com/golang/go/issues/13440
  • llmslave2 1 hour ago
    I love it. I'm using Go to handle building full stack javascript apps, which actually works great since esbuild can be used directly inside a Go program. The issue is that it's a dependency, so I settled for having a go mod file and running it directly with Go. If somehow these dependencies could be resolved without an explicit module configured (say, it was inline in the go file itself) it would be perfect. Alas, it will probably never happen.

    That being said...use Go for scripting. It's fantastic. If you don't need any third party libraries this approach seems really clean.

    • ahartmetz 1 hour ago
      >full stack

      Device drivers, task switching, filesystem, memory management and all?

      • llmslave2 1 hour ago
        Yes. Yes, I'm doing all of that with Javascript :P
      • mstipetic 1 hour ago
        Don't be that guy.
        • ahartmetz 55 minutes ago
          I am going to be that guy.

          I make computers do things, but I never act like my stuff is the only stuff that makes things happen. There is a huge software stack of which my work is just the final pieces.

          • mstipetic 40 minutes ago
            The term "full stack" has a widely well understood meaning, you're being pedantic
            • SunlitCat 16 minutes ago
              The problem with calling it “full stack” (even if it has a widely understood meaning) is that it implicitly puts the people doing the actual lower-level work on a pedestal. It creates the impression that if this is already “full stack,” then things like device drivers, operating systems, or foundational libraries must be some kind of arcane magic reserved only for experts, which they aren’t.

              The term “full stack” works fine within its usual context, but when viewed more broadly, it becomes misleading and, in my opinion, problematic.

            • ahartmetz 24 minutes ago
              It doesn't for me and I don't think that my subculture of computing uses similarly myopic terms.
              • llmslave2 3 minutes ago
                Where did your subculture come from, Pedanticville?
  • magicalhippo 52 minutes ago
    You can do the same[1] with .Net Core for those of us who like that.

    [1]: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...

    • rr808 32 minutes ago
      dotnet was always really good for this. There were a bunch of third party tools that have done this since the 90s like toolsack.

      I think Java can run uncompiled text scripts now too

  • w4rh4wk5 1 hour ago
    Back in the days, I've seen that with C files, which are compiled on the fly to a temporary file an run.

    Something like //usr/bin/gcc -o main "$0"; ./main "$@"; exit

    • ernst_klim 56 minutes ago
      Tcc even supports that with `#!/usr/local/bin/tcc -run`, although I don't understand people who use c or go for "scripting", when python, ruby, TCL or perl have much superior ergonomics.
      • w4rh4wk5 44 minutes ago
        This was a relatively old project that used a C program as build system / meta generator. All you needed was a working C compiler (and your shell to execute the first line). From there, it built and ran a program that generated various tables and some source code, followed by compiling the actual program. The final program used a runtime reflection system, which was set up by the generated tables and code from the first stage.

        The main reason was to do all this without any dependencies beyond a C compiler and some POSIX standard library.

  • age123456gpg 1 hour ago
    Official stance about supporting interpreter mode for the reference https://github.com/golang/go/issues/24118
  • chrismorgan 28 minutes ago
    One suggestion: change `exit` to `exit $?` so an exit code is passed back to the shell.
  • throw-12-16 1 hour ago
    I've been meaning to port some dotfiles utils over to go, I think I'll give this a shot.
  • solumos 40 minutes ago
    > I started this post out mostly trolling, but the more I've thought about it's not a terrible idea.

    I feel like this is the unofficial Go motto, and it almost always ends up being a terrible idea.

  • wiseowise 1 hour ago
    [flagged]