proposal-pipeline-operator icon indicating copy to clipboard operation
proposal-pipeline-operator copied to clipboard

Placeholder name, eg %name

Open pie6k opened this issue 2 years ago • 9 comments

I wanted to propose adding an optional placeholder name to the syntax and ask you what do you think about it?

Example:

const fileName = "file.txt";

fileName
  |> addServerPath(%) // `/path/to/server/file.txt`
  |> convertToUrl(%filePath) // `http://server.com/path/to/file.txt`
  |> await fetchFile(%fileUrl) // some node file object
  |> await saveFile(%fileHandler, "downloads")

As seen, in the pipe steps we add the name of the placeholder. It is optional and has 0 impact on how this code works, but makes it easier to read, as we can add the information 'what is the placeholder at this step' so the reader of the code doesn't have to guess it from function names.

pie6k avatar Aug 02 '22 06:08 pie6k

Don't comments work for that purpose? I often use them to document what each parameter is when calling a function, regardless of pipes.

const fileName = "file.txt";

fileName
  |> addServerPath(%) // `/path/to/server/file.txt`
  |> convertToUrl(/* filePath */ %) // `http://server.com/path/to/file.txt`
  |> await fetchFile(/* fileUrl */ %) // some node file object
  |> await saveFile(/* fileHandler */ %, "downloads")

nicolo-ribaudo avatar Aug 03 '22 06:08 nicolo-ribaudo

Of course this can be addressed with comments, but placeholder could be a nice "baked in" way to do that.

A bit similar to why we give variables good names if possible before writing a comment.

pie6k avatar Aug 04 '22 16:08 pie6k

This probably was discussed in #91.

VitorLuizC avatar Aug 04 '22 17:08 VitorLuizC

A bit similar to why we give variables good names if possible before writing a comment.

If you have good function names, you may not need to give variables names at all.

aloisdg avatar Aug 05 '22 07:08 aloisdg

A bit similar to why we give variables good names if possible before writing a comment.

If you have good function names, you may not need to give variables names at all.

True, but also quite subjective. What do you feel is the reason against placeholder names? In the end you don't have to use them if you don't want to

pie6k avatar Aug 06 '22 20:08 pie6k

I don't have any reason against placeholder name, because I don't oppose it. It may not be needed but I would say that it is not a bad thing either.

aloisdg avatar Aug 07 '22 17:08 aloisdg

This probably was discussed in #91.

Also in #203, with the OPs example here.

shuckster avatar Aug 18 '22 08:08 shuckster

Isn't avoiding giving the name 90% of the choice to use |> though? This would make parsing harder (and I assume slower), and would be one more thing to teach. I have a feeling like a simple comment is more useful here, even a "normal" one at the end of the line, like you'd do it now when chaining things like map and filter.

Also, IDEs are very likely to give an inline hint for the argument name right after % anyway, so it will pretty much look exactly like OP's example in practice.

lazarljubenovic avatar Jun 15 '23 21:06 lazarljubenovic