Readit News logoReadit News
charleszw commented on Rust's Block Pattern   notgull.net/block-pattern... · Posted by u/zdw
nadinengland · 10 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.

charleszw · 10 days ago
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?)

u/charleszw

KarmaCake day1December 11, 2024View Original