Indeed, `let`s and `const`s incur a significant performance penalty. This is also why the Scala.js compiler emits `var`s by default, even when targeting very recent versions of ECMAScript. The good news is that we can still write our Scala `val`s and `var`s (`const` and `let`) in the source code, enjoying good scoping and good performance.
The Temporal Dead Zone, or why the TypeScript codebase is full of var statements
51–60 of 64 posts
Re: The Temporal Dead Zone, or why the TypeScript codebase is full of var statements
#52The first example is not “terrible”, that’s just how lexical scope works. I don’t really see the point of complaining about language features like this - either learn how it works or ignore at your peril.
That's not how lexical scope works anywhere but in JavaScript. Or rather, it's the interaction between "normal" lexical scope and hoisting. In a "normal" lexically scoped language, if you tried: function f() { return x; // Syntax parsing fails here. } let x = 4; return f(); you would get the equivalent of a ReferenceError for x when f() tried to use it (well, refer to it) at the commented line. But in JavaScript, thi…
function f() {
return g()
}
function g() {
return f()
}Re: The Temporal Dead Zone, or why the TypeScript codebase is full of var statements
#53 local x = 42
do
print(x) -- 42
local x = x * 2
print(x) -- 84
end
print(x) -- 42
Look, ma! No dead zones!Re: The Temporal Dead Zone, or why the TypeScript codebase is full of var statements
#54The first example is not “terrible”, that’s just how lexical scope works. I don’t really see the point of complaining about language features like this - either learn how it works or ignore at your peril.
That's not how lexical scope works anywhere but in JavaScript. Or rather, it's the interaction between "normal" lexical scope and hoisting. In a "normal" lexically scoped language, if you tried: function f() { return x; // Syntax parsing fails here. } let x = 4; return f(); you would get the equivalent of a ReferenceError for x when f() tried to use it (well, refer to it) at the commented line. But in JavaScript, thi…
I wish there was explicit support for this though, maybe with a construct like where , etc, like what Haskell has, instead of having to hack it using functions and var
Re: The Temporal Dead Zone, or why the TypeScript codebase is full of var statements
#55Earlier quoted context omitted.
That's not how lexical scope works anywhere but in JavaScript. Or rather, it's the interaction between "normal" lexical scope and hoisting. In a "normal" lexically scoped language, if you tried: function f() { return x; // Syntax parsing fails here. } let x = 4; return f(); you would get the equivalent of a ReferenceError for x when f() tried to use it (well, refer to it) at the commented line. But in JavaScript, thi…
Would mutual recursion still work with this solution? E.g. function f() { return g() } function g() { return f() }
local b
local function a()
return b()
end
b = function()
return a()
end
(Lua's named function statements are just syntatic sugar. For example `local function a()` is equivalent to `local a; a = function()`.)Re: The Temporal Dead Zone, or why the TypeScript codebase is full of var statements
#56Earlier quoted context omitted.
I second that, I actually don't understand why do people believe every pair of curly braces has to be its own separate scope. An explicit construct for scoping would have been so much clearer to me.
> I actually don't understand why do people believe every pair of curly braces has to be its own separate scope. It’s much easier to reason about when your variables aren’t going to escape past the end of the block. In non-GC languages going out of scope can also be a trigger to free the contents of the variable. This is useful for situations like locking where you can put the minimal span of code that requires the l…
function readfile(name)
local f = assert(io.open(name))
return assert(f:read"a")
endRe: The Temporal Dead Zone, or why the TypeScript codebase is full of var statements
#57Earlier quoted context omitted.
By crux you mean the 1 paragraph at the end where it mentions performance? That's basically a footnote to an article that spends the other 99% describing javascript variable hoisting. They cite an 8% performance boost but they don't analyze it, instead just claiming it is a lot of work for the interpreter and linking to a github issue. They've run no benchmarks. They have shown no interpreter internals. They just rep…
Yes it turns out the article’s conclusion is in fact contained in the conclusion paragraph
Re: The Temporal Dead Zone, or why the TypeScript codebase is full of var statements
#58Re: The Temporal Dead Zone, or why the TypeScript codebase is full of var statements
#59Why wouldn't `let` be exactly what you want? It's block scoped but doesn't need fancy TDZ checks because like `var` it just starts out as undefined.
Consider
console.log(foo)
let foo
vs console.log(foo)
var foo
I think the article confuses "in scope" with "declared", and "declared and initialised" with "initialised".Re: The Temporal Dead Zone, or why the TypeScript codebase is full of var statements
#60Earlier quoted context omitted.
I wonder how many companies are still using Scala.js. Scala was fun to work with, wish it was more popular these days.
Usage of Scala.js is steadily growing. Several indicators suggest that 1 in 5 Scala developers use Scala.js at this point. It's regularly brought up as one of the strongest suits of Scala. Usage of Scala itself is less shiny if you look at market share. But I believe it's still growing in absolute numbers, only quite slowly.
Wow! 4 out of 20 total ain't bad!
Jocking aside the starting set (Scala developers) is already small, so it's not like either it or even less Scala.js is going to be a major player anytime soon.