Live data from Hacker News

Working pipe operator today in pure JavaScript

github.com

51–60 of 109 posts

Re: Working pipe operator today in pure JavaScript

#51
post #20
post #8

Further proof that JavaScript accidentally became the new C++. “Aren’t you surprised that this syntax works?” is not praise for a language design.

Agreed!!!! Serious q: but how does this sentiment change with LLMs? They can pickup new syntax pretty fast, then use fewer tokens...

IMO it's more likely to get confused because there are less unique tokens to differentiate between syntax (e.x. pipe when we want bitwise-or or vice-versa)

Re: Working pipe operator today in pure JavaScript

#52
post #48
post #8

Further proof that JavaScript accidentally became the new C++. “Aren’t you surprised that this syntax works?” is not praise for a language design.

Is there a language that can’t be contorted in surprising ways that I’m unaware of?

Probably not, but there are definitely languages that don't do automatic type coercion - so at least one fewer contortion available.

Re: Working pipe operator today in pure JavaScript

#53
post #42

Earlier quoted context omitted.

Are any of the cases compelling? Thinking of the actual proposal. It creates some new magic with |> and % just for syntactic sugar.

I am all for clean syntax but I feel like JS has already reached a nice middle ground between expressiveness (especially w/ map/reduce/filter) and readability. I'd personally rather not have another syntax that everyone will have to learn unless we're already moving to a new language.

I think JS's map/reduce/filter design is one of the worst ones out there actually - map has footguns with its extra arguments and everything gets converted to an array at the drop of a hat. Still, pipeline syntax probably won't help fix any of that.

Re: Working pipe operator today in pure JavaScript

#54
post #48
post #8

Further proof that JavaScript accidentally became the new C++. “Aren’t you surprised that this syntax works?” is not praise for a language design.

Is there a language that can’t be contorted in surprising ways that I’m unaware of?

LISP — the contortions are expected, not surprises

Re: Working pipe operator today in pure JavaScript

#55
post #48
post #8

Further proof that JavaScript accidentally became the new C++. “Aren’t you surprised that this syntax works?” is not praise for a language design.

Is there a language that can’t be contorted in surprising ways that I’m unaware of?

A language where there's only one way to do things, maybe a very early version of CSS. The things is all languages end up bloated with new features.

Re: Working pipe operator today in pure JavaScript

#56

If you're interested in the Ruby language too, check out this PoC gem for an "operator-less" syntax for pipe operations using regular blocks/expressions like every other Ruby DSL. https://github.com/lendinghome/pipe_operator#-pipe_operator "https://api.github.com/repos/ruby/ruby".pipe do URI.parse Net::HTTP.get JSON.parse.fetch("stargazers_count") yield_self { |n| "Ruby has #{n} stars" } Kernel.puts end #=> Ruby has…

It's an interesting experiment but standard Ruby is expressive enough.

[9, 64].map { Math.sqrt(_1) } #=> [3.0, 8.0]

For the first example I would just define a method that uses local variables. They're local so it's not polluting context.

Re: Working pipe operator today in pure JavaScript

#57
post #10

First example doesn't work though: const greeting = pipe('hello') | upper | ex('!!!') await greeting.run() // → "HELLO!!!" If you look at the tests file, it needs to be written like this to make it work: let greeting; (greeting = pipe('hello')) | upper | ex('!!!'); await greeting.run(); Which is not anymore as ergonomic.

Seems similar to the problem encountered when making the stupid idea PyNQ:

https://github.com/IAmStoxe/PyNQ

Re: Working pipe operator today in pure JavaScript

#58
post #10

First example doesn't work though: const greeting = pipe('hello') | upper | ex('!!!') await greeting.run() // → "HELLO!!!" If you look at the tests file, it needs to be written like this to make it work: let greeting; (greeting = pipe('hello')) | upper | ex('!!!'); await greeting.run(); Which is not anymore as ergonomic.

I suspect this was written with an LLM and the author didn't actually verify that the examples in the README worked.

Re: Working pipe operator today in pure JavaScript

#59
post #8

Further proof that JavaScript accidentally became the new C++. “Aren’t you surprised that this syntax works?” is not praise for a language design.

It is not a surprise that overriding the implementation of an operator’s type coercion works and overrides the behavior of the operator’s type coercion.

Re: Working pipe operator today in pure JavaScript

#60

This kind of stuff is why C++ developers has an almost overly allergic reaction to operator overloading.

This isn’t overloading the operator, it is replacing the implementation of type coercion when | is used with pipe() or asPipe() objects.

| itself still works exactly as before.

Post reply on HN