8 points · by alcover · 5y ago · 39 comments
With strong typing JS++ would eliminate many runtime bugs. Without all the crazy implicit conversions, boxing, 'eval', etc... fantastic speeds could be achieved.
Lots of electricity and developper hair could be saved.
JS++ would break backward compatibility but this could be softened by retaining the old syntax as largely as possible. With implicit and explicit typing.
It should be easy/automated to convert js to js++.
Inb4 ActionScript 3 : yes, something like that.
If you've ever written typescript, you can see how a strongly typed JS gives you the worst of both worlds.
Typescript adds static typing to JS, but it’s still weakly typed. This post is about strong typing in JS, which I’m still scratching my head about.
const o = {}; o.prop = "something"; // oh, actually, o.prop = 5;
and being able to do if( typeof o.prop === 'number' ) ...
Strong typing usually describes the combination of compile and runtime typing; Haskell code doesn't have types after compilation, so there is no runtime enforcement of typing, but no one calls it weakly-typed, because the static typing prevents any of the conditions which would display weak typing behavior fromm happening.
I'm no type theorist and - per wikipedia - 'strong' is not precisely defined.
'Static' may be closer to my idea : a JS where `typeof` and Number.isInteger are of no use.
Actually, no. I genuinely think Typescript is amazing and I would love if there was native support one day.
Not in the browser.. Nor in the app/server.
See what I mean ?
JS matters most client-side anyway.
WebAssembly as a target is a thing, so, yes, C is available there.
> Nor in the app/server.
How is C not available on the backend?
Because I -and everyone- need a faster, less energy-wasting JS.
> Are type errors the most common source of errors in JS?
They happen. And could be caught at compile-time under a stronger type system.
JS is used client-side in many banking/crypto webapps. I know everything is validated on the server but still presentation is done by JS with its nutty casts/coercions...
There are a good number of programming languages. Why not something like Go? I heard Go compiles to JS, but never tried it. Why is JS even used for banking, and why would converting to a JS++ be easier than adopting something else?
It may be possible to keep duck typing for objects while introducing fast unambiguous primitives like int64_t ?
> Why not something like Go?
Because JS syntax is very nice - that's my premise. Moreover, client side has to be JS, no other choice yet.
That makes JIT a complicated business, for you still have to accept any value. So two versions of the func would have to coexist ? One strong and one weak ? I'm no JS/JIT expert..
It is like I thought : holding different optimisation versions of the same code... that is overly complicated in my (naive) view.
Want to accept muck? Leave it as is. Want to accept something specific? Specify the class to accept, or even specify the shape if you want to go the duck typing route.
If you are going to break from JS semantics by using strong typing rather than JS’s mostly-very-weak typing, I don't see what the point is of making code deceptively look like JS.