Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler Syntax #288

Closed
no-gravity opened this issue Jan 21, 2023 · 11 comments
Closed

Simpler Syntax #288

no-gravity opened this issue Jan 21, 2023 · 11 comments

Comments

@no-gravity
Copy link

So in the current proposal, this:

a = d(c(b,7))

Becomes this:

a = b|>c(%,7)|>d(%)

I would very much prefer a simpler syntax. Example:

a = b,7~>c~>d

Any insurmountable hindrances towards a simple syntax like b,7~>c~>d?

@ljharb
Copy link
Member

ljharb commented Jan 21, 2023

Why is that simpler? That also seems more akin to F# syntax, which was rejected in favor of Hack (specifically, assuming that a value is a function)

@no-gravity
Copy link
Author

It is simpler because it avoids nesting and needs less meta characters.

As the proposal notes, nesting makes reading harder.

@OleksiiKachan
Copy link

in my opinion |> is better than ~> because
1 - | is literally called pipe. hence "pipeline operator"
2 - visually when scanning code ~ and > blend together you may confuse it with bitwise NOT
there are many other reasons why other variants were rejected, you can refer readme or closed issues
I agree that proposed syntax is not the simplest but after all this is something completely new in this language. we all gonna feel awkward using it until we are used to. maybe later all we all will figure out something better (like we did for async/await syntax for promises)

@mAAdhaTTah
Copy link
Collaborator

Besides the fact that the location of the 7 argument seems "misplaced" visually (the arguments occur before the function call), it's also not clear how you would translate this:

a = b|>c(%,7)|>d(%, 8)

Or this

a = b|>c(%,7)|>d(8, %)

to your version.

@tabatkins
Copy link
Collaborator

Yup, the core idea here is just F#-style again. See #221 for why that was rejected by the committee and is not being pursued.

It is simpler because it avoids nesting

The only nesting in your examples is in the original non-pipelined code, where calls are nested inside each other. The pipeline'd version just has functions being called - that's not nesting.

@no-gravity
Copy link
Author

Besides the fact that the location of the 7 argument seems "misplaced" visually (the arguments occur before the function call),

That is the point of pipes, isn't it?

it's also not clear how you would translate this:

a = b|>c(%,7)|>d(%, 8)

It would become: a = b,7 ~> c,8 ~> d

Or this

a = b|>c(%,7)|>d(8, %)

That is: a = b,7 ~> 8,c ~> d

@mAAdhaTTah
Copy link
Collaborator

That is the point of pipes, isn't it?

No, the point is to linearize nested code.

@no-gravity
Copy link
Author

That is the point of pipes, isn't it?

No, the point is to linearize nested code.

That is what I mean.

Nested:

a = b|>c(%,7)|>d(%)

Linearized:

a = b,7~>c~>d

@ljharb
Copy link
Member

ljharb commented Jan 21, 2023

That’s not nested, though - it’s linear.

@no-gravity
Copy link
Author

How so? Because % and 7 are not function calls? We can "fix" that by replacing 7 with e().

Current proposal:

a = b|>c(%,e())|>d(%)

My proposal:

a = b,e()~>c~>d

The issue with the current proposal is that it tries to avoid nesting, support multiple input parameters and use pipes that only carry a single value. And therefore must fail in at least one aspect. It fails in regards to nesting.

@ljharb
Copy link
Member

ljharb commented Jan 22, 2023

Because any sensible codebase would pad |> with newlines or spaces, and because you only have one pipeline, in both examples.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants