Remix.run Logo
nadinengland 3 days ago

I love that this is part of the syntax.

I typically use closures to do this in other languages, but the syntax is always so cumbersome. You get the "dog balls" that Douglas Crockford always called them:

``` const config = (() => { const raw_data = ...

  ...

  return compiled;
})()'

const result = config.whatever;

// carry on

return result; ```

Really wish block were expressions in more languages.

dwattttt 2 days ago | parent | next [-]

By the by, code blocks on here are denoted by two leading spaces on each line

  like
  this
notpushkin 2 days ago | parent | prev | next [-]

Interesting that you can use blocks in JS:

  {
    const x = 5;
    x + 5
  }
  // => 10
  x
  // => undefined
But I don’t see a way to get the result out of it. As soon as you try to use it in an expression, it will treat it as an object and fail to parse.
charleszw 3 days ago | parent | prev | next [-]

Yes, I constantly use this pattern in C++/JavaScript, although I haven't tested how performant it is in the former (what does the compiler even do with such an expression?)

paavohtl 2 days ago | parent [-]

At least in simple cases the compiler will just inline the closure, as if it never existed. There shouldn't be any measurable overhead.

pwdisswordfishy 2 days ago | parent | prev [-]

https://github.com/tc39/proposal-do-expressions

(Not to be confused with do notation)