Hacker News new | ask | show | jobs
by OskarS 36 days ago
Yes, you're absolutely right, but you're also illustrating the author's broader point a little bit. For someone not very deeply familiar with Nix (the language), that is a very difficult one-liner to parse. You have to be pretty hard-core nix-pilled to understand what that one is doing just reading it straight-on (my NAS is using NixOS, so I've written some amount of Nix). On the other hand, the TypeScript code the author provides is reasonably straight-forward, you don't have to be particularly familiar with either TypeScript or Nix to understand what it is doing.

You're correct in that the article is wrong in saying you can't use a nix repl this way, but I took the broader point of it to be "Nix-the-language gets in the way of the Nix-the-model". Which is something that I personally agree with 100% and I think the article illustrates beautifully.

1 comments

> You have to be pretty hard-core nix-pilled to understand what that one is doing just reading it straight-on [..]

There is little practical difference between that example and:

    Object.keys(licenses).filter(name => licenses[name]?.spdxId?.startsWith("GPL"))
The main difference is the syntax regarding attribute set operator (`attset ? key`), the rest is easily understandable by anyone that knows at least one or two programming languages that have closures (including Javascript).

> On the other hand, the TypeScript code the author provides is reasonably straight-forward [..]

Readability-wise, the Nix code from the article wins - the TS version has annotations that make it unnecessarily verbose, like `nix.lambda`, `nix.app`, `nix.sel`; to name a few.

From the article:

> Nix is lazy, so the emitted code wraps an expression in nix.thunk(() => ...) wherever Nix would allocate a thunk. (throw-up emoji)

I concur with the feeling.

I don't think I would alone in saying that your JavaScript example is much easier to read than the Nix variant. It reads very cleanly, it's obvious what's a function and what are arguments to the function, and you can easily read it left to right. You have to track the parentheses a long way to see that builtins.filter takes two arguments, and it's very non-obvious what the first argument even is. It's much harder to read than `Object.keys(licenses).filter(...)`, IMHO.

Maybe there's no inherent cosmic superiority to the C/C++/Java style syntax of JavaScript/TypeScript compared to the Haskell-style syntax of Nix, but in reality, most programmers can read it easily. Which is not something that can be said for Nix.

On the `nix.thunk` thing, that was for the code that was automatically transpiled from Nix while maintaining the exact semantics, so yeah, it looks ugly. But the article has examples of what it would look like hand-written, and it looks just fine.