I have a better idea: `ocaml script.ml` ;-)<p>Get started here: <a href="https://dev.to/yawaramin/practical-ocaml-314j" rel="nofollow">https://dev.to/yawaramin/practical-ocaml-314j</a>
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: <a href="https://docs.astral.sh/uv/guides/scripts/#using-a-shebang-to-create-an-executable-file" rel="nofollow">https://docs.astral.sh/uv/guides/scripts/#using-a-shebang-to...</a>
I solved this in 2019 with PyFlow, but no one used it, so I lost interest. It's an OSS tool written in rust that automatically and transparently manages python versions and venvs. You just setup a `pyproject.toml`, run `pyflow main.py` etc, and it <i>just works</i>. Installs and locks dependencies like Cargo, installs and runs the correct Python version for the project etc.<p>At the time, Poetry and Pipenv were the popular tools, but I found they were not sufficient; they did a good job abstracting dependencies, but not venvs and Python version.
Actually you can go one better:<p><pre><code> #!/usr/bin/env -S uv run --python 3.14 --script
</code></pre>
Then you don't even need python installed. uv will install the version of python you specified and run the command.
alternatively, uv lets you do this:<p><pre><code> #!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = ["foo"]
# ///</code></pre>
The /// script block is actually specified in PEP 723 and supported by several other tools apart from uv.
This is an awesome features for quick development.<p>I'm sure the documentation of this featureset highlights what I'm about to say but if you're attracted to the simplicity of writing Python projects who are initialized using this method, do not use this code in staging/prod.<p>If you don't see why this is not production friendly it's for the simple a good.reaaon that creating deployable artifacts packaging a project or a dependency of a project this uses this method, creating reproducible builds becomes impossible.<p>This will also lead to builds that pass your CI but fail to run in their destination environment and vice versa due to the fact that they download heir dependencies on the fly.<p>There may be workarounds and I know nothing of this feature so investigate yourself if you must.<p>My two cents.
This isn't really "alternatively"; it's pointing out that in addition to the shebang you can add a PEP 723 dependency specification that `uv run` (like pipx, and some other tools) can take into account.
Yeah, but you need `uv`. If we are reaching out for tools that might not be around, then you can also depend on nix-shell,<p><pre><code> #! /usr/bin/env nix-shell
#! nix-shell -i python3 --packages python3</code></pre>
Yeah, but you need Nix. If we are reaching out for tools that might not be around, then you can also depend on `curl | sudo bash` to install Nix when not present.<p>(this is a joke btw)
This comes with the added benefit that your environment is reverted as soon as you exit the Nix shell.
That shebang will work on GNU link based systems, but might not work elsewhere. I know that’s the most popular target, but not working on macOS, BSDs, or even busybox.
> Then you don't even need python installed. uv will install the version of python you specified and run the command<p>What you meant was, "you don't need python pre-installed". This does not solve the problem of not wanting to have (or limited from having) python installed.
I thought that too, but I think the tricky bit is if you're a non-python user, this isn't yet obvious.<p>If you've never used Clojure and start a Clojure project, you will almost definitely find advice telling you to use Leiningen.<p>For Python, if you search online you <i>might</i> 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.<p>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.<p>Although in that case, it was a much quicker resolution than I think anyone fighting with virtual environments would have.
That's my experience. I'm not a Python developer, and installing Python programs has been a mess for decades, so I'd rather stay away from the language than try another new tool.<p>Over the years, I've used setup.py, pip, pipenv (which kept crashing though it was an official recommendation), manual venv+pip (or virtualenv? I vaguely remember there were 2 similar tools and none was part of a minimal Python install). Does uv work in all of these cases? The uv doc pointed out by the GP is vague about legacy projects, though I've just skimmed through the long page.<p>IIRC, Python tools didn't share their data across projects, so they could build the same heavy dependencies multiple times. I've also seen projects with incomplete dependencies (installed through Conda, IIRC) which were a major pain to get working. For many years, the only simple and sane way to run some Python code was in a Docker image, which has its own drawbacks.
> Does uv work in all of these cases?<p>Yes. The goal of uv is to defuck the python ecosystem and they're doing a very good job at it so far.
> IIRC, Python tools didn't share their data across projects, so they could build the same heavy dependencies multiple times.<p>One of the neatest features of uv is that it uses clever symlinking tricks so if you have a dozen different Python environments all with the same dependency there's only one copy of that dependency on disk.
Hard links, in fact. It's not hard to do, just (the Rust equivalent of) `os.link` in place of `os.copy` pretty much. The actually clever part is that the package cache actually contains files that can be used this way, instead of just having wheels and unpacking them from scratch each time.<p>For pip to do this, first it would have to organize its cache in a sensible manner, such that it could work as an actual <i>download</i> cache. Currently it is an <i>HTTP</i> cache (except for <i>locally-built</i> wheels), where it uses a vendored third-party library to simulate the connection to files.pythonhosted.org (in the common PyPI case). But it still needs to connect to pypi.org to figure out the URI that the third-party library will simulate accessing.
I would not be putting up with Python if not for uv. It’s that good.<p>Before uv came along I was starting to write stuff in Go that I’d normally write in Python.
Coming from a mostly Java guy (since around 2001), I've been away from Python for a while and my two most recent work projects have been in Python and both switched to uv around the time I joined. Such a huge difference in time and pain - I'm with you here.<p>Python's always been a pretty nice language to work in, and uv makes it one of the most pleasant to deal with.
uv solved it, it’s safe to come back now.
There's definitely a philosophical shift that you can observe happening over the last 12-15 years or so, where at the start you have the interpreter as the centre of the world and at the end there's an ecosystem management tool that you use to give yourself an interpreter (and virtual environments, and so on) per project.<p>I think this properly kicked off with RVM, which needed to come into existence because you had this situation where the Ruby interpreter was going through incompatible changes, the versions on popular distributions were lagging, and Rails, the main reason people were turning to Ruby, was relatively militant about which interpreter versions it would support. Also, building the interpreter such that it would successfully run Rails wasn't trivial. Not <i>that</i> hard, but enough that a convenience wrapper mattered. So you had a whole generation of web devs coming up in an environment where the core language wasn't the first touchpoint, and there wasn't an assumption that you could (or should) rely on what you could apt-get install on the base OS.<p>This is broadly an extremely good thing.<p>But the critical thing that RVM did was that it broke the circular dependency at the core of the problem: it didn't itself depend on having a working ruby interpreter. Prior to that you could observe a sort of sniffiness about tools <i>for</i> a language which weren't implemented <i>in</i> that language, but RVM solved enough of the pain that it barged straight past that.<p>Then you had similar tools popping up in other languages - nvm and leiningen are the first that spring to mind, but I'd also throw (for instance) asdf into the mix here - where the executable that you call to set up your environment has a '#!/bin/bash' shebang line.<p>Go has sidestepped most of this because of three things: 1) rigorous backwards compatibility; 2) the simplest possible installation onramp; 3) being timed with the above timeline so that having a pre-existing `go` binary provided by your OS is unlikely unless you install it yourself. And <i>none</i> of those are true of Python. The backwards compatibility breaks in this period are legendary, you almost always <i>do</i> have a pre-existing Python to confuse things, and installing a new python without breaking that pre-existing Python, which your OS itself depends on, is a risk. Add to that the sniffiness I mentioned (which you can still see today on `uv` threads) and you've got a situation where Python is catching up to what other languages managed a decade ago.<p>Again.
It is sort of funny, if we squint just the wrong way, “ecosystem management tool first, then think about interpreters” starts to look a lot like… a package manager, haha.
> If you've never used Clojure and start a Clojure project, you will almost definitely find advice telling you to use Leiningen.<p>I thought the current best practice for Clojure was to use the shiny new built-in tooling? deps.edn or something like that?
deps.edn is becoming the default choice, yes. I interpreted the parent comment as saying "you will see advice to use leiningen (even though newer solutions exist, simply because it _was_ the default choice when the articles were written)"
Do you think a non-python user would piece it together if the shebang line reveals what tool to use?
> you might find someone saying to use uv, but also potentially <i>venv</i>, poetry or hatch.<p>This is sort of like saying "You might find someone saying to drive a Ford, but also potentially <i>internal combustion engine</i>, Nissan or Hyundai".
Only to those already steeped in Python. To an outsider they're all equally arbitrary non-descriptive words and there's not even obvious proper noun capitalization to tell apart a component from a tool brand.
It's always rather irritating to me that people make these complaints without trying to understand any of the under-the-hood stuff, because the ultimate conclusion is that it's <i>somehow a bad thing</i> that, on a FOSS project, multiple people tried to solve a problem concurrently.
I imagine by this they meant `python -m venv` specifically, using that interface directly, rather than through another wrapper CLI tool.
uv has been around for less than two years. It’s on track to become the default choice, it’s just a matter of time.
I've moved over mostly to uv too, using `uv pip` when needed but mostly sticking with `uv add`. But as soon as you start using `uv pip` you end up with all the drawbacks of `uv pip`, namely that whatever you pass after can affect earlier dependency resolutions too. Running `uv pip install dep-a` and then `... dep-b` isn't the same as `... dep-b` first and then `... dep-a`, or the same as `uv pip install dep-a dep-b` which coming from an environment that does proper dependency resolution and have workspaces, can be really confusing.<p>This is more of a pip issue than uv though, and `uv pip` is still preferable in my mind, but seems Python package management will forever be a mess, not even the bandaid uv can fix things like these.
you don't even need you prefered python version, uv will download it.
Won't those dependencies then be global? With potential conflicts as a result?
uv uses a global cache but hardlinks the dependencies for your script into a temp venv that is only for your script, so its still pretty fast.
Nope! uv takes care of that. uv is a work of art.
There are really so many things about this point that I don't get.<p>First off, in my mind the kinds of things that are "scripts" don't have dependencies outside the standard library, or if they do are highly specific to my own needs on my own system. (It's also notable that one of the advantages the author cites for Go in this niche is a standard library that avoids the need for dependencies in quick scripts! Is this not one of Python's major selling points since day 1?)<p>Second, even if you have dependencies you don't have to learn differences between these tools. You can pick one and use it.<p>Third, virtual environments are literally just a place on disk for those dependencies to be installed, that contains a config file and some stubs that are automatically set up by a one-liner provided by the standard library. You don't need to go into them and inspect anything if you don't want to. You don't need to use the activation script; you can just specify the venv's executable instead if you prefer. None of it is conceptually difficult.<p>Fourth, sharing an environment for these quick scripts <i>actually just works fine an awful lot of the time</i>. I got away with it for years before proper organization became second nature, and I <i>would usually still</i> be fine with it (except that having an isolated environment for the current project is the easiest way to be sure that I've correctly <i>listed</i> its dependencies). In my experience it's just not a thing for your quick throwaway scripts to be dependent on incompatible Numpy versions or whatever.<p>... And really, to avoid ever having to think about the dependencies you provide dynamically, you're going to switch to a compiled language? If it were such a good idea, nobody would have thought of making languages like Python in the first place.<p>And uh...<p>> As long as the receiving end has the latest version of go, the script will run on any OS for tens of years in the future. Anyone who's ever tried to get python working on different systems knows what a steep annoying curve it is.<p>The pseudo-shebang trick here isn't going to work on Windows any more than a conventional one is. And no, when I switched from Windows to Linux, getting my Python stuff to work was not a "steep annoying curve" <i>at all</i>. It came more or less automatically with acclimating to Linux in general.<p>(I guess referring to ".pyproject" instead of the actually-meaningful `pyproject.toml` is just part of the trolling.)
> Third, virtual environments are literally just a place on disk for those dependencies<p>I had a recent conversation with a colleague. I said how nice it is using uv now. They said they were glad because they hated messing with virtualenvs so much that preferred TypeScript now. I asked them what node_modules is, they paused for a moment, and replied “point taken”.<p>Uv still uses venvs because it’s the official way Python stores all the project packages in one place. Node/npm, Go/go, and Rust/cargo all do similar things, but I only really here people grousing about Python’s version, which as you say, you can totally ignore and never ever look at.
From my experience, it seems like a lot of the grousing is from people who don't like the "activation script" workflow and mistakenly think it's mandatory. Though I've also seen aesthetic objections to the environment actually having internal structure rather than just being another `site-packages` folder (okay; and what are the rules for telling Python to use it?)<p>The <i>very</i> long discussion (<a href="https://discuss.python.org/t/pep-582-python-local-packages-directory/963" rel="nofollow">https://discuss.python.org/t/pep-582-python-local-packages-d...</a>) of PEP 582 (<a href="https://peps.python.org/pep-0582/" rel="nofollow">https://peps.python.org/pep-0582/</a> ; the "__pypackages__" folder proposal) seems relevant here.
I've heard those objections, too. I do get that specific complaint: it's another step you have to do. That said, things like direnv and mise make that disappear. I personally like the activation workflow and how explicit it is, as you're activating that specific venv, or maybe one in a different location if you want to use that instead. I don't like sprinkling "uv run ..." all over the place. But the nice part is that both of those work, and you can pick whichever one you prefer.<p>It'll be interesting to see how this all plays out with __pypackages__ and friends.
> But the nice part is that both of those work, and you can pick whichever one you prefer.<p>Yep. And so does the pyenv approach (which I understand involves <i>permanently</i> adding a <i>relative</i> path to $PATH, wherein the system might place a stub executable that invokes the venv associated with the current working directory).<p>And so do hand-made subshell-based approaches, etc. etc.<p>In "development mode" I use my activation-script-based wrappers. When just hacking around I generally just give the path to the venv's python explicitly.
I use your "hacking around" method for things like cron jobs, with command lines like:<p><pre><code> * * * * * /path/to/project/.venv/python /path/to/project/foo.py
</code></pre>
It's more typing one time, but avoids a whole lot of fragility later.
....but you have to be able to get UV and on some platforms (e.g. a raspberry pi) it won't build because the version of rust is too old. So I wrote a script called "pv" in python which works a bit like uv - just enough to get my program to work. It made me laugh a bit, but it works anywhere, well enough for my usecase. All I had to do was embed a primitive AI generated TOML parser in it.
>I don't want to have virtual environments and learn what the difference between pip, poetry and uv is. I don't care. I just want to run the code.<p>So this is skill issue, the blog post. `uv run` and PEP 723 solved every single issue the author is describing.
While this is true, it is often stunning to me how long it took to get to `uv run`.<p>I have worked with Python on and off for 20+ years and I _always_ dreaded working with any code base that had external packages or a virtual environment.<p>`uv run` changed that and I migrated every code base at my last job to it. But it was too late for my personal stuff - I already converted or wrote net new code in Go.<p>I am on the fence about Python long term. I’ve always preferred typed languages and with the advent of LLM-assisted coding, that’s even more important for consistency.
Any old enough language will have competing libraries that you need to learn in the long run too.
It's a UX issue. The author is correct — <i>nobody cares</i> about all the mumbo-jambo virtualenvs or whatever other techno-babble.<p>The user<p>just<p>wants<p>to run<p>the damn program.<p>> `uv run` and PEP 723 solved every single issue the author is describing.<p>PEP 723 eh? "Resolution: 08-Jan-2024"<p>Sure, so long as you somehow magically gain the knowledge to use uv, then you will have been able to have a normal, table-stakes experience for whole 2 years now. Yay, go Python ecosystem!<p>Is uv the <i>default</i>, officially recommended way to run Python? No? Remember to wave goodbye to all the users passing the language by.
[dead]
Go has explicitly rejected adding shebang support, mandating this hack, due to being considered "abuse of resources"[0]. Rather `gorun`, which is also called a mistake by Pike, is recommended instead. And can alter this method so not to need to hardcode a path.<p><pre><code> /// 2>/dev/null ; gorun "$0" "$@" ; exit $?
</code></pre>
>Good-old posix magic. If you ask an LLM, it'll say it's due to Shebangs.<p>Well, ChatGPT gives same explanation as article, unsurprising considering this mechanic has been repeated many times.<p>>none other fits as well as Go<p>Nim, Zig, D, all have `-run` argument and can be used in similar way. Swift, OCaml, Haskell can directly execute a file, no need to provide an argument.<p>[0]: <a href="https://groups.google.com/d/msg/golang-nuts/iGHWoUQFHjg/_dbLKomrPmUJ" rel="nofollow">https://groups.google.com/d/msg/golang-nuts/iGHWoUQFHjg/_dbL...</a>
There is also yaegi, a Go interpreter, which might be a better choice for small scripts than 'go run'.<p><a href="https://github.com/traefik/yaegi" rel="nofollow">https://github.com/traefik/yaegi</a>
Mad genius stuff, this.<p>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.<p>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.<p>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.<p>I don't think I've thought about language ergonomics in this sense quite like this before, I'm curious what others think.
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.
Gtk makes that simple python program way more complex since it'll need more than pure-python dependencies.<p>It's really a huge pain point in python. Pure python dependencies are amazingly easy to use, but there's a lot of packages that depend on either c extensions that need to be built or have OS dependencies. It's gotten better with wheels and manylinux builds, but you can still shoot your foot off pretty easily.
I'm pretty sure the gtk dependencies weren't built by Astral, which, yes, unfortunately means that it won't always just work, as they streamline their Python builds in... unusual ways. A few months ago I had a similar issue running a Tkinter project with uv, then all was well when I used conda instead.
How were the dependencies specified? What kind of files were provided for you to instantiate the venv?
I haven't had the same issue with anaconda. Give it a try.
I've had similar issues with anaconda, once upon a time. I've hit a critical roadblock that ruined my day with every single Python dependency/environment tool except basic venv + requirements.txt, I think. That gets in the way the least but it's also not very helpful, you're stuck with requirements.txt which tends to be error-prone to manage.
> bash obviously is just using OS commands with syntactic sugar<p>No, bash is technically not "more" OS than e.g. Python. It just happens that bash is (often) the default shell in the terminal emulator.
Have to disagree, "technically" yes, both are interpreted languages, but the ergonomics and mental overhead of doing certain things are wildly different:<p>In python, doing math or complex string or collection operations is usually a simple oneliner, but calling shell commands or other OS processes requires fiddling with the subprocess module, writing ad-hoc streaming loops, etc - don't even start with piping several commands together.<p>Bash is the opposite: As long as your task can be structured as a series of shell commands, it absolutely shines - but as soon as you require custom data manipulation in any form, you'll run into awkward edge cases and arbitrary restrictions - even for things that are absolutely basic in other languages.
I love Python and dislike Bash, but just look at the difference between listing a folder in Bash vs Python, for example.
Maybe the ergonomics of <i>writing</i> code is less of a problem if you have a quick way of asking an LLM to do the edits? We can optimize for readability instead.<p>More specifically, for the readability of code written by an LLM.
I thought this was going to be a longer rant about how python needs to... Go away. Which, as a long time python programmer and contributor, and at one time avid proponent of the language, I would entertain the suggestion. I think all of ML being in Python is a collosal mistake that we'll pay for for years.<p>The main reasons being it is slow, its type system is significantly harder to use than other languages, and it's hard to distribute. The only reason to use it is inertia. Obviously inertia can be sufficient for many reasons, but I would like to see the industry consider python last, and instead consider typescript, go, or rust (depending on use case) as a best practice. Python would be considered deprecated and only used for existing codebases like pytorch. Why would you write a web app in Python? Types are terrible, it's slow. There are way better alternatives.
100%.<p>With that said... there <i>is</i> a reason why ML went with Python. GPU programming requires C-based libraries. NodeJS does not have a good FFI story, and neither does Rust or Go. Yes, there's <i>support</i>, but Python's FFI support is actually better here. Zig is too immature here.<p>The world deserves a Python-like language with a better type system, a better distribution system, and not nearly as much dynamism footguns / rope for people to hang themselves with.
Typescript?<p>Why replace a nice language like python with anything coming out of javascript?
Its type system is miles better than Python and it has some basic stuff Python doesn't have like block scope. Functional programming is also intentionally kind of a pain in Python with the limited lambdas.<p>If TypeScript had the awesome python stdlib and the Numpy/ML ecosystem I would use it over Python in a heartbeat.
Typescript also has significantly better performance. This is largely thanks to the browser wars funnelling an insane amount of engineering effort toward JavaScript engines over the last couple decades. Nodejs runs v8, which is the JavaScript engine used by chrome. And Bun uses JSC, written by the safari team for safari.<p>For IO bound tasks, it also helps that JavaScript has a much simpler threading model. And it ships an event based IO system out of the box.
you can define a named closure in python, i do it from time to time, though it does seem to surprise others sometimes. i think maybe it's not too common.
Typescript is a really nice language even though it sits on a janky runtime. I’d love a subset of typescript that compiles to Go or something like that.
Typescript is ubiquitous in web, and there are some amazing new frameworks that reuse typescript types on the server and client (trpc, tanstack). It's faster (than python), has ergonomic types, and a massive community + npm ecosystem. Bun advances the state of the art for runtime performance (which anthropic just bought and use for Claude code).
TypeScript is great!<p>Has shortcomings like all languages but it brought a lot of advanced programming language concepts to the masses!
Typescript is a lot nicer than Python in many ways. Especially via Deno, and especially for scripting (imports work like people want!).<p>There are some things that aren't as good, e.g. Python's arbitrary precision integers are definitely nicer for scripting. And I'd say Python's list comprehension syntax is often quite nice even if it is weirdly irregular.<p>But overall Deno is a much better choice for ad-hoc scripting than Python.
"> I think all of ML being in Python is a colossal mistake that we'll pay for for years.<p>Market pressure. Early ML frameworks were in Lisp, then eventually Lua with Torch, but demand dictated the choice of Python because "it's simple" even if the result is cobbled together.<p>Lisp is arguably still the most suitable language for neural networks for a lot of reasons beyond the scope of this post, but the tooling is missing. I’m developing such a framework right now, though I have no illusions that many will adopt it. Python may not be elegant or efficient, but it's simple, and that's what people want.
Gee, I wonder why the tooling for ML in Lisp is missing even though the early ML frameworks were in Lisp. Perhaps there is something about the language that stifles truly wide collaboration?
What sort of tooling is missing in Lisp? I'd love to check out your framework if you've shared it somewhere
I'd love to replace Python with something simple, expressive, and strongly typed that compiles to native code. I have a habit of building little CLI tools as conveniences for working with internal APIs, and you wouldn't think you could tell a performance difference between Go and Python for something like that, but you can. After a year or so of writing these tools in Go, I went back to Python because the LOC difference is stark, but every time I run one of them I wish it was written in Go.<p>(OCaml is probably what I'm looking for, but I'm having a hard time getting motivated to tackle it, because I dread dealing with the tooling and dependency management of a 20th century language from academia.)
<a href="https://dev.to/yawaramin/practical-ocaml-314j" rel="nofollow">https://dev.to/yawaramin/practical-ocaml-314j</a>
Have you tried Nim? Strong and static typed, versatile, compiles down to native code vía C, interops with C trivially, has macros and stuff to twist your brain if you're into that, and is trivially easy to get into.<p><a href="https://nim-lang.org" rel="nofollow">https://nim-lang.org</a>
That looks very interesting. The code samples look like very simple OO/imperative style code like Python. At first glance it's weird to me how much common functionality relies on macros, but it seems like that's an intentional part of the language design that users don't mind? I might give it a try.
You can replace Python with Nim. It checks literally all your marks (expressive, fast, compiled, strong-typing). It's as concise as Python, and IMO, Nim syntax is even more flexible.<p><a href="https://nim-lang.org" rel="nofollow">https://nim-lang.org</a>
I bounced off OCaml a few years ago because of the state of the tooling, despite it being almost exactly the language I was looking for.
I'm really happy with Gleam now, and recommended it over OCaml for most use cases.
I always assumed a runtime specialized for highly concurrent, fault-tolerant, long-running processes would have a noticeable startup penalty, which is one of the things that bothers me about Python. Is that something you notice with Gleam?
I tried out Gleam for Advent of Code this year. There was a significant difference in startup times, about 13 ms for Python and 120 ms for Gleam.<p>If you want something with minimal startup times then you need a language that complies to native binaries like Zig, Rust or OCaml.
Can you use Gleam for ad-hoc scripting? In my mind that means two requirements that most languages fail at.<p>1. You can import by relative file path. (Python can't.)<p>2. You can specify third party dependencies in a single file script and <i>have that work properly with IDEs</i>.<p>Deno is the best option I've found that has both of those and is statically typed.<p>I'm hoping Rust will eventually too but it's going to be at least a year or two.
Yes, Go can hardly be called statically typed, when they use the empty interface everywhere.<p>Yes, OCaml would be a decent language to look into. Or perhaps even OxCaml. The folks over at Jane Street have put a lot of effort into tooling recently.
I suppose you could try typescript which can compile to a single binary using node or bun. Both bun and node do type stripping of ts types, and can compile a cli to a single file executable. This is what anthropic does for Claude code.
I swear the only the people who care about Python types are on Hacker News comments. I've never actually worked with or met someone who cared so much about it, and the ones that care at all seem just fine with type hints.
How much does python really impact ml? All of the libraries are wrappers around C code that uses gpus any way, it's distributed and inference can be written in faster languages for serving anyway?
You're thinking only about the final step where we're just doing a bunch of matrix computation. The real work Python does in the ML world is <i>automatic differentiation</i>.<p>Python has multiple <i>excellent</i> options for this: JAX, Pytorch, Tensorflow, autograd, etc. Each of these libraries excels for different use cases.<p>I also believe these are cases where Python the <i>language</i> is part of the reason these libraries exist (whereas, to your point, for the matrix operations pretty much any language could implement these C wrappers). Python does make it easy to perform meta-programming and is very flexible when you need to manipulate the language itself.
<i>I think all of ML being in Python is a colossal mistake that we'll pay for for years.</i><p>If ML fulfills its promise, it won't matter in the least what language the code is/was written in.<p>If it doesn't, it won't matter anyway.
> I think all of ML being in Python is a collosal mistake that we'll pay for for years.<p>> The main reasons being it is slow, <snip>, and it's hard to distribute.<p>Don't forget that Python consumes approximately 70x more power when compared to C.
This is a needlessly dismissive and narrow-minded attitude. Have you ever tried to use FastAPI?
You say he's narrow-minded, but you focus on the least relevant thing of everything he said, speed, and suggest that, somehow, something with "fast" in its name will fix it?<p>Speed is the least concern because things like numpy are written in C and the overhead you pay for is in the glue code and ffi. The lack of a standard distribution system is a big one. Dynamic typing works well for small programs and teams but does not scale when either dimension is increased.<p>But pure Python is inherently slow because of language design. It also cannot be compiled efficiently unless you introduce constraints into the language, at which point you're tackling a subset thereof. No library can fix this.
Very little of what you're claiming is relevant for FastAPI specifically, which in terms of speed isn't too far from an equivalent app written in Go for writing a web app. You need to research the specifics of a problem at hand instead of making broad but situationally incorrect assumptions. The subject here is web apps, and Python is very much a capable language in this niche as of the end of 2025, both in terms of speed, code elegance and support for static typing (FastAPI is fully based on Pydantic) - <a href="https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-6" rel="nofollow">https://www.techempower.com/benchmarks/#section=test&runid=7...</a>
> But pure Python is inherently slow because of language design. It also cannot be compiled efficiently unless you introduce constraints into the language, at which point you're tackling a subset thereof. No library can fix this.<p>A similar point was raised in the other python thread on cpython the other day, and I’m not sure I agree. For sure, it is far from trivial. However, GraalVM has shown us how it can be done for Java with generics. Highover, take the app, compile and run it. The compilation takes care of any literal use of Generics, running the app takes care of initialising classes and memory, instrumentation during runtime can be added to add runtime invocations of generics otherwise missed. Obviously, this takes a lot of details getting it right for it to work. But it can be done.
Yes. Have you ever tried trpc?
While you are at it, might as well do this for C++ or assembly. You hate scripting so much and would rather go to great lengths to use a complied language and throw away all the benefits of a scripting language and scripting itself, just because you don't like the language, not because of technical merit. Congratulations, you just wasted yourself many hours of precious time.<p>> The price of convenience is difficulties to scale<p>Of course, they never scale. The moment you start thinking about scaling, you should stop writing code as throwaway scripts but build them properly. That's not an argument to completely get rid of Python or bash. The cost of converting Python code to Go is near zero these days <i>if there is a need to do so</i>. Enough has been said about premature optimization.<p>> Anyone who's ever tried to get python working on different systems knows what a steep annoying curve it is.<p>If you need 10 libraries of certain versions to run a few lines of Python code, nobody calls that a script anymore. It becomes a proper project that requires proper package management, <i>just like Go</i>.
There is a much larger gap in language ergonomics between python and C++ than between python and golang. Compile time and package management being some of the major downsides to C++.<p>"You'd rather drive a compact car than an SUV? Might as well drive a motorcycle then!"
The main problem with python for system scripts is that's even in that domain it's not a very good choice.<p>Perl is right there, requires no installation, and is on practically every unix-like under the sun. Sure it's not a good language, or performant, or easy to extend, but neither is python, so who cares. And, if anything, it's a bit more expressive and compact than python, maybe to a fault.
I don’t really understand the initial impetus. I <i>like</i> scripting in Python. That’s one of the things it’s good at. You can extremely quickly write up a simple script to perform some task, not worrying about types, memory, yada yada yada. I <i>don’t like</i> using Python as the main language for a large application.
I love scripting in Python too. I just hate trying to install other people’s scripts.
> hate trying to install other people’s scripts.<p>This phrasing sounds contradictory to me. The whole idea of scripts is that there's nothing to install (besides one standard interpreter). You just <i>run</i> them.
> I just hate trying to install other people’s scripts.<p>This notion is still strange to me. Just... incompatible with how I understand the term "script", I guess.
You don't understand the concept of people running software written by other people?<p>One of my biggest problems with python happens to be caused by the fact that a lot of freecad is written in python, and python3 writes _pycache_ directories everywhere a script executes (which means everywhere, including all over the inside of all my git repos, so I have to add _pycache_ to all the .gitignore ) and the env variable that is supposed to disable that STUPID behavior has no effect because freecad is an appimage and my env variable is not propagating to the environment set up by freecad for itself.<p>That is me "trying to install other people's scripts" the other people's script is just a little old thing called FreeCAD, no big.
> That is me "trying to install other people's scripts" the other people's script is just a little old thing called FreeCAD, no big.<p>What I don't understand is why you call it a "script".<p>> and python3 writes _pycache_ directories everywhere a script executes (which means everywhere, including all over the inside of all my git repos, so I have to add _pycache_ to all the .gitignore )<p>You're expected to do that anyway; it's part of the standard "Python project" .gitignore files offered by many sources (including GitHub).<p>But you mean that the repo contains plugins that FreeCAD will import? Because otherwise I can't fathom why it's executing .py files that are within your repo.<p>Anyway, this seems like a very tangential rant. And this is essentially the same thing as Java producing .class files; I can't say I run into a lot of people who are this bothered by it.
If they use <a href="https://packaging.python.org/en/latest/specifications/inline-script-metadata/" rel="nofollow">https://packaging.python.org/en/latest/specifications/inline...</a> then it becomes a breeze to run with uv. Not even a thing.
It seems to be Linux specific (does it even work on other unix like OSes?) and Linux usually has a system Python which is reasonably stable for things you need scripting for, whereas this requires go to be installed.<p>You could also use shell scripting or Python or another scripting language. While Python is not great at backward compatibility most scripts will have very few issues. Shell scripts are backward compatible as are many other scripting languages are very backward compatible (e.g. TCL) and they areG more likely to be preinstalled. If you are installing Go you could just install uv and use Python.<p>The article does say "I started this post out mostly trolling" which is part of it, but mostly the motivation would be that you have a strong preference for Go.
Python is great for the coder, and unholy garbage for everyone else.<p>If you care about anyone but yourself, don't write things in python for other people to distribute, install, integrate, run, live with.<p>If you don't care about anyone else, enjoy python.
You do have to worry about types, you always do.
You have to know, what did this function return, what can you do with it.<p>When you know well the language, you dont need to search for this info for basic types, because you remember them.<p>But that's also true for typed languages.
This is more than just trivially true for Python in a scripting context, too, because it doesn’t do things like type coercion that some other scripting languages do. If you want to concat an int with a string you’ll need to cast the int first, for example. It also has a bunch of list-ish and dict-ish built in types that aren’t interchangeable. You have to “worry about types” more in Python than in some of its competitors in the scripting-language space.
> The one big problem: gopls. We need the first line of the script to be without spaces...<p>Specifically the problem here is automated reformatting. Gopls typically does this on save as you are editing, but it is good practice for your CI system to enforce the invariant that all merged *.go files are canonically formatted. This ensures that the user who makes a change formats it (and is blamed for that line), instead of the hapless next person to touch some other spot in that file. It also reduces merge conflicts.<p>But there's a second big (bigger) problem with this approach: you can't use a go.mod file in a one-off script, and that means you can't specify versions of your dependencies, which undermines the appeal to compatibility that motivated your post:<p>> The primary benefit of go-scripting is [...] and compatibility guarantees. While most languages aims to be backwards compatible, go has this a core feature. The "go-scripts" you write will not stop working as long as you use go version 1.*, which is perfect for a corporate environment.<p>> In addition to this, the compatibility guarantees makes it much easier to share "scripts". As long as the receiving end has the latest version of go, the script will run on any OS for tens of years in the future.
Ha, I just tried the same trick with Rust:<p><pre><code> //$HOME/.cargo/bin/rustc "$0" && ${0%.rs} "$@" ; exit
use std::env;
fn main() {
println!("hello, world!");
for arg in env::args() {
println!("arg: {arg}");
}
}
</code></pre>
Total hack, and it litters ./ with the generated executable. But cute.
Expected a rant, got a life-pro-tip. Enough for a good happy new year.<p>That said, we can abuse the same trick for any languages that treats `//` as comment.<p>List of some practical(?) languages: C/C++, Java, JavaScript, Rust, Swift, Kotlin, ObjC, D, F#, GLSL/HLSL, Groovy<p>Personally, among those languages, GLSL sounds most interesting. A single-GLSL graphics demo is always inspiring. (Something like <a href="https://www.shadertoy.com/" rel="nofollow">https://www.shadertoy.com/</a> )<p>Also, let’s not forget that we can do something similar using block comment(`/* … */`). An example in C:<p>/*/../usr/bin/env gcc "$0" "$@"; ./a.out; rm -vf a.out; exit; */<p>#include <stdio.h><p>int main() { printf("Hello World!\n"); return 0; }
For Swift there’s even a project[1] that allows running scripts that have external dependencies (posting the fork because the upstream is mostly dead).<p>I think it’s uv’s equivalent, but for Swift.<p>(Also Swift specifically supports an actual shebang for Swift scripts.)<p>[1] <a href="https://github.com/xcode-actions/swift-sh" rel="nofollow">https://github.com/xcode-actions/swift-sh</a>
You don't need to abuse comments like this for Rust, because it supports shebangs directly.
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.<p>That being said...use Go for scripting. It's fantastic. If you don't need any third party libraries this approach seems really clean.
I made one of these too! I decided not to use // because I use gofmt auto formatting in my editor and it puts a space between the // and the usr. This one isn't changed by gofmt:<p><pre><code> /*?sr/bin/env go run "$0" "$@"; exit $? #*/</code></pre>
You can lose the ugly "exit" at the end and space it right for formatting too<p><pre><code> // 2>/dev/null; exec go run "$0" "$@"</code></pre>
You can do the same[1] with .Net Core for those of us who like that.<p>[1]: <a href="https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/tutorials/file-based-programs#unix-shebang--support" rel="nofollow">https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...</a>
That's explicit support rather than using the same // hack. The language is specifically ignoring a shebang even though it doesn't match the usual comment syntax.
dotnet was always really good for this. There were a bunch of third party tools that have done this since the 90s like toolsack.<p>I think Java can run uncompiled text scripts now too
I never had any trouble setting up or working with venvs. I don't even feel the need to learn what uv is because it's such a non problem for me.
In a similar way I changed all of my build and deployment scripts to Go not long ago. The actual benefit was utility functions used by the service could be shared in deployment. So I could easily share code to determine if services/dbs were online or to access cloud secrets in a uniform way. It also improved all the error checks to be much clearer (did the curl fail because it’s offline or malformed).<p>Additionally, it is even more powerful when used with go modules. Make every script call a single function in the shared “scripts” module and they will all be callable from anywhere symmetrically. This will ensure all scripts build even if they aren’t run all the time. It also means any script can call scripts.DeployService(…) and they don’t care what dir they are in, or who calls it. The arguments make it clear what paths/configuration is needed for each script.
> Sidetrack: I actually looked up what the point of arg0 even is since I failed to find any usecases some months back and found this answer.<p>I think arg0 was always useful especially when developing multifunctional apps like busybox that changes its behavior depending on the name it was executed as.
Cute trick! I pointlessly wondered if I could make it work with Ruby and you <i>kinda</i> can, if you can tolerate a single error message before the script runs (sadly # comments don't work as shells consider them comments too):<p><pre><code> =begin
ruby $0; exit
=end
puts "Hello from Ruby"
</code></pre>
Not immediately useful, but no doubt this trick will pop up at some random moment in the future and actually be useful. Very basic C99 too, though I'm not sure I'd want to script with it(!):<p><pre><code> //usr/bin/cc $0 && ./a.out && exit</code></pre>
Official stance about supporting interpreter mode for the reference <a href="https://github.com/golang/go/issues/24118" rel="nofollow">https://github.com/golang/go/issues/24118</a>
You don't even need to end the file in `.go` or the like when using shebangs, and any self-respecting editor will be good at parsing out shebangs to identify file types (... well, Emacs seems to do it well enough for me)<p>no need to name your program foo.go when you could just name it foo
> don't want to have virtual environments and learn what the difference between pip, poetry and uv is<p>Oh come on, it's easy:<p>Does the project have a setup.py? if so, first run several other commands before you can run it. python -m venv .venv && source .venv/bin/activate && pip install -e .<p>else does it have a requirements.txt? if so python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt<p>else does it have a pyproject.toml? if so poetry install and then prefix all commands with poetry run ...<p>else does it have a pipfile? pipenv install and then prefix all commands with pipenv run ...<p>else does it have an environment.yml? if so conda env create -f environment.yml and then look inside the file and conda activate <environment_name><p>else does it have a uv.ock? then uv sync (or uv pip install -e .) and then prefix commands with uv run.
> Oh come on, it's easy: (satire)<p>If you've checked out a repo or unpacked a tarball without documentation, sure.<p>If you got it from PyPI or the documentation indicates you can do so, then you just use your tooling of choice.<p>Also, the pip+venv approach works fine with pyproject.toml, which was designed for interoperability. Poetry is oriented towards your own development, not working with someone else's project.<p>Speaking of which, a project that has a pipfile, environment.yml, uv.lock etc. <i>and doesn't have pyproject.toml</i> is not being seriously distributed. If this is something internal to your team, then you should already know what to do anyway.
And you consider that easy?
Back in the days, I've seen that with C files, which are compiled on the fly to a temporary file an run.<p>Something like //usr/bin/gcc -o main "$0"; ./main "$@"; exit
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.
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.<p>The main reason was to do all this without any dependencies beyond a C compiler and some POSIX standard library.
I've tried Go scripting but would still still prefer python (uv is a game changer tbh). My go-to for automation will always be powershell (on linux) though. It's too bad PowerShell has the MSFT ick keeping people away from adopting it for automation. I can convince you to give it a try if you let me
Related tangent: I recently learned about Mise^1 -- a tool for managing multiple language runtime versions. It might ease some of the python environment setup/mgmt pains everyone complains about. It apparently integrates with uv, and can do automatic virtualenv activation....<p>1. <a href="https://mise.jdx.dev/lang/python.html" rel="nofollow">https://mise.jdx.dev/lang/python.html</a><p>via
<a href="https://gelinjo.hashnode.dev/you-dont-need-nvm-sdkman-pyenv-rustup-homebrew-or-even-nix-try-mise-instead" rel="nofollow">https://gelinjo.hashnode.dev/you-dont-need-nvm-sdkman-pyenv-...</a>
One thing I hate about Python executables, at least the ones I've seen installed in Debian/Ubuntu is that the ones in /usr/bin are wrappers to execute somewhere in your site-packages.<p>I just want to see the full script where I execute it.
> Did you (rightfully) want to tear your eyes out when some LLM suggested that you script with .mjs?<p>I respectfully disagree with this sentiment. JS is a fantastic Python replacement for scripts. Node.js has added all kinds of utility functions that help you write scripts without needing external dependencies. Bun, Deno, and Node.js can execute TS files (if you want to bring types into the mix). All 3 runtimes are sufficiently performant. If you do end up needing external dependencies, they're only a package.json away. I write all my scripts in JS files these days.
For another excellent scripting solution that has
- fast startup (no compilation)
- uses a real language
- easy to upgrade beyond a script
- has tons of excellent dependencies baked-in<p>Look no further than babashka! It’s a clojure interpreter that has first class support scripting stuff. Great built in libs for shelling out to other programs, file management, anything http related (client and server), parsing, html building, etc.<p>Babashka is my go-to tool for starting all new projects now. It has mostly everything you need. And if it’s missing anything, it has some of the most interesting and flexible dependency management of any runtime I’ve ever seen. Via the “pod protocol” any process (written in go/rust/java whatever) can be exposed as a babashka dependency and bundled straight in. And no separate “install dependencies” command is required, it installs and caches things as needed.<p>And of course you keep all of the magic of REPL based development. It’s got built in nrepl support, so just by adding on ‘—nrepl-server 7888’ to your command, you can connect to it from your editor and edit the process live. I’m building my personal site this way and it’s just SO nice.<p>Sorry for the rant but when superior scripting solutions come up, I have to spread the love for bb. It’s too good to not talk about!!
The following would probably be more portable:<p><pre><code> ///usr/bin/env go run "$0" "$@"; exit
</code></pre>
Note, the exit code isn't passed through due to:
<a href="https://github.com/golang/go/issues/13440" rel="nofollow">https://github.com/golang/go/issues/13440</a>
Does the third leading slash do something?
To quote the blog in question:<p>> How true this is, is a topic I dare not enter.
The blog says that in regard to finding bash with env. My reading is that it does not make the same claim regarding finding go with env. bash is commonly found at /bin/bash (or a symlink there exists) as it is widely used in scripts and being available at that path is a well known requirement for compatibility. Go does not so much have a conical path and I have personally installed it at a variety of paths over the years (with the majority working with env). While I agree with the author of the blog that using env to find bash may or may not improve compatibility, I also agree with the parent comment that using env to find go probably does improve compatibility.
May I...<p>augroup fix
autocmd!
autocmd BufWritePost *.go
\ if getline(1) =~# '^// usr/bin/'
\ | call setline(1, substitute(getline(1), '^// ', '//', ''))
\ | silent! write
\ | endif
augroup END
You can also use jbang to run java scripts with dependencies<p><a href="https://www.jbang.dev/" rel="nofollow">https://www.jbang.dev/</a>
One suggestion: change `exit` to `exit $?` so an exit code is passed back to the shell.
I've been meaning to port some dotfiles utils over to go, I think I'll give this a shot.
You can use <a href="https://github.com/erning/gorun" rel="nofollow">https://github.com/erning/gorun</a> as a Go script runner. It lets you embed `go.mod` and `go.sum` and have dependencies in Go scripts. This is more verbose than Python's inline script metadata and requires manual management of checksums. gorun caches built binaries, so scripts start quickly after the first time.<p>Example:<p><pre><code> #! /usr/bin/env gorun
//
// go.mod >>>
// module foo
// go 1.22
// require github.com/fatih/color v1.16.0
// require github.com/mattn/go-colorable v0.1.13
// require github.com/mattn/go-isatty v0.0.20
// require golang.org/x/sys v0.14.0
// <<< go.mod
//
// go.sum >>>
// github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
// github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
// github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
// github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
// github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
// github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
// github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
// golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
// golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
// golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
// golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
// <<< go.sum
package main
import "github.com/fatih/color"
func main() {
color.Green("Hello, world!")
}
</code></pre>
The shebang line can be replaced for compatibility with standard Go tooling:<p><pre><code> /// 2>/dev/null ; gorun "$0" "$@" ; exit $?
//
// go.mod >>>
// ...</code></pre>
This is great. Means my scripts in a golang repo can also be written in Golang vs bash/python. It can even import libs from my project.<p>Awesome!
i tried this and security pinged me about behavior based security rules firing because it looks like an infostealer...
So the entire reason why this is not a "real" shebang and instead takes the roundtrip through the shell is because the Go runtime would trip over the # character?<p>I think this points to some shortcomings of the shebang mechanism itself: That it expects the shebang line to be present and adhering a specific structure - but then passes the entire file <i>with</i> the line to the interpreter where the interpreter has to process (and hopefully ignore) the line again.<p>I know that situations where one piece of text is parsed by multiple different systems are intellectually interesting and give lots of opportunities for cleverness - but I think the straightforward solution would be to avoid such situations.<p>So maybe the linux devs should consider adding a new form for the shebang where the first line is just stripped before passing the file contents to the interpreter.
Linux already did one better: binfmt_misc (see <a href="https://blog.cloudflare.com/using-go-as-a-scripting-language-in-linux/" rel="nofollow">https://blog.cloudflare.com/using-go-as-a-scripting-language...</a> for using it for a much cleaner way of using it to use gorun on executable *.go files.)
It doesn't pass the file contents at all, it passes the file path.
Yep, this is a common misunderstanding, and the blog post itself repeats it.<p>The only way to "pass the file contents" would be through the standard input stream, but the script might want to use stdin like normal, so this isn't an option.
skill issue
> Sidetrack: I actually looked up what the point of arg0 even is since I failed to find any usecases some months back and found this answer[0]. Confused, and unsatisfied by the replies, I gave up trying to understand "why arg0?" as some sort of legacy functionality.<p>I struggle to think of how the answers provided here could be clearer or more satisfactory. Why write an article if you're going to half-ass your research? Why even mention this nothingburger sidetrack at all...? (Bait?)<p>[0] <a href="https://stackoverflow.com/questions/24678056/linux-exec-function-what-is-the-arg0-parameter-used-for" rel="nofollow">https://stackoverflow.com/questions/24678056/linux-exec-func...</a>
See also <a href="https://blog.cloudflare.com/using-go-as-a-scripting-language-in-linux/#current-state-of-go-scripting" rel="nofollow">https://blog.cloudflare.com/using-go-as-a-scripting-language...</a> and <a href="https://gist.github.com/posener/73ffd326d88483df6b1cb66e8ed1e0bd" rel="nofollow">https://gist.github.com/posener/73ffd326d88483df6b1cb66e8ed1...</a> . They explained the direct use of "go run" was not good in some scenario. Is that still applied today?<p>> go run does not properly return the script error code back to the operating system and this is important for scripts, because error codes are one of the most common ways multiple scripts interact with each other and the operating system environment.
what's even cooler is when the language comes with first class support for this: <a href="https://www.erlang.org/docs/18/man/escript" rel="nofollow">https://www.erlang.org/docs/18/man/escript</a><p>Or the venerable <a href="https://babashka.org/" rel="nofollow">https://babashka.org/</a>
Go is poor for cheap scripts for one reason: error handling.<p>It’s great for “robust” code, not for quick things that you’re okay with exploding in the default way.
> I started this post out mostly trolling<p>So your goal was to waste your reader's time. Thanks.
Yes, you can but should you?
Tangent but... I kinda like the Python language. What I don't like about Python is the way environments are managed.<p>This is something I generally believe, but I think it's particularly important for things like languages and runtimes: the idea of installing things "on" the OS or the system needs to die.<p>Per-workspace or per-package environment the way Go, Rust, etc. does it is correct. Installing packages globally is wrong.<p>There should not be such a thing as "globally." Ideally the global OS should be immutable or nearly so, with the only exception being maybe hardware driver stuff.<p>(Yes I know there's stuff like conda, but that's yet another thing to fix a fundamentally broken paradigm.)
> This is something I generally believe, but I think it's particularly important for things like languages and runtimes: the idea of installing things "on" the OS or the system needs to die.<p>Python has been trying to kill it for years; or at least, the Linux distros have been seeking Python's help in killing it on Linux for years. <a href="https://peps.python.org/pep-0668/" rel="nofollow">https://peps.python.org/pep-0668/</a> is the latest piece of this.
I feel like this principle could be codified as "the system is not a workspace."<p>The use of the system as a workspace goes back to when computers were either very small and <i>always</i> personal only to one user, or when they were very big and administrated by dedicated system administrators who were the only ones with permission to install things. Both these conditions are obsolete.
I remember when I first experienced golang, I tried compiling it.<p>The compilation command returned immediately, and I thought it had failed. So I tried again and same result. WTF? I thought to myself. Till I did an `ls` and saw an `a.out` sitting in the directory. I was blown away by how fast the golang compiler was.
What about Mojo?
>This second method is, by the way, argued to increase compatibility as we utilize env to locate bash, which may not be located at /bin/bash. How true this is, is a topic I dare not enter.<p>At least it seems important on NixOS, I had to rewrite a few shebangs on some scripts that used /bin/bash and didn't work on NixOS.
argv0 is very necessary for use cases like busybox
Now try to call some C++ code from your Go script…
> I started this post out mostly trolling, but the more I've thought about it's not a terrible idea.<p>I feel like this is the unofficial Go motto, and it almost always ends up being a terrible idea.
[dead]
[dead]
[flagged]
Using `uv` with python is significantly safer and better. At least you get null safety. Sure, you can't run at the speed of light, but at least you can have some decent non-halfarsed-retrofitted type checking in your script.
In what way does Python have more null safety than Go? Using None will cause exceptions in basically all the same places using nil will cause panics in Go, and Python similarly lacks the usual null-safe operators like traversal (?.), coalescing (??), etc.<p>You can <i>abuse</i> the falsity of None to do things like `var or ""`, but this ground gets quite shaky when real bools get involved.
I think you're mistaking Go for some other language.
<p><pre><code> Try the following in sh:
////////usr/local/go/bin/go
</code></pre>
Well, how about this: I use ruby or python. And not shell.<p>Somehow I have been doing so since +25 years. Never regretted it.
Never really needed shell either. (Ok, that's not entirely true;
I refer to shell scripts. I do use bash as my primary shell, largely
due to simplicity; I don't use shell scripts though, save for keeping
a few legacy ones should I be at a computer that has no support for
ruby, python or perl. But this is super-rare nowadays.)