Skip to content

Argument against this proposal #39

@xixixao

Description

@xixixao

I am trying to revive pipeline proposal and have it get going with Hack-style only version. See tc39/proposal-pipeline-operator#167 (comment)

I'd like to add for your consideration why I think we should not be moving forward with this proposal - not any of its particular variants, but in general (if we decide to move forward with any Hack-style pipeline supporting proposal). This expands on the point 5 in the comment linked above.

What are Pipelines?

First, let me explain the point of the pipeline operator: It allows you to skip naming things. Every pipeline can be rewritten:

return foo |> bar(#) |> baz(#);

like this:

const someVeryGoodName = bar(foo);
return bar(someVeryGoodName);

Now if that's the case, you might be wondering what's my gripe with this proposal. What's the difference, isn't this proposal also allowing you to skip naming things?

It is! But with one major, major difference.

In the case of the pipeline, you can see what you're not naming.

I can see foo and bar(#) in the example above, so I have some idea of what bar(foo) is.

A more realistic example from Hack:

return $test_users_not_sorted
  |> Vec\unique_by($$, $test_user ==> $test_user['user']['id'])
  |> Vec\sort_by($$, $test_user ==> $test_user['user']['name']);

It doesn't help this code to add variables unique_test_users_not_sorted and unique_test_users_sorted. I can see what's going on just as well from the pipeline code.

Partial Application

Now let's look at this proposal:

const fooBar = foo(1, ?);

What is ?? I have no idea. I'll have to inspect foo to find out, or fooBar needs to be superbly named. What's the alternative? Functions!

const fooBar = n => foo(1, n)

Even a super undescriptive name like n gives me more information (the argument is probably a number).

More examples directly from readme:

const log = console.log({ toString() { return `[${new Date()}]` } }, ?);

I have no idea what the second arg is intended to do.

button.addEventListener("click", this.onClick(?));

I have no idea what is being passed to onClick (if I pretend I don't know what addEventListener does - but even knowing it took me a second to wrap my head around this). Now I try to remember what coding was like when I got started, and I really would not want to be learning from such code (or wishing it upon anyone else).

There are other arguments against this proposal, like its weirdly restricted nature to only some forms of expressions (why not others? we could argue for years).

Just like in the discussion on pipelines I will advise: Swallow the bullet and add those 5 characters. If you're not writing an entirely throw-away code you will want to have a good name for that argument. This proposal is way too complicated for the little benefit of saving those 5 characters in the few special cases it applies.

In summary, this proposal got started to support pipelines, pipelines don't need it if we go with Hack-style only, and in that case we should drop this proposal.

cc @codehag @ducaale @aadamsx who are advocating the other direction in #36

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions