I very much like knowing where a local variable stops being relevant. Often I'll do things like
const bar = f();
const baz = g();
foo = h(bar, baz);
to contain intermediate variables in a lexical scope (TypeScript is trashy that I have to define `foo` outside the braces—Julia etc. blocks can return).
I wish syntax or editors helped even more in showing when a variable stops mattering. It might be one of those small ergonomic things that add up to much more.
@22 this might just be because it's a trivial example, but I'd generally write a "block that returns" as a function in TS. Then, `foo` could even be a `const`, depending.
@afontaine do you think I’m being too silly and pre-optimizing by not wanting an IIFE for perf reasons? It also seems so much ceremony just to hide a few temporary variables from subsequent code 😕? I’d worry my kouhai would see such code and be more alarmed and wary, wondering what dread cause moved me to write something like that, and they’ll be peeved it was nothing more than containing intermediate variable.
But that is of course a solution.
I think there might be a couple good options depending on complexity...
If you don't need to check `bar` or `baz` for errors, etc. inlining here might not be the worst? It can be spaced out in a way that is still _mostly_ readable
const foo = `h(f(), g())`
but at the same time, if you suddenly need to check `bar` and/or `baz` and sanitize values? then your function is hiding temporary variables _and_ error checking logic, which I think is definitely a win
Server run by the main developers of the project It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!