rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

[RFC 0148] Pipe operator

Open piegamesde opened this issue 1 year ago • 84 comments

Rendered

Discussion notice: please try to attach all discussions to a thread by using the code review feature. If your comment doesn't refer a specific line to attach to, use the header line instead.

piegamesde avatar May 23 '23 18:05 piegamesde

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/pre-rfc-pipe-operator/28387/3

nixos-discourse avatar May 23 '23 18:05 nixos-discourse

I am very well aware of the language's complexity. I am also aware of the fact that some of its users are very technical and into functional programming languages, and for many others this is a first contact with these concepts.

This is why I suggest picking only one of these operators as a compromise. I don't have any overly strong preferences here, but I make a point against function composition instead of argument piping, because the former leads to the so-called "point-free" programming style which tends to be more confusing for new users. I picked |> because of its similarity to the existing lib.pipe and the |> operator in Nickel, but if you are concerned about reversing control flow, then <| is a viable alternative too.

I strongly oppose calling this proposal "accidental" complexity. I spent a lot of time thinking about the options and trying to balance expressiveness and complexity, finding a compromise that makes solving real Nix problems easier. The Nix language is full of weird quirks users eventually have to face: we even have a wiki article collecting such instances, and it is far from exhaustive. Feel free to call these accidental complexity. But nothing about this proposal is accidental.

piegamesde avatar May 25 '23 12:05 piegamesde

To be clear, I don't use accidental to describe this RFC. I only used it in accidental complexity, which I've used as a synonym for extrinsic complexity. I can see that you've put a lot of thought into it, and I respect that, but that does not necessarily make the change a net positive.

expressiveness

A language with more syntax may be easier to write, but is not more expressive unless the syntax comes with semantics that were not already covered by existing features and combinations of them.

makes solving real Nix problems easier.

What is a real Nix problem? At least the lack of a syntax won't end up on the quirks page.

Are the quirks a problem? Probably. I'd be happy to see a proposal that simplifies the language or makes the syntax easier to learn, but those are hard problems with a lot of inertia, and up-front costs that aren't "repaid" for years into the future. Pragmatically, I think the real Nix problems aren't in the syntax. We might reach a stage where we could simplify the syntax and possibly redo it to make it more accessible to people who use more commonplace languages. That's not in the coming five years though, unless we radically expand the Nix team, which is rather resource constrained today.

roberth avatar May 25 '23 13:05 roberth

Nix is already considered to be overly complex by many.

And more people consider Nix awkward to read and write rather than being complex. Mostly because the standard library is poor and not discoverable.

|> would definitely make Nix less awkward to use.

suhr avatar May 25 '23 13:05 suhr

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/pre-rfc-pipe-operator/28387/10

nixos-discourse avatar May 25 '23 23:05 nixos-discourse

A language with more syntax may be easier to write, but is not more expressive unless the syntax comes with semantics that were not already covered by existing features and combinations of them.

I disagree with your interpretation of the word "expressiveness". Because you can (almost) always already solve all existing problems with existing syntax in (almost) any programming language. That's the point of being Turing complete. Therefore the question then becomes, how well can a problem be expressed in the language. And I think this holds true even for changes that are purely syntactical, like this one.

When adding new syntax to the language, one goal may indeed be to make it easier to write. Another one, and IMO much more important, is does it make the language easier to read. Depending on the feature and the language those may coincide, or one may have the other as a side benefit, or they may contradict each other. I recently learned Haskell, so I am very well aware of the trap of having a lot of powerful operators that allow it to write programs concisely and without parentheses, but which comes at the cost of readability.

What is a real Nix problem?

Problems that one might face when writing Nix code, either for some flake/shell/system configuration or when contributing to Nixpkgs. What I mean with this, is that I don't want to solve problems that for example mostly occur when trying to solve AdventOfCode in Nix.

piegamesde avatar May 26 '23 17:05 piegamesde

I think going through with this RFC would take gigantic effort

Honestly, the most effort in this RFC is convincing people, and maybe also the coordination across many projects. But from the technical side of things, this is actually pretty easy to implement.

and the positive results (if any) will be seen only after a few years.

This only applies to Nixpkgs, see https://github.com/NixOS/rfcs/pull/148#discussion_r1209471419

And I'm thinking those positive results aren't worth it, because they won't make Nixlang significantly easier to read for beginners, and they don't solve any technical issues with Nixpkgs or Nix.

They also won't make it significantly harder for beginners to read Nix code IMO, while bringing quality of life improvements to everyday Nix development.

I don't understand why only "technical" problems should be worth solving.

piegamesde avatar May 29 '23 17:05 piegamesde

This RFC is now open for shepherd nominations!

edolstra avatar May 31 '23 13:05 edolstra

@AndersonTorres because I don't know every programming language and just didn't come across OCaml during my research. Furthermore, the related work section is intended to roughly cover the design space, not to be an exhaustive list of every programming language.

piegamesde avatar Jun 05 '23 22:06 piegamesde

Updated the text according to some of the initial feedback. The more I think of it, the more I'm leaning towards also having <| in the language. I'll try to conduct a larger Nixpkgs survey soon to get some more data on that question. (Function concatenation operators are still out IMO)

piegamesde avatar Jun 06 '23 15:06 piegamesde

I was thinking on it, precisely, two pipe operators! It makes the language more orthogonal: if we have arg |> function, it looks reasonable to have function <| arg as its reverse operator.

The problems are:

  • if we are to elevate pipe to builtins and pipe == |>, where is the builtin for reverse pipe? The apply previously suggested looks good to me;

  • how the pipes should interact when in a same statement (a |> b <| c, a <| b |> c)? I suggest to APLize: same precedence, right-to-left associativity (a |> (b <| c), a <| (b |> c))

  • a problem for the parser team: how should the errors be reported?

AndersonTorres avatar Jun 06 '23 21:06 AndersonTorres

I nominate @maralorn, who has a lot of experience with functional programming languages and programming language design.

piegamesde avatar Jun 12 '23 09:06 piegamesde

@roberth, what about you, would you like to be a shepherd? I'd rather like to have critical voices on board from the beginning …

piegamesde avatar Jun 13 '23 09:06 piegamesde

I nominate @maralorn, who has a lot of experience with functional programming languages and programming language design.

I am pretty certain there are a lot of people with more experience on this in the wider community. That doesn’t prevent me from having opinions on this particular bikeshed, though. :rofl:

My availability depends on the timeframe here. I will be very busy in the next few weeks, after that I’d be on board.

maralorn avatar Jun 14 '23 10:06 maralorn

I've procrastinated writing this RFC for at least half a year, so waiting two more months won't be the end of the world

piegamesde avatar Jun 14 '23 11:06 piegamesde

would you like to be a shepherd?

I can do that

roberth avatar Jun 15 '23 15:06 roberth

I did a survey of some randomly sampled Nixpkgs files for this RFC here: https://github.com/NixOS/nixpkgs/pull/238579. I'll update the RFC with the results later on.

piegamesde avatar Jun 19 '23 13:06 piegamesde

I think we have one confirmed shepherd? @roberth. Looking for 2 more.

kevincox avatar Jun 28 '23 13:06 kevincox

@kevincox AFAICT two, so only one more

piegamesde avatar Jun 28 '23 13:06 piegamesde

We need one more shepherd, any takers?

edolstra avatar Jul 12 '23 14:07 edolstra

@edolstra I'd like to, but don't have much experience yet with the internals of Nix, especially the language evaluation itself, so uncertain if I'm qualified.

iFreilicht avatar Jul 16 '23 12:07 iFreilicht

@iFreilicht having a diversity of fields of expertise in the shepherd team is a good thing, so your participation would be welcomed and valuable for moving the RFC forward :)

lheckemann avatar Jul 26 '23 12:07 lheckemann

In that case, I hereby volunteer as a shepherd for this RFC.

iFreilicht avatar Jul 26 '23 22:07 iFreilicht

My availability depends on the timeframe here. I will be very busy in the next few weeks, after that I’d be on board.

@maralorn is your availability such that you can accept the nomination at this point?

tomberek avatar Aug 09 '23 13:08 tomberek

No, I am sorry, not yet.

maralorn avatar Aug 09 '23 22:08 maralorn

I see two shepherds @roberth and @iFreilicht. I believe we still need 1 more.

@piegamesde did I miss someone? I reviewed the comments again and can't find the second shepherd that you mentioned.

kevincox avatar Aug 23 '23 13:08 kevincox

having a diversity of fields of expertise in the shepherd team is a good thing

No expertise in language design is a good thing for this RFC specifically? Asking for a friend.

AndersonTorres avatar Aug 25 '23 03:08 AndersonTorres

@AndersonTorres It's very hard to find a charitable interpretation of your words. You might want to reconsider your reply.

ocharles avatar Aug 25 '23 10:08 ocharles

I'm talking in a literal way: knowing about programming language design is a pre-requisite?

AndersonTorres avatar Aug 25 '23 10:08 AndersonTorres

I do not think that domain knowledge is a requirement for becoming a shepherd, even though it generally is a good idea to have some within the shepherd team (which we do).

piegamesde avatar Aug 25 '23 21:08 piegamesde