343 points · by jashkenas · 11y ago · 221 comments
Some examples of strong mode changes we are aiming for are:
accessing missing properties throws, arrays cannot have holes,
all scoping errors are static, classes are immutable.
Specifically, "accessing missing properties throws" will undermine how developers use the language. Options objects require this as a feature. Immutable classes might also be an issue as language extensibility / monkey patching is another feature, enabling a whole swath of Aspect Oriented Programming solutions like New Relic's monitoring or the node.js async trycatch library.I do wonder though, in fighting for its life against native, whether JavaScript will need to adopt optimizing solutions like "strong mode" to strengthen where it's weak.
EDIT: It's really unfortunate that I'm getting down voted so severely (from +3 to -3 in <10m). HN increasingly discourages discussion and debate. I don't think there's any question that my comment adds to the conversation. At most, I could have added, "In my opinion..." to the beginning of my comment.
I couldn't agree more; there are many times I access a property that may or may not exist and I plan on using the undefined that comes with it not existing. Requiring it to exist is trying to turn JavaScript into a more strict language without all of the language features to do so very easily.
Guaranteeing that optional properties have a default value would be one solution, another would be to use ES6 default parameters instead of options objects. But there has to be some sort of value to use at runtime if missing property access always throws.
Object.assign(defaults, options)
The defaults object has all the necessary properties, no missing property access is necessary. Object.assign({}, defaults, options)
instead if `defaults` is an object shared across invocations of your function.)The same could have been said for strict mode.
Javascript littered with casts is nothing I want to see. I don't know about you.
function foo(x, options) {
var y = options.y | 0;
return x + y;
}
You can write: function foo(x, y = 0) {
console.log(x + y);
}
Problem solved!Options _Map_. There I fixed it.
To that effect, it seems like strong mode and SoundScript are a step in the wrong direction. I noticed the very deliberate and self-aware FAQ entry "Are you turning JavaScript into Java?" along with the canned denial, but that still doesn't change the fact that strong mode and SoundScript aim to remove dynamic typing and prototypes from a dynamically-typed prototypal language.
It's damning that you say it took 20 years for us to "start" to leverage JavaScript's power. Compare to C#, which appeared 15 years ago, or Go which is from 2009, or Swift, which hasn't even celebrated its first birthday yet.
Better comparisons might be Python and Ruby, which are both fully dynamic and have cool metaprogramming facilities like JavaScript does, but they'll both give you hard errors when you type the equivalent of [].lenght. And they give you proper stack traces and error messages, too: none of "undefined is not a function" which took until 2015 to get fixed in Chrome (try it). Working with Node.js will make you fall into despair when you realize that your program crashes, and it has stack traces, but none of the stack frames are in your code because everything has been threaded through callbacks. Python's major implementation has serious problems with concurrency (re: the GIL, global interpreter lock) and it too has dynamic types everywhere but it's still far easier to work with.
What I want is to be able to refactor a JavaScript project without feeling like I'm crossing the river Styx. Where are the call sites for this function... who knows? TypeScript seems to at least give me some of those tools, it's a shame that the tooling isn't really ready--the compiler takes ages to run (timed it at 2.0 seconds on a small project... I might as well be using C++ at those speeds).
And if Google has been using TypeScript as a basis, as they say, then you can keep using JavaScript the way you want and you don't even have to type anything in differently. Just let us add some type checking if we want it.
What's damning is the stagnation under the IE (convicted in the US) monopoly from late '90s through 2009 when ES5 was published. It's not as if Python 1.3 or whatever, if frozen in Netscape 2 amber, would have fared better if forked.
Disagree. Python 1.3 was at least designed as a general-purpose programming language, with a variety of use cases, and took the best parts of existing languages (TCL and Perl) rather than having novel features that sorta-but-not-quite replace more conventional ones. It had its share of warts but nothing in Python 1.3 is as awkward as prototypal inheritance or javascript's scoping.
IMO the biggest tragedy is Mozilla's unwillingness to put other languages in the browser. Dart was developed in public, far more of an open standard than the original JS, fixed language design problems that ES6 still isn't addressing, had an adequate approach to running in JS-only browsers, and would have added much less complexity to browser implementation (the reason given for rejection) than many standards that Mozilla has been happy to support.
It's especially a good sign that Google is using TypeScript as a basis because it means we might not get siloed implementations and communities.
I think it will happen since in September at the Python mailing list the Guido found a slew of bugs when using MyPy and started to advocate gradual typing.
If that's true, then Lisp is surely triply damned, as it's older than 60 and it's safe to say that most working programmers in the industry don't know how to leverage its power.
Or, since you brought up Ruby, the industry by and large didn't care about its existence for roughly the first decade of its life, though I suppose that's only half-damned.
One might reasonably conclude that what a language has to offer is only tenuously connected to whether a critical mass of industrial programmers knows how to work in it and take advantage of everything it has.
> Compare to C#, which appeared 15 years ago, or Go which is from 2009, or Swift, which hasn't even celebrated its first birthday yet.
Since a comparison has been invited:
- C# is an iteration of an iteration of an already industry accepted paradigm (and the first iteration's uptake is considerably more impressive).
- Go is more or less the same thing, except they took out a lot of industry accepted paradigms (and enough people are actually complaining loudly about some of the removed bits that I think Go's uptake is going to plateau more quickly).
- Swift is a super interesting case and maybe the best comparison to JS of all of these -- familiar syntax but with enough differences that are going to be unfamiliar that some developers would probably freak out and resist... if its only real competition weren't Objective C (so of course it's doing well :b) and its target market weren't already familiar with the underlying Cocoa libraries (which are almost 30 now).
- C# and Swift were both released by deeply entrenched market-bendingly powerful industry patrons who were decades old (this shoe nearly fits golang, too).
By contrast, JavaScript was released by a company barely a year old in an emerging market. A partner (another decades old entrenched player) of the neophyte company wanted the language nerfed and positioned as a toy, and got some of what it wanted. It was created very quickly. Within a year or two of release, tens of thousands of amateurs and professionals were doing something with it, most without having ever bothered to learn the specifics of the language at all. Within five years, thousands were actually doing reasonably complex applications with it. At about 10 years (right around the age Rails mania starts to hit the industry, right?) is when some significant portion of the industry starts to take notice that things like Google Maps can be built and (some) people start to consider that maybe if they actually took the time to learn the language and platform, they could do neat things too....
I'd say JavaScript fares pretty well by a number of standards for comparison.
Not to say it couldn't be improved; it is being improved. Better error messages and stack traces are great ideas, type hinting could work out too.
Yes. It's an awful language, beloved of those who've never had to maintain someone else's code.
> Or, since you brought up Ruby, the industry by and large didn't care about its existence for roughly the first decade of its life, though I suppose that's only half-damned.
Yes. Ruby is an uninteresting language. Rails was the kind of innovation in framework design that's so insightful that it now seems obvious and it's hard to remember that we would have thought differently, and by an accident of history it was in Ruby. Industry popularity turns out to track the really important innovations, who'd've thought?
> JavaScript was released by a company barely a year old in an emerging market. A partner (another decades old entrenched player) of the neophyte company wanted the language nerfed and positioned as a toy, and got some of what it wanted.
Javascript had the huge advantage of being required to effectively use the most popular application in history. The fair comparison is with something like Visual Basic during the rise of Word, except that most word documents never needed a single macro. Or perhaps to the things people make with Excel, even if it's not a "real" programming language. If Javascript were the perfect language handed down on tablets of stone, if it were Idris 20 years ahead of its time, it wouldn't have got much more adoption - and if it were the devil's own, MUMPS back from the dead, it wouldn't have got much less. The factors driving its adoption were simply unconnected to its strengths or weaknesses as a language, because there simply was no alternative for the overwhelming majority of Javascript use cases.
If you compare it to a grassroots contemporary, a language without the corporate sponsorship, how does it fare? Going by Wikipedia those look to be PHP, Ruby and OCaml. It's not clear-cut, but all of those feel more mature than JS to me.
It's a Turing-complete language. If you can do neat things in one Turing-complete language, you can do neat things in all of them. The only difference is how painful it is to do neat things in one Turing-complete language vs. another.
Just because it's Turing-complete doesn't mean it's a good example of a Turing-complete language.
https://brendaneich.com/2007/11/my-media-ajax-keynote/
/be
"It seems to me that a lot of you "bring on our new overlords" boosters are unaware of how HTML5 came about. It was not through one vendor shipping proprietary code and standards bodies mopping up later. Study some recent history."
You convinced me 1274 days ago.
/be
But seriously, that article is insanely ahead of its time. Or we're progressing reeeaaally slowly. Or both.
Q: "Are you turning Javascript into Java?" A: "No, it's optional"
That's not a strong denial, I was hoping for a more substantial response.
Having actual integers? Threads? Better tooling?
The `class` keyword? It makes the code less verbose.
Optional types? Would you rather write JSDoc comments?
Optional typing actually works amazingly well. You need very few type annotations to get all the tooling benefits. Typically, it's enough to annotate the headers of your function. Type inference takes care of the rest.
Regarding #1:
The optional part wasn't Perl6-style optional typing (which I'd be fine with), as I read it, but USING their system at all.
If I teach how to juggle chainsaws, and someone says "isn't that dangerous?" and I respond "No, you don't have to do it", I've not addressed the question at all.
Regarding #2:
For me, it'd be threads (a simple system that is almost never painless), classes (JS today has objects but not classes, and it's a fundamental part of how it works), compilation, and most importantly typing. "Session session = Session.getSession()" is not something I enjoy typing.
It's also a good gesture that they'll try to work with others to standardize. SPDY -> http/2 is great example of this!
I disagree with 'Accessing missing properties' and a few others. I don't want Javascript turned into Java.
Also sounds a bit like a hammer looking for nails, i.e. they've already optimized everything, so to optimize more they'll need to rewrite the language. Again, I think some ideas are good, but may be slightly misdirected.
This worries me. If it's running "correctly", then sure, it will run elsewhere. But if it hits something that Strong Mode considers "incorrect", then things diverge, and other browsers will execute something different.
This can be avoided if Strong Mode just issues warnings, not errors. Which seems sufficient, if the goal is to inform people about stuff they should optimize.
For those that want more rigorous checking, browsers could add a developer mode, in which those warnings become errors. This way, there is no risk of production code working differently on different browsers.
We have seen "use strict" cause errors in production. Avoiding that with "use strong" seems like a safer path, with no significant downsides that I can see.
"use strict" is used in production all the time. Google and Facebook use it. The Babel transpiler (formerly 6to5) adds it to your code by default.
It's one thing to get JS programmers to write their code in a certain way, but if the VM knows they are doing so, it's even more powerful.
I guess the question is, how much better can you do, over easy-to-optimize code. Or in other words, once something is valid in Strong Mode, how much do extra Strong Mode optimizations get you.
Such code should already be quite fast in current JS engines. The big, big difference is between the engine getting hard-to-optimize vs easy-to-optimize code. So I would bet that the bigger deal is the devtool aspect here. But, these are empirical questions.
We lint, unit-test and acceptance-test aggressively (including legacy browsers), and the strict directive itself is of course scoped to our own IIFE. Perhaps that explains why I've not witnessed the hurt you mention.
The mechanics of strict mode are very clearly defined too, so I've not seen any cases were developer confusion caused unwanted side-effect (although I have heard straw-man arguments made where people predict it would).
The benefits, on the other hand, are real and tangible. Errors that might otherwise be difficult to diagnose fail hard and obviously. Browsers are better able to optimise strict code than non-strict. And culturally, I suspect that a use-strict policy has forced everyone to be more clinical in their approach.
Hand on heart, I would never go back to deploying non-strict code, so would be really interested to hear from anyone else in the opposite camp.
> I found two opinions about using strict mode in production:
> > There is no reason to ship “use strict” in your production code. There is no performance gain (verified with V8 team and Brendan a while ago) and I don’t need my users’ VMs doing the extra checks as well. Keep it development only, strip it out during build. This way you also avoid the concatenation issue you reference.
> And:
> > There may not be a performance gain, but there’s also not a performance loss. In production, even more than in development, is where you want to be sure you’re noticing errors. Minimizing the changes between the development and production versions of the code is key to being able to debug issues quickly and efficiently. Yes it helps during development, but there’s no reason to pull it out of production code.
> The source is in the comments at the bottom [1]
> And of course those 12b weight of "use strict" won't change a thing.
[0] http://stackoverflow.com/a/10986793/1072106
[1] http://www.nczonline.net/blog/2012/03/13/its-time-to-start-u...
There have also been breakage issues. "use strict" changes semantics. Before all browsers implemented "use strict", some had it and some didn't, which meant scripts with "use strict" ran differently in different browsers.
This issue bit Amazon in the ass a while back and gave rise to JSHint checking for function-level strict mode declarations only and the general rule-of-thumb to not use strict mode in production code.
Not changing JS semantics would avoid this. All the developer benefits are still possible without semantic changes.
It's kind of like protocols: be strict in what you send out but lenient in what you accept. be strict in the javascript you write but then lenient when your users are actually running it.
Similar problems could easily arise in JS with e-commerce type applications, failing is sometimes a good thing.
A more particular criticism. How does forcing let statements on everyone improve performance?
All it does is force implicit (rather than explicit) scoping rules on JS developers because devs from other languages don't seem to be able to understand functional scoping or hoisting. It's a huge case of X language isn't like Y language that I already know, so let's change the unfamiliar language.
I imagine that let and const afford optimizations to the VM.
Sure other ES6 browsers will ignore the string and move on, but they will have other ES6 compatibility issues. For example, Chrome's "fat arrow" doesn't do the lexical bind to the parent scope that the current spec requires. There are a ton of situations where this would break your code if you ran it on FF (and there are other differences).
The only option is to transpile into ES5.1, but ES5.1 breaks the optimization requirements.
Thus, using the optimization flag means building to Google's JS engine (we've been there with IE), while building a shared version means you cannot use the flag.
Let adds scopes. Scopes are bad for performance (this is why closure compiler removes them). Removing them (if safe) is one more thing for the JIT to do. It's has little to do with efficiency and a lot to do with forcing another language's preferences on users.
And that's why fat arrows are currently not enabled in Chrome. Chrome exposes in development features behind flags. IMO vastly better than the vendor prefixes of ages past.
What I do find annoying is the constant rebranding the teams in Google tries to do to TypeScript. Angular team called TypeScript + runtime typechecking a "AtScript". Now this document calls something of similar a "SoundScript".
Can't the Google just admit it's using TypeScript? Adding a runtime checking doesn't change the fact it's just a TypeScript.
What makes you think they haven't "admitted" it yet?
> AtScript is TypeScript: We’ve been collaborating with the TypeScript team on our proposed productivity [1]
They have been collaborating with Microsoft, and it's no secret[2]
1. http://angularjs.blogspot.com/2015/03/announcements-from-ng-...
2. http://blogs.msdn.com/b/typescript/archive/2015/03/05/angula...
As a little note about your references:
1. was posted 23 hours ago. 2. six days ago.
I'm actually not checking their plans daily.
1. Google implements this 2. Chrome becomes the fastest browser by a wide margin 3. Other browsers die or become minor players 4. Google leverages this to enforce their own changes into the HTML/Javascript domain, "for the better" of the web and maybe even into mobile. 5. Web is broken unless you use Chrome
The pain developers suffered before dealing with IE4-6 will be nothing to the repercussions we face now if we have to continue being backwards compatible with some version of Chrome because website X is "Chrome only" in the future.
Hell it's already happened a bit with the new HTML5 features. Hell Korea is still paying for the mistakes of committing to go with IE.
Feel like it ends up being Google's version of EEE.
Also, keep in mind, this "SoundScript", even if its in the early stages, has not been declared as being open source, so it is closed source at the moment. This makes me feel that at best SoundScript will be open source like Android is open source. Release stuff but keep the latest version for Google to use.
Er, you just made up five steps, none of which have happened yet, and then conclude that they sound like "Google's version of EEE". That's what happens when you make up a "Google's version of EEE" scenario" :)
It's a proposed ES7+ addition being implemented behind a runtime flag. Can you be specific about what that has to do with Korean banking laws and destruction of the competitive browser landscape?
I lived there for a few years and worked with Macs. I was completely unable to access my bank account online. Even when I could log in on a Windows desktop, there's an extremely overly-complicated (and quite manual) certificate system also required.
But again, the concern is that Google is going to go ahead with this even before any approval. So when every single javascript related product from Google is already using it, what's preventing Google from just shrugging and going "oh well" and just continuing on with their modifications?
What is V8 for if not for Chrome (since V8 is not beholden to node/iojs)?
1: http://blog.chromium.org/2015/02/hello-http2-goodbye-spdy-ht...
1. Google announces New Great Way 2. Google implements 3. Early adopters jump on 4. Improvements are promised. 5. Languish 6. Google moves on
Not universally true (NaCl and GWT followed this, SPDY didn't), but frequent enough that people aren't yet cautious.
Why do people want an open web? Because if you allow one entity to gain too much influence, you become locked into their whims rather than what is best for the web.
- V8 (and Chrome, via Chromium) is an open source project: https://github.com/v8/v8-git-mirror . Try doing a search for 'use strong' in the V8 source and you will find that the code for this proposal is already open source, not "closed source at the moment".
- Chrome is nowhere near the kind of market dominance that IE once enjoyed (> 90%), and there is no rational prospect of it ever reaching it, unless you believe Windows, OS X and iOS are about to disappear. Thus they will never enjoy the monopoly necessary to unilaterally introduce proprietary features.
- Chrome auto-updates. In fact, it was the first mainstream browser to adopt this "evergreen" model (since adopted by Firefox and IE). This means that there are no concerns about maintaining backwards compatibility with "some version" of Chrome.
- IE has fixed versions, IE 6, 7, 8, 9, 10, 11; Chrome autoupdates so there's only Chrome stable, Chrome beta, Chrome dev and Chrome canary.
No need to hardcode IE6-specific hacks.
- IE is closed source; Chrome is more open source.
I still see old versions of Chrome in my access logs fairly regularly. Don't kid yourself that everyone updates all the time.
> - IE is closed source; Chrome is more open source.
Chrome is not F/OSS, Chromium is.
On mobile, there are all sorts of old Chrome versions being shipped by various Android vendors and not getting updated at all.
[Citation Needed]
As I understand it ES6 is meant to be backwards compatible with ES5.
CS classes won't make use of the new "class" syntax, but they should be compatible ES6 classes (they can subclass each other) because they're both really just sugar on top of JavaScript's prototypal inheritance.
That's ok if the latter two (and other such languages) can change to track ES6, as MS promises TS will.
Just one example from CS: the difference between for/of meanings.
http://www.lemonde.fr/pixels/visuel/2015/03/06/google-memori...
http://channel9.msdn.com/Shows/Going+Deep/Anders-Hejlsberg-a...
At one point, Lars and Anders both say they liked ES4 and they wondered why it died. I LOLed a lot :-|, in view of how their employers were intimately involved in killing ES4.
(I write this without rancor, as ES4 needed to die.)
Why is that by the way? From what I read at the time in the PDFs it seemed nice and not out of the ordinary. Did you ever wrote about technical failures of ES4 and I missed it?
— jhnns
Apparently Chrome feels the same about ES6 .. they continue playing launch pad chicken (only 39% on Kangax)
With perl, which has similar characteristics we decided to seal classes only from the main application, with "use oo :final", and modules, libraries, implementations of classes do not seal their classes. Thus you can easily allow duck-typing in the calling application for testing, or go fast and disallow adding or changing methods and properties.
So you cannot pre-compile modules per se, but js has no static block compiler anyway.
Asm.js isn't a solution for JavaScript developers, it provides an efficient compilation target for porting C/C++ code-bases to JS by leveraging Emscriptem or Mandreel compilers.
But this doesn't benefit the 99+% of websites running normal JavaScript. Whereas the goal of StrongMode is to carve out a safer and faster "subset" of JavaScript that's less error prone and easier to optimize with more predictable performance.
Only SoundScript is proposing adding (TypeScript-compatible) optional typing that's built into V8. ES6 is source compatible with TypeScript which can be transpiled to strip its type annotations so it runs in ES5 JS VMs. Essentially this is an evolutionary enhancement to JS.
That still wont be used by 99%+ of the websites out there.
At least not unless they want to forgo standards, or forgo strict-mode in all browsers but Chrome, and last but not least: they will have to update the code which is already there, and IE6 told us how that works in practice.
Let's not help Google forge the internet a new MSIE with Chrome.
"Q: How does SoundScript compare to asm.js? A: They have different goals: asm.js is a low-level language designed to be a compilation target for other (mostly low-level) languages. SoundScript is a user-facing type system for direct use of JavaScript as a high-level language. Both are complementary, both are useful, and V8 is committed to both."
I think Google (as usual) is getting ahead of this problem. But they shouldn't be alone in the fight for clarity.
They're starting with TypeScript which was Hejlsberg's project at Microsoft. Microsoft wants people to develop web apps for Microsoft server platforms, and you can use TypeScript with intellisense in Visual Studio. We'll see if Microsoft puts it in the browser but it seems like they already have a stake in the success, at least.
* Why is `delete` such a problem? * Closed objects (under "Dynamic Restrictions") seem like a really heavy change from current common JS usage. You basically can't use objects as a hash. This would break a ton of code. ES6 Weak Maps seem like an odd replacement. Especially because they are weak, that's semantically totally different than an object. * Not being able to add properties to Arrays I assume will cause quite a bit of problem, as that pattern is common. Or maybe subclassing Array will work fine? * Under Functions they seem to be disallowing traditional class definitions, so you can only use ES6 classes. So you can't write ES5 that is also StrongScript :( * Under Classes, it sounds like you can't call methods of this? I guess this is so you can't call methods on an object that is not entirely initialized. This will break a lot of code, or at least most classes I've written. I'd rather see all the possible instance attributes get pre-filled with undefined. * Both this proposal and ES6 seem to dislike non-method properties on prototypes. Why? * Disallowing `for in` is also annoying.
I like the concept, but I'm not excited by the proposal.
Granted, it won't speed up DOM operations much, but JS is being used in so many non-browser places... it's good to know that the language performance isn't stuck against a wall.
The web (as in HTML + JS) has always been about backward "interpretability" (meaning, a new feature won't break existing clients). The incompatibility of "var" and "strong mode" seems to be the most important break in this concept since JavaScript 1.1 and the introduction of the Array-constructor. (Some may remember the days, when we had to write two scripts, one for Netscape 2 and newer, and another one for older clients, each defining the same functions and producing comparable results. – Most of this was owed to features related to DOM-interaction. – Alas, the language-attribute ...)
Realistically, not everyone will have a fully updated (or even fairly current) browser, and this really shouldn't be an issue which necessarily breaks things. "strong mode" will thus limit access to only those clients with at least some support of ES6 (as in "let").
Please add some basic support of "var"!
Essentially I am saying expose a layer even closer to the metal in the browser so that these optimization problems can be moved to front end development.
https://news.ycombinator.com/item?id=5707088
Apart from syntax wins, you can't get much lower-level semantically and keep both safety and linear-time verifiability. Java bytecode with unrestricted goto and type confusion at join points makes for O(n^4) verification complexity. asm.js type checking is linear.
New and more concise syntax may come, but it's not a priority (gzip helps a lot), and doing it early makes two problem-kids to feed (JS as source language; new syntax for asm.js), which not only costs more but can make for divergence and can overconstrain either child. (This bit Java, pretty badly.)
/be
Why extend javascript instead of treating it as VM for anything you like?
Transpiling to javascript is a hack to make up for percieved deficiencies in the language itself - but as with any other language, javascript can still be improved upon and evolve.
Requiring that anyone who wants to write javascript for the web do so through a Java or C compiler is actually the worst option.
Compiling a more rigid language to JS doesn't help with this, because the runtime and JIT compiler has no way to know what the original constraints were, so it has to remain open to the possibility that this is plain old JS and any of those weird and unoptimisable -- but legal! -- constructs may occur.
Of course, you can write runtimes and JIT compilers with optimistic fast paths, that assume certain constraints apply and bail out to slower paths if they encounter something they can't handle. But this only gets you so far. It adds a lot of complexity to your implementation, and provides no clue to developers that they've violated a particular constraint and their code is running 10x slower than it could do. Furthermore, different runtime implementations from different vendors may have different heuristics and fast path behaviours.
Having a standardised subset of the language, marked by a backwards compatible pseudo-pragma (like 'use strong') lets developers opt in to explicit constraints that enable greater optimisation. These constraints are common across different runtimes, properly documented, and are enforced by fail-early checking. The latter gives clear feedback to developers when they violate a constraint, and means the fast-path code can work without escape hatches, because the code it's running is guaranteed not to violate the constraints.
Google is capable on working on improving JS and Dart simultaneously. You can see Dart as a test ground for features that may make it to JS. Cross-browser improvements made to JS will also benefit the Dart ecosystem, as it is a compile to JS platform.
Don't expect Dart to disappear any time soon. Despite popular rhetoric, Google actually has a good history of supporting its web programming platforms, for example GWT and Closure.
Mmm... yes please.
/be
BUT: please provide a way to construct classes dynamically (or allow functions to have [[construct]]).
I thought that
"It guarantees that (1) an expression that has a static type T can never evaluate to a value that is not a T, and that (2) evaluation cannot run into unexpected runtime type errors."
is already supported in TypeScript.
class Base {}
class Derived1 extends Base {}
class Derived2 extends Base {}
class Box<T> {
constructor(public value: T) {}
};
var a: Derived1 = new Derived1();
var b: Box<Base> = new Box<Base>(a);
var c: Box<Derived2> = b;
var d: Derived2 = c.value; var s : String = "bar";
var a : any = s;
var i : int = a;
Not sure, but I think Typescript's assignability rules, which use structural typing, also introduce unsoundness. class A { foo() { print('A'); } }
class B { foo() { print('B'); } }
var a : A = new A();
var b : B = a;I don't think I would use the type system. Maybe it should have its own proposal instead of being "bundled up" with sane mode. At least it is optional.
Doubling the testing load, making hidden time bombs for older browsers to find blowing up in their faces at later dates: Not Good.
Elsewhere here, both Alon Zakai I question the wisdom of using an erased "use sanity"; mode directive, given that runtime semantics will diverge for any code not in the new subset. The hope is that people will test fully with checks on, and find all code that doesn't follow the rules. I think TC39 will balk at this hope. Murphy was an optimist.
/be
> The hope with sane mode (or whatever less able-ist name it should have) is to have no runtime semantic change if the mode directive is not recognized
From my limited understanding, old browsers can't handle 'let' anyway, which is supposed to be used exclusively on this mode (as there will be no 'var'). But you probably know more about this than me.
> making hidden time bombs for older browsers to find blowing up in their faces at later dates: Not Good.
Doesn't that happen all the time? What I mean is: If ES6 becomes widely supported in browsers, pages written on it will make old browsers "blow up", too. Unless the people who program those make two versions, which defeats the point of using ES6 in the first place. The same when a new version of CSS comes out - use that, and the old browsers "blow up", too.
It seems to me it is the nature of the beast - new features make old browsers blow up.
> Doesn't that happen all the time?
You're talking about new syntax bombing old browsers. That's not the issue. The issue is same syntax in old and new, works (for whatever value of "works") in old and new, but differs in meaning due to a "use sanity"; directive.
Update: this does not say 0 == "" of course, separate issue.
/be
This "testbed" could be good or bad, time will tell.
"let is the new var". No it's fucking not! "let" promotes procedural block scoped code. Moves people away from thinking properly about flow in their code. "var" has it's places, "let" can be a good addition is SOME circumstances. And calling code with "var" in it as insane, is itself insane.
/be
I personally don't like some of the ES6 additions, but this one is just a step too far. For us mere mortals that is.
/be