On Mar 28, 2011, at 1:53 PM, Dmitry A. Soshnikov wrote:
> 
> Exactly. "Classes" are not about just the "class" keyword, but about the 
> _ability to classify_, i.e. to program in classified (i.e. with 
> object-patterned programming). JS supports (and supported all these years 
> both approaches: delegation-based prototypal (i.e. unclassified or chaotic 
> code reuse) and classical (classified or systematized code reuse).

To quote the title of a famous paper by William Cook: "Inheritance Is Not 
Subtyping".  This is commonly misquoted as "Subclassing is not Subtyping".

> 
> Thus, a "class" in JS is a pair of "constructor function + prototype". From 
> this viewpoint, e.g. classes in Python (or CoffeeScript) are just syntactic 
> sugar of the same delegation-based inheritance used in JS. And this means 
> that JS also may have this sugar -- to allow users to program in classified 
> manner (if they need to). So there's no a big difference between these 
> languages and therefore keyword `extends` may fit absolutely normally.

And quoting the definition of class in Smalltalk-80: The Langauge and Its 
Implementation: "class:  A description of a group of similar objects".  I would 
emphasize the word "description" in the Smalltalk-80 definition.  In dynamic 
object oriented languages, a class consists of the description of the common 
implementation of a set of identically implemented objects. Part of that common 
implementation may be obtained via inheritance. But obtaining parts of an 
object's implementation via inheritance (subclassing) is not the same as 
subtyping.

Subtyping implies a substitutive relationship. If B is a subtype of A, then in 
general you can expect to be able to substitute B in any situation where A is 
expected.  Static object oriented languages in the style of  C++, Java, and C# 
fairly strongly equate subclassing with subtyping.  What you can say in a class 
definition is constrained by the rules of subtyping. Dynamic object-oriented 
languages such as Smalltalk, Ruby, and Python do not equate subclassing and 
subtyping.  In such languages, B being a subclass of A means that B shares some 
of it implementation with A but it does not mean that B can always be 
substituted for A

One of the rules of object subtyping is that additional  methods may be added 
by a subtype but methods may not be deleted.  Thus in a subclassing==subtyping 
language it is easy to think about subclasses as generally "extending" 
superclasses with additional members.  The use of "extends" in Java is no doubt 
a reflection of that perspective.

It is fairly straight forwards to augment JavaScript with the concept of 
"class" as a syntactic unit that describes the shared description of the 
implementation shared by a group of objects. It would also be straight forward 
to including the concept of implementation "subclassing" in the 
Smalltalk/Ruby/Python style.  It would be very difficult to introduce the 
concept of classes as nominal types with subclassing into the JavaScript.

Using "extends" to mean "subclass of" may be familiar to Java programers, but 
it may also be misleading.

> 
> Here how I see classes syntactic in JS (a combination of Coffee's sugar + 
> Java's syntax, since we can't eliminate it).
> 
> Notes:
> 
> I think that usage of thing like: class method fromString() { .. } are to 
> verbose.
> Don't think we need another keyword `method` at all.
> 
> Also I used a syntactic sugar for `this` keyword as `@`. This `at` allows 
> easily to define and distinguish class- and instance- methods. The rule is 
> simple: if a property/method inside the class body starts with @ -- it's the 
> class's property/method (i.e. `this` refers to class). In other case -- it's 
> an instance method. @ evaluated inside the instance method refers of course 
> to the instance.

this second usage of replacing this with @ seems like a separable piece and the 
same familiarity argument that might be made for using "extends" would argue 
against replacing "this" with "@".


> 
> ,,,
> 

Allen
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to