StopIteration, ForwardToTarget, ... & symbols

Brendan Eich brendan at mozilla.org
Mon Nov 26 13:11:35 PST 2012


Herby Vojčík wrote:
> Hi,
>
> shouldn't StopIteration, ForwardToTarget from "Notification proxies" 
> thread and similar ones be rather well-known unique symbols (like 
> @iterator), now that we have them, instead of well-known globals? \

Why?

Let's separate the naming and unique identity concerns. Objects have 
unique identity, so do symbols. But if a unique identity is required 
without being a property key, then an object is the right answer, not a 
symbol. I think this applies to StopIteration.

Then there's the naming question. Should one have to use an @-name to 
reference a singleton object? Again I say no. APIs have public names, 
mostly or always. An identifier is a fine public name, better than a 
non-private symbol if bound in a namespace object or module -- or even 
if a global like JSON.

> On the more general line, I got pretty fond of (unique) symbols, they 
> seem like very good things for these sentinel-like objects. Is it ok / 
> preferable to use them for that? No need to use empty objects bearing 
> only their identity any more, imo.

For unique identity, why do you care between symbol and object?

For naming, see above.

/be


More information about the es-discuss mailing list