samuelgoto / proposal-block-params

A syntactical simplification in JS to enable DSLs
205 stars 8 forks source link

Advantage over existing callback syntax is unclear #19

Closed not-an-aardvark closed 6 years ago

not-an-aardvark commented 6 years ago

The readme says that under this proposal, code like this:

a("hello") {
  /* ... */
}

is desugared to code like this:

a("hello", function() {
  /* ... */
});

Aside from saving a few characters, is there an advantage to using a block param over using a callback function? I'm confused about how block params would "enable DSLs" if they're just a less verbose way to do something which is already possible. For example, it seems like lock demo in the readme would already be possible by using something like this:

lock(resource, () => {
  resource.kill();
});
samuelgoto commented 6 years ago

It enables custom control structures that resemble syntactically built-in ones.

https://github.com/samuelgoto/proposal-block-params/tree/8b33d26659b5f4ac33c3202e41045b27966ec2d7#cs-foreach

Or kotlin-style DSLs like the following:

https://github.com/samuelgoto/proposal-block-params/tree/8b33d26659b5f4ac33c3202e41045b27966ec2d7#kotlins-templates

Which are substantially different (visually) from callbacks.

Does that sound like a reasonable distinction?

On Wed, Nov 15, 2017 at 4:12 PM, Teddy Katz notifications@github.com wrote:

The readme says that under this proposal, code like this:

a("hello") { / ... / }

is desugared to code like this:

a("hello", function() { / ... / });

Aside from saving a few characters, is there an advantage to using a block param over using a callback function? I'm confused about how block params would "enable DSLs" if they're just a less verbose way to do something which is already possible. For example, it seems like lock https://github.com/samuelgoto/proposal-block-params/tree/8b33d26659b5f4ac33c3202e41045b27966ec2d7#lock demo in the readme would already be possible by using something like this:

lock(resource, () => { resource.kill(); });

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/samuelgoto/proposal-block-params/issues/19, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqV6j6OxU-iHjCLM1wE9as_WvXZ-RArks5s2331gaJpZM4QfxXu .

-- f u cn rd ths u cn b a gd prgmr !

not-an-aardvark commented 6 years ago

That makes sense, thanks for clarifying.