I was just trying to understand the AS3 namespace a little bit yesterday
while fixing some issues in dts2as. It appears that the AS3 namespace is
used to allow certain functions on the Object class, like toString() and
valueOf(), to be implemented in subclasses without requiring the override
keyword. I think the AS3 namespace is always available, so it ends up
acting similarly to public. Kind of interesting.

Back on topic, yes, I agree some kind of token or keyword should be used to
designate the global namespace. Like you, I'm a little wary of using the
existing AS3 namespace identifier for that.

Of the options that you presented, I think I like  *.Event and .Event the
most.

The options with :: don't feel quite right. While I know that packages are
namespaces (I remember making that discovery back in the day and excitedly
blogging about it), other classes aren't usually referenced with :: in
code. With that in mind, I like . better than :: because the . is more
consistent. If it were somehow easier to implement, though, I could live
with it.

A simple string like global or null might conflict with some top-level
variable in user code or in the standard library of some JS environment, so
I think that style should be avoided.

Of the two between *.Event and .Event, I'm not quite sure which I like
better. Which of these seems more readable?

var myVar:.Event = new .Event();

var myVar:*.Event = new *.Event();

At first, I thought I liked *.Event better, but I might be preferring
.Event more now.

- Josh


On Fri, Sep 18, 2015 at 9:38 AM, Alex Harui <aha...@adobe.com> wrote:

>
>
> On 9/18/15, 9:02 AM, "Josh Tynjala" <joshtynj...@gmail.com> wrote:
>
> >I don't think that there's a currently a way to explicitly specify the
> >global namespace in a fully-qualified class name. I suspect it rarely came
> >up in the Flash runtime because it has so few global classes. This would
> >be
> >very useful with the very large number of classes in the JavaScript global
> >namespace, though. I hope you can figure out how to add it!
>
> I don’t know if there is currently a way or not.  I’m currently stepping
> through the lexer/parser to see how it handles namespaces.  The concept of
> namespaces is heavily used within the compiler.  There appear to be
> special namespaces like “public”, “protected” and “private” and user
> defined namespaces (like mx_internal) and packages are also namespaces and
> not objects like they are in JS.
>
> If there isn’t a current way, my first thoughts are to designate a special
> token or keyword for a user-defined namespace that implies the global
> namespace or trick the package namespace lexer/tokenizer to allow
> something.
>
> For example, user-defined namespaces are indicated in-line with ‘::’ as in:
>   mx_internal::someVar
>
> And package namespaces are indicated with a dot-path expression to fully
> qualify something as in:
>   org.apache.flex.events.Event
>
> So maybe one of the following can currently be used or the compiler can be
> taught to use as a way to fully qualify the “global” package/namespace.
>
>   ::Event  // nothing in front of the user-defined namespace delimiter
>   null::Event
>   global::Event
>   *::Event
>   *.Event
>   null.Event
>   .Event   // nothing in front of the package path delimiter
>
> FWIW, there appear to be “hidden” namespaces for the builtins like Object,
> Array, String. I see use of:
>
>   http://adobe.com/AS3/2006/builtin
>
> and
>
>   AS3
>
> as namespaces in the compiler code.  We could use AS3 as the special
> keyword so
>
>   AS3::Event
>
> is the Event in the global namespace, but that doesn’t feel right to me.
> I’m leaning towards keeping these namespaces for the true builtins for AS
> and JS.  But I’m open to change on that.
>
> Thoughts?
> -Alex
>
>

Reply via email to