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

Toss the nested block param idea #43

Open
theScottyJam opened this issue Mar 5, 2022 · 0 comments
Open

Toss the nested block param idea #43

theScottyJam opened this issue Mar 5, 2022 · 0 comments

Comments

@theScottyJam
Copy link

The whole :: idea is intriguing, but in the end, it really doesn't provide much value to the language, nor is it an essential part of the core concept of being able to pass blocks as arguments into functions.

The reason why it doesn't provide much value is because it's trivial to make an API that doesn't rely on it. Let me just pull some examples from the README, and show how I can build a very similar looking thing without the :: syntax:

/* map */

// before
let a = map {
  ::put("hello", "world") {}
  ::put("foo", "bar") {}
}

// after
let a = map($ => [
  $.put("hello", "world"),
  $.put("foo", "bar"),
])


/* custom data */

// before
let data = survey("TC39 Meeting Schedule") {
  ::question("Where should we host the European meeting?") {
    ::option("Paris")
    ::option("Barcelona")
    ::option("London")
  }
}

// after
let data = survey("TC39 Meeting Schedule", $ => [
  $.question("Where should we host the European meeting?", $ => [
    $.option("Paris"),
    $.option("Barcelona"),
    $.option("London"),
  ]),
])


/* kotlin's templates */

// before
let body = html {
  ::head {
    ::title("Hello World!") {}
  }
  ::body {
    ::div {
      ::span("Welcome to my Blog!") {}
    }
    for (page of ["contact", "guestbook"]) {
      ::a({href: `${page}.html`}) { span(`${page}`) } {}
    }
  }
}

// after
let body = html($ => [
  $.head($ => [
    $.title("Hello World!")
  ]),
  $.body($ => [
    $.div($ => [
      $.span("Welcome to my Blog!")
    ]),
    ...["contact", "guestbook"].map(page => (
      $.a({href: `${page}.html`}, $ => [$.span(`${page}`)])
    )),
  ]),
])

// Alternative that's more imperative and closer to the "before" example
let body = html($ => {
  $.head($ => {
    $.title("Hello World!")
  })
  $.body($ => {
    $.div($ => {
      $.span("Welcome to my Blog!")
    })
    for (page of ["contact", "guestbook"]) {
      $.a({href: `${page}.html`}, $ => $.span(`${page}`)}
    }
  })
})

Notice how similar the "before" and "after" are? You may disagree here, but I actually prefer the "after" versions. The "before" examples are imperative in nature (because they're built on blocks), and make the API user describe their desired piece of data by building it through a series of discrete steps. The "after" versions are declarative in nature, and simply showcase the desired data in it's entirety, with the help of some pure functions.

Anyways, the point is, I think it's hard to make a case for the "::" syntax and ask for it to pass the high syntax bar that EcmaScript has, when it's pretty trivial (and even arguably better/easier) to just build your APIs without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant