> Almost: a primitive is something that isn’t handled by reference.
>
> Is that from the spec? My interpretation of "primitive" is from ISO/IEC 11404
> (a surprisingly good read for a spec about types!): primitive datatypes are
> "defined axiomatically without reference to other datatypes" and goes on to
> say "All primitive datatypes are conceptually atomic". XSD similarly defines
> primitives: "Primitive datatypes are those that are not defined in terms of
> other datatypes; they exist ab initio."
>
> What you're defining as primitive is instead the notion of value types, but
> it's all kind of jumbled together anyway. To my mind the notion of value vs.
> reference types are completely orthagonal, and instead closely related to
> mutability. Still, I agree I was wrong to call Objects primitive -- Object
> instances are still derived, or generated, or compound, or product, or
> whatever (AFAICT the literature is all over the map on this).
Every language defines "primitive" different, you thus have to be careful with
transferring these concepts. The spec elegantly avoids the issue by simply
enumerating which types are primitive.
The best you can do, then, is to describe how primitives work. Possibly like
this:
Primitives are immutable value types. Any properties they have, they get from
their object wrapper types. I think strings get their "length" property this
way, too – I think it is often implemented as a getter that accesses an
internal property that strings have.
> But your comments help demonstrate my point, that javascript's type system is
> bifurcated.
True, but I think it works well – primitives supported by object wrapper types.
> - instanceof: use for objects.
>
> It's usable on objects, but not all that useful, even with natives like Array
> (they could have come from another frame). This is my biggest problem with
> javascript's nominative types. Ducktyping helps, but meh. This is one reason
> I'm so excited about private names and the de jure namespace the module
> system gives us -- which can help sort this out once and for all.
Both are indeed welcome. I wonder how often the frame crossing is an issue in
practice.
>> You could also say javascript's type lattice is pretty damn degenerate.
>
> Can you elaborate?
>
> The subtype relation is a partial order -- whether the top and bottom type
> are implicit or explicit is language dependent, but as a partial order all
> types in a given system can be represented as a lattice. But if you drew the
> types of any es5 application as a hasse diagram it would look pretty goofy --
> flat on one side with most of the built-ins nearly impossible to extend, and
> then below Object you'd have a tree that sprawls out, with each leaf
> bottoming out at falsum. So that's what I meant by a degenerate lattice. And
> es-next does offer some help with extending the built-ins, it's type system
> will still lack the capabilities to do much else, like derivation by
> restriction.
>
> This is all just speaking to the built-in type system -- obviously any number
> of application-level type systems have been layered on top with various
> characteristics. This is another problem :-/
I find things is JavaScript much more workable than in Java. A few minor quirks
need to be fixed, but I don’t have any major complaints (I’m not very demanding
in this area). Ignoring aesthetic objections – what problems can’t you solve in
JavaScript now?
>> (I do think structural typing could be really useful but I have no idea how
>> it could be introduced to the language unobtrusively.)
>
> Something like this?
> var Counter = { inc: "function", data: "number" };
> matchesInterface(anObject, Counter);
>
> You could do that and more with a library today, but you'd just be layering
> on third incompatible type system. And then we'd have three problems :)
I don’t think it clashes with what is there, it’s more like a helper for duck
typing.
--
Dr. Axel Rauschmayer
[email protected]
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss