If you come at this (like I first did) thinking of Packages as containers, things can get confusing.

The secret to understanding is to start with namespaces, which are central and critical to ES4 and backwards compatibility. I won't try to describe namespaces here and will leave that to others far more competent than me, but given namespaces, then packages are really just a syntax shortcut for namespaces.

Now you could (as we did), overload the package name as the file name of compiled program elements. However, this has restrictions and complications. It starts burdening package names with meaning you really don't want. Imports directives then become program unit dependencies also.

Unit directives provide an independent naming for how various components of a program will be bundled. Often these do not lie along package or namespace boundaries. Units also provide dependency information.

We use units directives to group program elements and name them as external (pre-compiled) byte code files. In our case, we use the UnitName as  the name of the byte code file. We currently don't use the unit URL. The compiler also has the option to merge all units and dependent units into a single output file. Each unit file can thus have code from one or more packages. Determining the units for an application thus become a loading and network consideration.

So the unit proposal gives flexibility in deciding what program elements should be loaded or transmitted as a unit. This is often independent of and at cross purposes to package or namespace naming.

Michael


Our compiler uses the UnitName of the unit directive to name compiled byte code files.

Brendan Eich wrote:
On Oct 31, 2007, at 3:46 AM, Maciej Stachowiak wrote:

I notice some seemingly duplicate features that will perhaps become  
more clear on closer reading of the spec. For instance I see all three  
of namespace, package and unit productions in the grammar. With my  
limited imagination it's hard to think of how those could be three  
interestingly different features.

What's the Sesame Street song? "... one of these things is not like the other, one of these things just doesn't belong."

You are not alone in wondering about these three -- this has come up at past TG1 meetings and we went ahead and implemented to get experience. Michael O'Brien has a small-device implementation that he's posted about here. He may have useful feedback.

This may help separate namespaces and units:

* A namespace is a qualifier on property name (a string in general in ES1-3). It's a prefix to apply to unqualified identifiers used by a block in which a 'use namespace N' pragma occurs at the top. There are sane rules about ordering and ambiguity errors, covered briefly in the overview. As you can see from the RI, namespaces are used heavily. One benefit is to avoid incompatible name pollution of unqualified identifiers in the standard objects and the global object.

* A program unit is an explicit reflection of the Program production's semantics from ES1-3. When you see a program unit body's closing brace, the steps in ES3 Chapter 10.2, plus ES4 steps like those, kick in. You can nest units, and a server framework can expand them server side when they are stated without bodies, but with locators that point to the body in question. This preserves accurate source coordinates for errors coming from nested units, and avoids downloading too many small files. See the proposal for more detail.

These two are genuinely different, orthogonal, and useful things, I think.

* Packages are built on namespaces, and unlike program units they are open-ended. You can keep adding to a package (someone correct me if I'm wrong), by writing

package acme.widgets {
  ...
}

several times in a row. As the overview notes, a package has two namespaces, package-public and package-internal. There's an import directive for pulling some or all of the public names of a package into another scope.

/be


_______________________________________________ Es4-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es4-discuss



_______________________________________________
Es4-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es4-discuss

Reply via email to