Reshaping the Extensions proposal

While I agree both proposals share a common goal—writing chainable code—I think they don't necessarily address it at the same level.

The pipeline operator is mostly useful to the end-developer who needs to chain functions from multiple libraries. I find it very versatile but difficult to read.

The extension functions are great for library maintainers to export functions that can extend existing objects. They are very similar to classic functions and are easy to read/understand.

Also, the pipeline proposal seems a bit stuck ATM, but I'm not sure this is a good argument.

I'm a bit sad to admit it, but yes, a new syntax might be required.

To TC39 delegates: If I alter the proposal to include a new syntax, could it get a chance to be championed and proposed to a future TC39 meeting?

1 Like

Like @aclaymore mentioned, welcome to the forum.

I myself don’t have the bandwidth to champion this proposal. But I can give a prediction that, for better or worse, all syntax proposals (except perhaps already-close proposals such as those related to import attributes) are unlikely to reach Stage 3 or 4 within the next few years.

As you may know, new syntaxes are generally much more complicated and costly to specify, implement, and perpetually maintain by the engines.

As a co-champion of the pipe operator and the bind-this operator proposals, I can say from experience that syntax proposals generally face a very high barrier to entry. It’s been more difficult than ever for even simple syntaxes to be added to the language. You may find the update I wrote for the pipe operator last spring relevant to this issue.

In fact, new syntaxes that do not add any behaviors that had been previously unimplementable by developers—that is, new convenience syntaxes—ironically may face increased scrutiny. This is because some members of the Committee perceive such convenience syntaxes as less beneficial for a still-high cost, compared to syntaxes that do bring new behaviors.

Even if this situation is unfortunate, I think it’s also understandable how conservative the Committee’s consensus, particularly from the engines, is toward adding new syntax.

That is also probably one of the reasons why @hax has left his extensions proposal alone for the past few years. There’s been other proposals for him to focus on, ones that are more likely to be accepted by the engines.

I apologize for being pessimistic. I think your proposal is interesting—but I also think it’s good to be realistic about the prospects of any new syntax proposals in the near future. That’s why I’ve been lately focusing more on new function-only APIs myself. I wish you luck with finding a champion.

3 Likes

Thank you very much @jschoi for taking the time to explain the situation. In fact, I did already read your update for the pipe operator and—naively—thought that my proposal isn't bringing any new syntax because it doesn't need any new operator… But I was wrong, it still requires to update how we parse the language.

To all other TC39 delegates, I'm still open to work on this proposal despite the pessimistic predictions.

3 Likes

Do you think this situation could be helped if the rationale for a proposal were more anchored to the end-user benefits? From what I can tell, most of the motivation for the pipeline and call-this proposals is framed as ā€œmake clunky code more readableā€ but it’s not immediately obvious why that benefits end-users.

Here is my basic line of thinking:

  1. Dead code is a big problem slowing down the web (Gemini claims 30-70% of JS on the web is dead code).
  2. prototype-based functions are particularly hard to tree-shake, resulting in more dead code.
  3. prototype-based functions are also very popular because of how convenient they are for devs to define (class syntax) and invoke (method call, method-chaining, etc).
  4. To get people to write more tree-shakable code, we need to offer a tree-shakable option that is as convenient as method-chaining. Then, developers will be willing to use that instead.
  5. More tree-shaking == faster, lighter web == happier end users.

I’m sure there are holes and many details or other rationale I could fill out, but the main point is that ā€œdeveloper convenienceā€ in this context is really just a means to the end of a faster user-experience for everyone.

2 Likes