<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: AS3 Primitives</title>
	<atom:link href="http://k2xl.com/wordpress/2008/09/17/as3-primitives/feed/" rel="self" type="application/rss+xml" />
	<link>http://k2xl.com/wordpress/2008/09/17/as3-primitives/</link>
	<description>Flash, Web, Casual Games, Interactive Development</description>
	<lastBuildDate>Tue, 10 Jan 2012 11:48:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
	<item>
		<title>By: Danny Miller</title>
		<link>http://k2xl.com/wordpress/2008/09/17/as3-primitives/comment-page-1/#comment-119</link>
		<dc:creator>Danny Miller</dc:creator>
		<pubDate>Tue, 07 Oct 2008 14:29:12 +0000</pubDate>
		<guid isPermaLink="false">http://k2xl.com/wordpress/?p=34#comment-119</guid>
		<description>Thanks Brian, that convinces me. I&#039;ll edit the post.</description>
		<content:encoded><![CDATA[<p>Thanks Brian, that convinces me. I&#8217;ll edit the post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://k2xl.com/wordpress/2008/09/17/as3-primitives/comment-page-1/#comment-116</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Mon, 06 Oct 2008 18:18:24 +0000</pubDate>
		<guid isPermaLink="false">http://k2xl.com/wordpress/?p=34#comment-116</guid>
		<description>Danny - Enjoyed the discussion on casual gaming SIEGE &#039;08. Jumping in a little late here, but, with regards to the primitives in AS3 discussion: 

http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_08.html

&quot;...ActionScript stores primitive values internally as immutable objects. The fact that they are stored as immutable objects means that passing by reference is effectively the same as passing by value.&quot;

&quot;In ActionScript 3.0, primitive values and their wrapper objects are, for practical purposes, indistinguishable. All values, even primitive values, are objects. Flash Player and Adobe AIR treat these primitive types as special cases that behave like objects but that don&#039;t require the normal overhead associated with creating objects. This means that the following two lines of code are equivalent:

var someInt:int = 3;
var someInt:int = new int(3);&quot;</description>
		<content:encoded><![CDATA[<p>Danny &#8211; Enjoyed the discussion on casual gaming SIEGE &#8217;08. Jumping in a little late here, but, with regards to the primitives in AS3 discussion: </p>
<p><a href="http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_08.html" rel="nofollow">http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_08.html</a></p>
<p>&#8220;&#8230;ActionScript stores primitive values internally as immutable objects. The fact that they are stored as immutable objects means that passing by reference is effectively the same as passing by value.&#8221;</p>
<p>&#8220;In ActionScript 3.0, primitive values and their wrapper objects are, for practical purposes, indistinguishable. All values, even primitive values, are objects. Flash Player and Adobe AIR treat these primitive types as special cases that behave like objects but that don&#8217;t require the normal overhead associated with creating objects. This means that the following two lines of code are equivalent:</p>
<p>var someInt:int = 3;<br />
var someInt:int = new int(3);&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny Miller</title>
		<link>http://k2xl.com/wordpress/2008/09/17/as3-primitives/comment-page-1/#comment-105</link>
		<dc:creator>Danny Miller</dc:creator>
		<pubDate>Thu, 18 Sep 2008 14:52:27 +0000</pubDate>
		<guid isPermaLink="false">http://k2xl.com/wordpress/?p=34#comment-105</guid>
		<description>Theo,
Thanks again for your response and the discussion.

int x = 5 is not equivalent to int x = new Number(5) (is that what you were arguing?). 

At least in AVM2 it isn&#039;t...

A way you can see is by 
trace(System.totalMemory);
for (var i:int = 0; i &lt; 100; i++)
{
int x = 5;
}
trace(System.totalMemory);

Since garbage collection occurs over a few frames, the instances of 5 would still be in memory if 5 referred to a new object. 
Again, I&#039;m not sure if this is what you were arguing...

I&#039;m pretty sure x is referencing the memory location of value 5, rather than a new object with that value.

Also, I&#039;m VERY skeptical that 74345.4 in your example isn&#039;t casted before runtime. I&#039;m not saying I&#039;m 100% sure I&#039;m right; I could be wrong about this and you could be right, but I need some evidence.

The primitives in AS3 are treated very different than objects programmers can make.

Here&#039;s some documentation I believe supports my claim:
http://www.nusphere.com/kb/jscoreref/number.html
&quot;The Number object is an object wrapper for primitive numeric values.&quot;

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Number.html

&quot;You can manipulate primitive numeric values by using the methods and properties associated with the Number class. This class is identical to the JavaScript Number class.&quot;</description>
		<content:encoded><![CDATA[<p>Theo,<br />
Thanks again for your response and the discussion.</p>
<p>int x = 5 is not equivalent to int x = new Number(5) (is that what you were arguing?). </p>
<p>At least in AVM2 it isn&#8217;t&#8230;</p>
<p>A way you can see is by<br />
trace(System.totalMemory);<br />
for (var i:int = 0; i &lt; 100; i++)<br />
{<br />
int x = 5;<br />
}<br />
trace(System.totalMemory);</p>
<p>Since garbage collection occurs over a few frames, the instances of 5 would still be in memory if 5 referred to a new object.<br />
Again, I&#8217;m not sure if this is what you were arguing&#8230;</p>
<p>I&#8217;m pretty sure x is referencing the memory location of value 5, rather than a new object with that value.</p>
<p>Also, I&#8217;m VERY skeptical that 74345.4 in your example isn&#8217;t casted before runtime. I&#8217;m not saying I&#8217;m 100% sure I&#8217;m right; I could be wrong about this and you could be right, but I need some evidence.</p>
<p>The primitives in AS3 are treated very different than objects programmers can make.</p>
<p>Here&#8217;s some documentation I believe supports my claim:<br />
<a href="http://www.nusphere.com/kb/jscoreref/number.html" rel="nofollow">http://www.nusphere.com/kb/jscoreref/number.html</a><br />
&#8220;The Number object is an object wrapper for primitive numeric values.&#8221;</p>
<p><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Number.html" rel="nofollow">http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Number.html</a></p>
<p>&#8220;You can manipulate primitive numeric values by using the methods and properties associated with the Number class. This class is identical to the JavaScript Number class.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://k2xl.com/wordpress/2008/09/17/as3-primitives/comment-page-1/#comment-104</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Wed, 17 Sep 2008 15:27:14 +0000</pubDate>
		<guid isPermaLink="false">http://k2xl.com/wordpress/?p=34#comment-104</guid>
		<description>I think the AVM2 overview is liberal in its use of the term &quot;primitive&quot;, I&#039;ve also seen mentions of &quot;primitive objects&quot;, which is probably a better term, since they are objects, but with some special handling where they are treated like primitives by the runtime for performance reasons.

Your proof of them being passed by value is wrong and confuses variables for the values they contain. 

In the example &quot;x&quot; is a variable. It is not the object. The variable references an object, in this case the number 9. Assigning a new value to &quot;x&quot; makes the variable point to another object, the number 90. This was created by multiplying a reference to the earlier 9 with a literal object with the value 10, this returned &lt;em&gt;a new object&lt;/em&gt; with the value 90. 

The example has nothing to do with the actual object being passed by value or by reference or not. Since Number and int are immutable there is no way of proving that they are passed by value or by reference in the way you do, because you only change the variable. The variable is not the same as the object it references.

&quot;5 is Object&quot; and &quot;74345.4.toExponential(4)&quot; has absolutely nothing to do with the compiler. ActionScript has late binding, which means that the method toExponential isn&#039;t resolved until runtime. Other languages bind early and resolve these things at compile time, but ActionScript does not. The compiler does not cast, and the runtime doesn&#039;t cast either. The literal 5 &lt;em&gt;is an object&lt;/em&gt;. It is just treated a bit different by the runtime in some cases.</description>
		<content:encoded><![CDATA[<p>I think the AVM2 overview is liberal in its use of the term &#8220;primitive&#8221;, I&#8217;ve also seen mentions of &#8220;primitive objects&#8221;, which is probably a better term, since they are objects, but with some special handling where they are treated like primitives by the runtime for performance reasons.</p>
<p>Your proof of them being passed by value is wrong and confuses variables for the values they contain. </p>
<p>In the example &#8220;x&#8221; is a variable. It is not the object. The variable references an object, in this case the number 9. Assigning a new value to &#8220;x&#8221; makes the variable point to another object, the number 90. This was created by multiplying a reference to the earlier 9 with a literal object with the value 10, this returned <em>a new object</em> with the value 90. </p>
<p>The example has nothing to do with the actual object being passed by value or by reference or not. Since Number and int are immutable there is no way of proving that they are passed by value or by reference in the way you do, because you only change the variable. The variable is not the same as the object it references.</p>
<p>&#8220;5 is Object&#8221; and &#8220;74345.4.toExponential(4)&#8221; has absolutely nothing to do with the compiler. ActionScript has late binding, which means that the method toExponential isn&#8217;t resolved until runtime. Other languages bind early and resolve these things at compile time, but ActionScript does not. The compiler does not cast, and the runtime doesn&#8217;t cast either. The literal 5 <em>is an object</em>. It is just treated a bit different by the runtime in some cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny Miller</title>
		<link>http://k2xl.com/wordpress/2008/09/17/as3-primitives/comment-page-1/#comment-103</link>
		<dc:creator>Danny Miller</dc:creator>
		<pubDate>Wed, 17 Sep 2008 14:24:59 +0000</pubDate>
		<guid isPermaLink="false">http://k2xl.com/wordpress/?p=34#comment-103</guid>
		<description>Theo,
Thanks for your response. According to the AVM2 Overview document released by Adobe:

&quot;Primitive data include integers and floating-point numbers encoded in various ways.&quot;

So I assume I&#039;m using the correct term.

Also, I&#039;m confused why you say that they are not passed by reference.

var x:int = 9;
func(x);
trace(x); // still 9
x = func(x);
trace(x); // now 90

func = function(x:int)
{
x = x*10;
return x;
}

The actually value is immutable because they are primitives.

5 is Object works because of the compiler. That&#039;s why 7345.4.toExponential works. The compiler casts the number as a Number object.

7345.4.toExponential(2) is equivalent to Number(7345.4).toExponential(2);</description>
		<content:encoded><![CDATA[<p>Theo,<br />
Thanks for your response. According to the AVM2 Overview document released by Adobe:</p>
<p>&#8220;Primitive data include integers and floating-point numbers encoded in various ways.&#8221;</p>
<p>So I assume I&#8217;m using the correct term.</p>
<p>Also, I&#8217;m confused why you say that they are not passed by reference.</p>
<p>var x:int = 9;<br />
func(x);<br />
trace(x); // still 9<br />
x = func(x);<br />
trace(x); // now 90</p>
<p>func = function(x:int)<br />
{<br />
x = x*10;<br />
return x;<br />
}</p>
<p>The actually value is immutable because they are primitives.</p>
<p>5 is Object works because of the compiler. That&#8217;s why 7345.4.toExponential works. The compiler casts the number as a Number object.</p>
<p>7345.4.toExponential(2) is equivalent to Number(7345.4).toExponential(2);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://k2xl.com/wordpress/2008/09/17/as3-primitives/comment-page-1/#comment-102</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Wed, 17 Sep 2008 09:17:34 +0000</pubDate>
		<guid isPermaLink="false">http://k2xl.com/wordpress/?p=34#comment-102</guid>
		<description>&quot;Number, int, etc are primitives.&quot;

Except that they are not. Everything &lt;em&gt;is&lt;/em&gt; an object in ActionScript. Java has real primitives, but they are a completely different thing from the Number, Boolean, int and uint types in ActionScript. Just consider this:

trace(5 is Object) // this prints &quot;true&quot;

The reason that it looks like Number and the others are primitives is that the compiler and the runtime does some optimization tricks on variables that are typed as Number, int and uint, and the fact that these types are immutable. That is not the same thing as them being primitives. You can&#039;t do this with a primitive:

trace(7345.4.toExponential(2)) 

Number, int, uint and Boolean, are &lt;em&gt;not&lt;/em&gt; passed by value, but by reference. Not that it makes any difference, because they are immutable and you can&#039;t change them anyway. The same goes for String.</description>
		<content:encoded><![CDATA[<p>&#8220;Number, int, etc are primitives.&#8221;</p>
<p>Except that they are not. Everything <em>is</em> an object in ActionScript. Java has real primitives, but they are a completely different thing from the Number, Boolean, int and uint types in ActionScript. Just consider this:</p>
<p>trace(5 is Object) // this prints &#8220;true&#8221;</p>
<p>The reason that it looks like Number and the others are primitives is that the compiler and the runtime does some optimization tricks on variables that are typed as Number, int and uint, and the fact that these types are immutable. That is not the same thing as them being primitives. You can&#8217;t do this with a primitive:</p>
<p>trace(7345.4.toExponential(2)) </p>
<p>Number, int, uint and Boolean, are <em>not</em> passed by value, but by reference. Not that it makes any difference, because they are immutable and you can&#8217;t change them anyway. The same goes for String.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

