proposal-pipeline-operator: Breaks C function call semantics
I’m gonna say it. The pipe operator obj |> func breaks the semantic style of javascript being a C-like language.
I’m not saying it’s bad, but it turns a C-like language semantically and syntactically into something pretty darn different. You call functions with (...args) You access object properties with obj.property. It’s shared amongst all C-like languages. This is familiar to developers coming from Java, C, C++, even Python, etc etc.
All of a sudden now you have a syntax that changes the semantic behavior of function calls into two distinct styles completely different – the func(...args) way and the obj |> func way. It’s quite transparent for some, but quite obscure for others.
I don’t disagree with adding it into the language, but I don’t agree either. It seems to bring only a small short-hand syntax for something that can be implemented with a simple function definition or set of function definitions. ( #131 )
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 15 (2 by maintainers)
The “looking like C” ship sailed a long time ago. Most of modern JS’s language features don’t look like C at all.
And that’s fine! Most developers learning to write code today are starting with a more modern language than C.
“Looking like other C-inspired languages” would make more sense as a priority to me than “looking like C” (though I wouldn’t be a huge fan of that priority either).
I’d like to advocate for Chrant’s idea. A function could simply do the job of this new operator. I’d imagine it would be quite confusing if we have a separate operator for iterating / mapping / folding collection instead of the nowadays standard
forEachmapreduce.This will be wayyy easier to adapt too. A change in operator (aka new syntactic rule) would mean lots of effort from transpilers (babel, ts, or even others that transpile kotlin, go, etc to JS). Plus all the cost in training etc.
It’s great that there is a C-like language that has something similar for the familiarity factor. You don’t want, after all, to introduce some syntax as opposed to something else, just because you can. That’s good. Familiarity isn’t everything, but it definitely eases barrier to adoption and hopefully the clarity of best-practices.
Hack is C-like and implements a pipeline operator as well, although its version requires a placeholder.