RE: Classes as Sugar (was: Renaming ECMAScript 4 for the final standard?)
Pardon the top post, Brandon already seemed to dig into this proposal with his typical surgical deftness. I just couldn't resist relating some Flash history. As the saying goes, been there, done that. Here's the abridged version of ActionScript's history: AS1 ~= ES3 AS2 == ES3 + classes as pure compiler sugar AS3 == proto ES4 with classes as first class citizens Flash is a couple years ahead of the web in terms of dealing with application complexity. If you imagine that the web browser just gave you a Canvas class and JavaScript you'd have a workable approximation of Flash, we have no HTML declarative backbone, its the wild west of scripting. We introduced classes into AS 8 years or so ago in an attempt to deal with the insuitability of ES to these growing applications. As soon as we introduced classes users clamored for coherent large UI libraries to make their lives easier but any attempt to build a large coherent library brought the VM to its knees. So Flash developers got by with smaller less useful purpose built frameworks. A lot of the problems stemmed from having classes as syntatic sugar. Weird edge cases permeated the system, inheritance, class initialization order, proper statics, and getting overriding working well were issues. But performance and memory usage were the kickers. We know this because we tried multiple times to build the big honking frameworks in AS2 folks wanted and they ran like poo eating memory and CPU voraciously. So we got wise and built classes into the language as first class citizens with well defined semantics and a compiler/file format that piped all that juicy RTTI to the runtime which sported an optimizing JIT. Then we built an even bigger honking framework and now it all sings: http://livedocs.adobe.com/flex/2/langref/ Or look at the Android docs, probably similiar in scope/scale. The bits about piping juicy RTTI to the vm probably apply too. My point is that we needed classes to build these rigid, well defined frameworks that all applications and 3rd party libraries could build on instead of everyone starting with Canvas and all that static information sure doesn't hurt when it comes to performance (can I say that much Brendan? ;-) The reality is that there's a world of developers out there waiting to build sophisticated web applications but they are limited by the adhoc frameworks at their disposal. The script kiddies would go nuts if they could build full fledged applications in web pages with just a veneer of scripting code on top of a proper UI framework. A least the Flash script kiddies have. Built it and they will come. I'm not saying AS3 is the be all end all, maybe we drank the Java cool aid a little too much and its great to see ES4 taking its time to get it right (righter?) by being more dynamic/pythonic. The geek in me would love to see classes that could be sliced and diced and julienned (reflected/generated/extended) at runtime like the classes as sugar way would avail but that's not always a good thing. A damn good Singularity [1] paper I read recently made some assertions that dynamic loading makes tricky/impossible proving some type system stability/correctness theorems and I can buy that. A better point is what the geeks want isn't what's necessary good for the rest of the world. Sometimes loosey goosey is good, in large frameworks (and certainly OSes) not so much. We think that one language can serve both ends. Flex 3 was just released and we say without a doubt that the programming in the large structures in AS3 have done amazing things in scaling the complexity of applications our developers have built. We're building full fledged word processors (buzzword), image editting applications (photoshop express) and even working on viable video editting [2]. The tiny hyper dynamic ninja ES3 ain't gonna fit the bill, somethings gotta give, the web wants heavy artillery (or all the heavy lifting will be left to Silverlight and Flash, oh and I suppose I should say Java, its probably still ahead of Silverlight in some respects). With AS3 we're seeing people build applications with complexity rivaling or surpassing that of the player itself. That never could have happened with AS2 and it won't happen in the browser with ES3. To come at it from another angle we envision ES4 as playing a similar role at Adobe as python has at Google. Ie something like only write the super critical bits in C/C++ and glue it all together with a higher level dynamic scripting language. Only we're probably drinking the cool aid too much again and see very little need for C/C++ (or at least new C/C++). Anyways sorry for the rambling but we have some new arrivals and I haven't ranted in awhile. Hopefully this background on how the Adobe folks got here helps somehow. EcmaScript is about more than just the web. [1] http://www.research.microsoft.com/os/singularity/publications/OSR2007_RethinkingSoftwareStack.pdf [2]
Re: Classes as Sugar (was: Renaming ECMAScript 4 for the final standard?)
On Mar 24, 2008, at 11:21 PM, Thomas Reilly wrote: ... and all that static information sure doesn't hurt when it comes to performance (can I say that much Brendan? ;-) If you've got it, use it -- no point in dropping type information during a source to bytecode or other transformation. Just don't expect the web to type-annotate the way Flash authors did (with some grumbling) based on the carrot of speed that you guys dangled. Sometimes loosey goosey is good, in large frameworks (and certainly OSes) not so much. We think that one language can serve both ends. I'm pretty sure Mark wants to avoid loose geese too, but he has reached different conclusions. My goal is to work from conclusions backward to premises such as ES4 is statically typed and try to identify the reason for that kind of statement. This may not succeed. As Graydon once observed, a lot depends on mood of the language. People see static type checkers (even optional ones, as optional as JSLint) and type annotations (also optional), and the 'class' keyword (which is used in dynamic languages too), and suddenly it's a statically typed language and therefore b-a-d. The charge Matthias leveled about intentional loopholes (ES4's * type, which is the default annotation) meaning errors can (as is usual in ES3 today) originate from anywhere in a large system and mess over your hybrid or partially typed code is pretty much on target. But we are trying not to do Contract or TypeScheme research, and we are definitely not imposing a static type system (not even within new modules -- and defining a module is turning out to be quite hard in JS on the web). Contrary to all the claims alleging that we are doing those bad things. If ES4 users want to lock a module down in a static-typing sense, they can annotate all API entry points with non-like types (wrap would allow untyped client code to pass plain old objects and arrays, at a price). Further self-imposed BD programming inside the module is optional in my view. This is the best that I believe we can do for ES4. It beats purely dynamic typing for any non-trivially-small codebase. I wish I had the option to code in this language when writing Narcissus. /be ___ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss
RE: Classes as Sugar (was: Renaming ECMAScript 4 for the final standard?)
If ES4 users want to lock a module down in a static-typing sense, they can annotate all API entry points with non-like types (wrap would allow untyped client code to pass plain old objects and arrays, at a price). Further self-imposed BD programming inside the module is optional in my view. This is the best that I believe we can do for ES4. It beats purely dynamic typing for any non-trivially-small codebase. I wish I had the option to code in this language when writing Narcissus. And I think that's good enough. Flex has a strict mode where you get a warning if you don't statically type things. Typically I turn it off when prototying around and turn it back on if I'm implementing anything others have to use. I never really stopped to think why this is. Is it as simple as facilitating code sharing and declarative input validation or is there more to it? I suspect it might be that simple. One thing that occurs to me is that classes facilitate wrapping up code into a compiled form and sharing it as a fixed closed entity. Not sure that will ever apply to browsers but its a very common idiom in Flex (and Java/C/C++...). Here static typing is just facilitating creating code boundaries I guess. Boundaries are definitely a good thing when trying to coordinate the efforts of many. But then I see things like this: http://ptrthomas.wordpress.com/2006/06/06/java-call-stack-from-http-upto-jdbc-as-a-picture/ Its kinda awe-inspiring to look at but part of me wonders if maybe there's a better way (and wow, the JVM must have an unbounded stack)? Maybe with ES4 all the boxes are there with similiarly defined boundaries but the meat inside the boxes is leaner/clever dynamic code. How's that for an ES4 pitch, like Java but with leaner meat ;-) Taste great, less filling. -Original Message- From: Brendan Eich [mailto:[EMAIL PROTECTED] Sent: Tue 3/25/2008 12:19 AM To: Thomas Reilly Cc: Mark S. Miller; Dave Herman; es4-discuss@mozilla.org Subject: Re: Classes as Sugar (was: Renaming ECMAScript 4 for the final standard?) On Mar 24, 2008, at 11:21 PM, Thomas Reilly wrote: ... and all that static information sure doesn't hurt when it comes to performance (can I say that much Brendan? ;-) If you've got it, use it -- no point in dropping type information during a source to bytecode or other transformation. Just don't expect the web to type-annotate the way Flash authors did (with some grumbling) based on the carrot of speed that you guys dangled. Sometimes loosey goosey is good, in large frameworks (and certainly OSes) not so much. We think that one language can serve both ends. I'm pretty sure Mark wants to avoid loose geese too, but he has reached different conclusions. My goal is to work from conclusions backward to premises such as ES4 is statically typed and try to identify the reason for that kind of statement. This may not succeed. As Graydon once observed, a lot depends on mood of the language. People see static type checkers (even optional ones, as optional as JSLint) and type annotations (also optional), and the 'class' keyword (which is used in dynamic languages too), and suddenly it's a statically typed language and therefore b-a-d. The charge Matthias leveled about intentional loopholes (ES4's * type, which is the default annotation) meaning errors can (as is usual in ES3 today) originate from anywhere in a large system and mess over your hybrid or partially typed code is pretty much on target. But we are trying not to do Contract or TypeScheme research, and we are definitely not imposing a static type system (not even within new modules -- and defining a module is turning out to be quite hard in JS on the web). Contrary to all the claims alleging that we are doing those bad things. If ES4 users want to lock a module down in a static-typing sense, they can annotate all API entry points with non-like types (wrap would allow untyped client code to pass plain old objects and arrays, at a price). Further self-imposed BD programming inside the module is optional in my view. This is the best that I believe we can do for ES4. It beats purely dynamic typing for any non-trivially-small codebase. I wish I had the option to code in this language when writing Narcissus. /be ___ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss
Classes as Sugar (was: Renaming ECMAScript 4 for the final standard?)
On Sun, Mar 23, 2008 at 11:28 PM, Brendan Eich [EMAIL PROTECTED] wrote: ES4 is not statically typed, so... ... this is a false dilemma. These analogies are weak and tendentious in my opinion. Let's try to get back to premises and argue forward. Can we start with why you seem to believe that ES4 is statically typed? The language design I accused of being statically typed is the language design currently called proposed ES4. Of course, one of the things at stake is whether ES4 will be statically typed. As I've made clear, I hope not. Now on to your real question. Why do I seem to believe that proposed ES4 is statically typed? A fair question. Proposed ES4 lies somewhere between the simple categories of statically typed and dynamically typed. However, rather than finding a happy compromise between the two, it mostly combines the worst of these two worlds. It pays most of the costs of static typing but obtains few of the benefits. And it inherits all the costs of having been dynamically typed, but retains few of the benefits. Benefits of Static Typing * static assurance that type mismatch errors will not happen at runtime * runtime space savings * runtime time savings * type-based IDE refactoring support (as in IDEA and Eclipse) Costs of Static Typing * language complexity * limit expressiveness to statically checkable type predicates. :int, but no :prime * two expression languages - static type expressions vs dynamic value expressions * multiple partial type theories: nominal, structural, duck, ... * verbosity (inside Google, we've expanded to a 100 column limit for Java generics) * inappropriate for casual scripting audience Benefits of Dynamic Typing * lambda abstraction / objects is all you need * Tennent correspondence http://gafter.blogspot.com/2006/08/tennents-correspondence-principle-and.html * all abstractions first-class, composable * simple meta-interpreters can enable powerful meta-programming * syntactic simplicity supports other metatools: minifiers, lints, ... * rapid prototyping Costs of Dynamic Typing * runtime space and time costs * less static knowledge of dynamic behavior Benefits of Soft / Gradual Typing Proposed ES4 and some dynamic languages share some of the advantages of soft typing systems. A soft typing system is, essentially, a dynamic typing system with a convenient syntax for declaring type checks that should be checked at runtime. * Better documentation of expected interfaces - better project coordination * Fail-fast runtime behavior * easy transition from rapid prototypes to production Benefit of Soft Types absent from Proposed ES4 gradual types: * type predicates are any runtime test expressible in the language A comprehensive treatment of all these points would need a book. Here, I will illustrate with a small example as my belated response to Dave Herman. I wrote: If instead classes, for example, were defined purely by syntactic expansion to the constructs in ES3.1, then classes would inherit the lexical nestability of the constructs they expand into. On Tue, Mar 11, 2008 at 5:49 AM, Dave Herman [EMAIL PROTECTED] wrote: Nestability is a good design goal, and I'm glad you brought it up. [...] That said, you've hinted at alternative approaches, perhaps with constructs desugaring to closures of some sort To get discussion going, I will here present a first cut at a desugaring of something like proposed ES4's class syntax and type declarations into ES3.1 constructs. Were ES4 to be redefined in terms of such syntactic sugar, then the desugared semantics could be precisely ES3.1's would thereby preserve most of ES3.1's virtues. The example below demonstrates the value of preserving ES3.1's lexical nestability and first-classness. Browsers would only need to initially implement ES3.1, and the expansion of ES4 to ES3.1 could happen initially offline or on the server. Classes as Sugar Given something like the __createProperty__ operation we've been discussing lately, and that Lars has made progress on specifying, we could imagine generalizing it to also constrain properties to be non-overridable (as in proposed ES4 final) and protected (addessable only by way of this.). We could also imagine an operation constraining an object to be non-extensible (i.e., fixture). For purposes of this note, I will make up a plausible static API for these. Were the proposed ES4 class syntax defined in terms of the obvious expansion to ES3.1 + calls to these functions, the first class definition in the proposed ES4 overview doc class C { var val; var large = Infinity; const x = 3.14; function f(n) { return n+val*2; } } would expand to function C() { Object.__createProperty__(this, 'val', undefined, Readable | Settable); Object.__createProperty__(this, 'large', Infinity, Readable | Settable); Object.__createProperty__(this, 'x', 3.14, Readable);