[prev in list] [next in list] [prev in thread] [next in thread] 

List:       webkit-dev
Subject:    Re: [webkit-dev] the name "AtomicString"
From:       Maciej Stachowiak <mjs () apple ! com>
Date:       2018-12-20 20:34:56
Message-ID: 4DAFF4C0-685B-4A56-AF06-C2C5A7CE0865 () apple ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


> On Dec 20, 2018, at 11:24 AM, Geoffrey Garen <ggaren@apple.com> wrote:
> 
> > > > So hard to pronounce though! Why not UniqueString? It's not quite as explicit \
> > > > but close enough. 
> > > 
> > > Wouldn't it be confusing to use UniqueString type for a string that is *common* \
> > > in order to save memory?
> > 
> > I would interpret it as UniqueString(foo) means "give me the unique copy of \
> > string foo". You use a unique copy so you can use the same string in many places \
> > without wasting memory, or excess time on string compares. It's used in many \
> > places, but there is only one. (Maybe we should call it HighlanderString? OK, not \
> > serious.)
> 
> By definition, any string that has been uniqued is unique.
> 
> So, maybe we like "unique" or maybe we don't. But if we like "unique", it's \
> strictly better than "uniqued". 
> > > Personally, I like the AtomString proposal as it is close to the naming we are \
> > > used to and addresses the issue raised (atomic has a different meaning with \
> > > threading). Also, I had never heard of interned strings before.
> 
> AtomicString has two features:
> 
> (1) You do comparison by pointer / object identity;
> 
> (2) You never allocate two objects for the same sequence of characters.
> 
> JavaScript symbols offer (1) but avoid (2):
> 
> 	let a = Symbol("The string of the past!");
> 	let b = Symbol("The string of the past!");
> 	a == b; // false
> 	a === b; // false
> 
> Today we call (1) "UniquedStringImpl" and (1) + (2) "AtomicStringImpl".
> 
> If we rename (1) + (2) to "UniqueString" or "UniquedString", we need a new name for \
> (1) alone.

It seems like (1) alone is not actually "uniqued". In the case of symbols at least, \
it's the opposite: the string deliberately kept distinct from all other strings of \
equal value, so pointer equality is used as a check for equality by pointer identity, \
rather than a shortcut for equality by value. 

From what I can tell, UniquedStringImpl exists mainly to be a base class for \
SymbolImpl and AtomicStringImpl. So you could imagine giving it a more verbose and \
explicit name, like PointerEqualityStringImpl. However, JSC seems to use \
UniquedStringImpl directly in a bunch of cases, I think to make it convenient for a \
property name to be either an AtomicString or a Symbol. Maybe a longer name for that \
case is ok?

Regards,
Maciej


[Attachment #5 (text/html)]

<html><head><meta http-equiv="Content-Type" content="text/html; \
charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; \
line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote \
type="cite" class=""><div class="">On Dec 20, 2018, at 11:24 AM, Geoffrey Garen \
&lt;<a href="mailto:ggaren@apple.com" class="">ggaren@apple.com</a>&gt; \
wrote:</div><br class="Apple-interchange-newline"><div class=""><meta \
http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div \
style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: \
after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div \
class=""><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: \
12px; font-style: normal; font-variant-caps: normal; font-weight: normal; \
letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; \
white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; \
text-decoration: none;" class=""><blockquote type="cite" class=""><div \
class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: \
12px; font-style: normal; font-variant-caps: normal; font-weight: normal; \
letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; \
white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; \
text-decoration: none;"><div class=""><div class="" style="caret-color: rgb(0, 0, 0); \
font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: \
normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: \
0px; text-transform: none; white-space: normal; word-spacing: 0px; \
-webkit-text-stroke-width: 0px; text-decoration: none;"><div class="">So hard to \
pronounce though! Why not UniqueString? It's not quite as explicit but close \
enough.&nbsp;</div></div></div></blockquote><div class="" style="caret-color: rgb(0, \
0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; \
font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: \
start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: \
0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><br class=""></div><div \
class="" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; \
font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: \
normal; text-align: start; text-indent: 0px; text-transform: none; white-space: \
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: \
none;">Wouldn't it be confusing to use<span \
class="Apple-converted-space">&nbsp;</span><b class="">Unique</b>String type for a \
string that is<span class="Apple-converted-space">&nbsp;</span><b \
class="">*common*</b><span class="Apple-converted-space">&nbsp;</span>in order to \
save memory?</div></div></blockquote><div class=""><br class=""></div><div class="">I \
would interpret it as UniqueString(foo) means "give me the unique copy of string \
foo". You use a unique copy so you can use the same string in many places without \
wasting memory, or excess time on string compares. It's used in many places, but \
there is only one. (Maybe we should call it HighlanderString? OK, not \
serious.)</div></div></div></blockquote><div class=""><br class=""></div>By \
definition, any string that has been uniqued is unique.</div><div class=""><br \
class=""></div><div class="">So, maybe we like "unique" or maybe we don't. But if we \
like "unique", it's strictly better than "uniqued".<br class=""><div class=""><br \
class=""></div><blockquote type="cite" class=""><div class=""><div \
style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; \
font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: \
normal; text-align: start; text-indent: 0px; text-transform: none; white-space: \
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" \
class=""><blockquote type="cite" class=""><div class=""><div class="" \
style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; \
font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: \
normal; text-align: start; text-indent: 0px; text-transform: none; white-space: \
normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: \
none;">Personally, I like the AtomString proposal as it is close to the naming we are \
used to and addresses the issue raised (atomic has a different meaning with \
threading).</div><div class="" style="caret-color: rgb(0, 0, 0); font-family: \
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; \
font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; \
text-transform: none; white-space: normal; word-spacing: 0px; \
-webkit-text-stroke-width: 0px; text-decoration: none;">Also, I had never heard of \
interned strings before.</div></div></blockquote></div></div></blockquote><div \
class=""><br class=""></div><div class="">AtomicString has two features:</div><div \
class=""><br class=""></div><div class="">(1) You do comparison by pointer / object \
identity;</div><div class=""><br class=""></div><div class="">(2) You never allocate \
two objects for the same sequence of characters.</div><div class=""><br \
class=""></div><div class="">JavaScript symbols offer (1) but avoid (2):</div><div \
class=""><br class=""></div><div class=""><span class="Apple-tab-span" \
style="white-space:pre">	</span>let&nbsp;a = Symbol("The string of the \
past!");</div><div class=""><span class="Apple-tab-span" style="white-space: \
pre;">	</span>let&nbsp;b = Symbol("The string of the past!");</div><div \
class=""><span class="Apple-tab-span" style="white-space:pre">	</span>a == b; // \
false</div><div class=""><span class="Apple-tab-span" \
style="white-space:pre">	</span>a === b; // false</div><div class=""><br \
class=""></div><div class="">Today we call (1) "UniquedStringImpl" and (1) + (2) \
"AtomicStringImpl".</div><div class=""><br class=""></div><div class="">If we rename \
(1) + (2) to "UniqueString" or "UniquedString", we need a new name for (1) \
alone.</div></div></div></div></blockquote><br class=""></div><div>It seems like (1) \
alone is not actually "uniqued". In the case of symbols at least, it's the opposite: \
the string deliberately kept distinct from all other strings of equal value, so \
pointer equality is used as a check for equality by pointer identity, rather than a \
shortcut for equality by value.&nbsp;</div><div><br class=""></div><div>From what I \
can tell,&nbsp;UniquedStringImpl exists mainly to be a base class for SymbolImpl and \
AtomicStringImpl. So you could imagine giving it a more verbose and explicit name, \
like PointerEqualityStringImpl. However, JSC seems to use UniquedStringImpl directly \
in a bunch of cases, I think to make it convenient for a property name to be either \
an AtomicString or a Symbol. Maybe a longer name for that case is ok?</div><div><br \
class=""></div><div>Regards,</div><div>Maciej</div><div><br class=""></div><div><br \
class=""></div></body></html>



_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic