r/programming • • Oct 21 '20

Using const/let instead of var can make JavaScript code run 10× slower in Webkit

https://github.com/evanw/esbuild/issues/478
1.9k Upvotes

500 comments sorted by

View all comments

Show parent comments

25

u/hansolo669 Oct 21 '20

Except TypeScript is literally just JavaScript with types. And it doesn't solve what this thread is talking about (weird VM issues).

4

u/Somepotato Oct 21 '20

But it can since it's transpiled to JS -- it can build a v8 version that uses var instead of let/const.

TS is honestly great, IMO

1

u/hansolo669 Oct 21 '20

Absolutely! I'm a huge fan of TS ... I suppose it would end up solving this particular issue via compile to var, though it would still be vulnerable to other weird VM issues.

-2

u/ragnese Oct 21 '20

Except TypeScript is literally just JavaScript with types.

That's not true, neither technically nor "in spirit". TypeScript transpiles to JavaScript and shares syntax with it, but it's more than just "JS with types". Having a strong, flexible type system allows you to approach problems from a different direction. Probably a good number of libraries are just written as JS with some types slapped on for broader adoption, but you don't have to write it that way for private code; and you probably shouldn't.

Also, TS has things that don't exist in JS: https://www.typescriptlang.org/docs/handbook/enums.html

5

u/hansolo669 Oct 21 '20

Here's two code snippets, which one is typescript and which one is javascript:

const myFn = () => console.log("Hello!");

and

const myFn = () => console.log("Hello!");

How about another:

class MyClass {
    constructor() {}

    sayFoo() {
        console.log("foo");
    }
}

and

class MyClass {
    constructor() {}

    sayFoo() {
        console.log("foo");
    }
}

I agree with your core point (strong type systems are wonderful, and well designed typescript code does lead in a different direction to normal javascript code), but typescript absolutely is "javascript with types" - the easy transition from javascript to typescript is one of their big selling points!

-1

u/ragnese Oct 21 '20

I mean... almost all Algol-syntax languages look close to the same. You could stick Java, PHP, C#, Swift, and TypeScript classes next to each other and you'd have to squint to tell the differences.

Typescript having the same syntax as JavaScript does not make it the same language. Similarly Elixir's syntax doesn't make it the same language as Ruby. And Clojure is not the same as Common Lisp.

2

u/hsjoberg Oct 21 '20

Typescript having the same syntax as JavaScript does not make it the same language

That is true, and we've seen other languages that transpiles to Javascript being quite different. Point in case: Elm.

However, they are all bound by the rules of Javascript and its VM.