<?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: Is None more like 0 or -1 ?</title>
	<atom:link href="http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/</link>
	<description>game dev blog</description>
	<lastBuildDate>Fri, 06 Jan 2012 23:00:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>By: philhassey</title>
		<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/comment-page-1/#comment-22307</link>
		<dc:creator>philhassey</dc:creator>
		<pubDate>Fri, 08 Jan 2010 21:01:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=261#comment-22307</guid>
		<description>Thanks everyone for the feedback.  Sounds like &quot;0&quot; is the winner.  

Here&#039;s the deal, in tinypyC++, when compiling I actually do check for None vs int and throw a compilation error at that point.  So your code &quot;can&#039;t&quot; assign None to an int.

However if you read my post earlier this week about Exceptions, I&#039;ve since added an optional exception-free mode to tinypyC++.  So in cases like this [1,2,3].pop(5) it will print an error to stderr and return &quot;None&quot;.  But I had to decide if &quot;None&quot; was more like 0 or -1.  To be clear, this will never happen when exceptions are enabled (which is the default behavior.)  Exception-free mode is enabled by -DTP_NO_THROW.

In tinypyC++ you can assign an object = None and it will nullify the internal pointer and reduce the ref-count.</description>
		<content:encoded><![CDATA[<p>Thanks everyone for the feedback.  Sounds like &#8220;0&#8243; is the winner.  </p>
<p>Here&#8217;s the deal, in tinypyC++, when compiling I actually do check for None vs int and throw a compilation error at that point.  So your code &#8220;can&#8217;t&#8221; assign None to an int.</p>
<p>However if you read my post earlier this week about Exceptions, I&#8217;ve since added an optional exception-free mode to tinypyC++.  So in cases like this [1,2,3].pop(5) it will print an error to stderr and return &#8220;None&#8221;.  But I had to decide if &#8220;None&#8221; was more like 0 or -1.  To be clear, this will never happen when exceptions are enabled (which is the default behavior.)  Exception-free mode is enabled by -DTP_NO_THROW.</p>
<p>In tinypyC++ you can assign an object = None and it will nullify the internal pointer and reduce the ref-count.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/comment-page-1/#comment-22306</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Fri, 08 Jan 2010 20:00:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=261#comment-22306</guid>
		<description>For what it&#039;s worth, I have previously invoked the fact that None is less than any integer, so 0x8000000 would certainly be tempting.  However, the fact that it&#039;s false is used far more often in my code, so zero is probably better  Then again, I have elsewhere relied on the difference between zero and None, so that clearly can&#039;t be optimal.  0xDEADBEEF would be great for the humor value, and very negative, but might occasionally trip on a real value.

That said, this looks like an exceptional case to me.  You have a choice between failing loudly, or doing the wrong thing sometimes.  If tinypyC++ will frequently be used on third-party code, then perhaps zero is best; otherwise, error out.</description>
		<content:encoded><![CDATA[<p>For what it&#8217;s worth, I have previously invoked the fact that None is less than any integer, so 0&#215;8000000 would certainly be tempting.  However, the fact that it&#8217;s false is used far more often in my code, so zero is probably better  Then again, I have elsewhere relied on the difference between zero and None, so that clearly can&#8217;t be optimal.  0xDEADBEEF would be great for the humor value, and very negative, but might occasionally trip on a real value.</p>
<p>That said, this looks like an exceptional case to me.  You have a choice between failing loudly, or doing the wrong thing sometimes.  If tinypyC++ will frequently be used on third-party code, then perhaps zero is best; otherwise, error out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/comment-page-1/#comment-22305</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Fri, 08 Jan 2010 17:10:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=261#comment-22305</guid>
		<description>To expound on my earlier post now that my laptop is working again, I&#039;d say focus on the common use cases and performance above anything else.

tinypyc++ ints should definitely be ints in C++, so int* or the tuple idea above are out for performance reasons.

So for use cases, here&#039;s ones I can think of:

x = None
if something_condition:
  x = something_other_than_none
if x:
  do_something()

x = something_other_than_none
if some_condition:
  x = None
if not x:
  do_something()

x = something_other_than_none
if some_condition:
  y = None
else:
  y = some_other_number
if x == y:
  do_something()

I know you&#039;re big on unit testing, so I would definitely think that there should be a fair number of x = None : int unit tests to build, and that they should all look reasonable.

I&#039;m still leaning towards 0 though.</description>
		<content:encoded><![CDATA[<p>To expound on my earlier post now that my laptop is working again, I&#8217;d say focus on the common use cases and performance above anything else.</p>
<p>tinypyc++ ints should definitely be ints in C++, so int* or the tuple idea above are out for performance reasons.</p>
<p>So for use cases, here&#8217;s ones I can think of:</p>
<p>x = None<br />
if something_condition:<br />
  x = something_other_than_none<br />
if x:<br />
  do_something()</p>
<p>x = something_other_than_none<br />
if some_condition:<br />
  x = None<br />
if not x:<br />
  do_something()</p>
<p>x = something_other_than_none<br />
if some_condition:<br />
  y = None<br />
else:<br />
  y = some_other_number<br />
if x == y:<br />
  do_something()</p>
<p>I know you&#8217;re big on unit testing, so I would definitely think that there should be a fair number of x = None : int unit tests to build, and that they should all look reasonable.</p>
<p>I&#8217;m still leaning towards 0 though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/comment-page-1/#comment-22304</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Fri, 08 Jan 2010 15:28:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=261#comment-22304</guid>
		<description>I agree that &quot;if not x:&quot; is the most common use case so should work.</description>
		<content:encoded><![CDATA[<p>I agree that &#8220;if not x:&#8221; is the most common use case so should work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tonic</title>
		<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/comment-page-1/#comment-22302</link>
		<dc:creator>tonic</dc:creator>
		<pubDate>Fri, 08 Jan 2010 11:35:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=261#comment-22302</guid>
		<description>My intuition would be for it to be 0. But then again, I&#039;m not familiar with python and what is the meaning of None.

OTOH - what about 0x80000000.. ;-)
(for a 32bit machine, this is the one negative number which doesn&#039;t have a positive counterpart)
I think this is same what Mike also suggested as one possibility.</description>
		<content:encoded><![CDATA[<p>My intuition would be for it to be 0. But then again, I&#8217;m not familiar with python and what is the meaning of None.</p>
<p>OTOH &#8211; what about 0&#215;80000000.. <img src='http://www.philhassey.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /><br />
(for a 32bit machine, this is the one negative number which doesn&#8217;t have a positive counterpart)<br />
I think this is same what Mike also suggested as one possibility.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Larry Hastings</title>
		<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/comment-page-1/#comment-22300</link>
		<dc:creator>Larry Hastings</dc:creator>
		<pubDate>Fri, 08 Jan 2010 05:18:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=261#comment-22300</guid>
		<description>Definitely more like 0 than -1; you&#039;d want it to be a false value.

But why are you considering allowing &quot;int&quot; variables to be set to &quot;None&quot; in the first place?  Why bother to have typed variables unless you&#039;re going to enforce type safety?  Whatever those circumstances are where you wanted to say &quot;int x = None&quot;, you should change *that*.</description>
		<content:encoded><![CDATA[<p>Definitely more like 0 than -1; you&#8217;d want it to be a false value.</p>
<p>But why are you considering allowing &#8220;int&#8221; variables to be set to &#8220;None&#8221; in the first place?  Why bother to have typed variables unless you&#8217;re going to enforce type safety?  Whatever those circumstances are where you wanted to say &#8220;int x = None&#8221;, you should change *that*.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jovoc</title>
		<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/comment-page-1/#comment-22299</link>
		<dc:creator>jovoc</dc:creator>
		<pubDate>Fri, 08 Jan 2010 02:34:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=261#comment-22299</guid>
		<description>I think it has to be 0 or otherwise statements like &quot;if not x:&quot; would fail to evaluate correctly.

If that&#039;s not an issue, I&#039;d make it a symbolic constant, i.e.
#define NONE_VAL (0xDEADBEEF)

That way it&#039;s easy to spot in a debugger.</description>
		<content:encoded><![CDATA[<p>I think it has to be 0 or otherwise statements like &#8220;if not x:&#8221; would fail to evaluate correctly.</p>
<p>If that&#8217;s not an issue, I&#8217;d make it a symbolic constant, i.e.<br />
#define NONE_VAL (0xDEADBEEF)</p>
<p>That way it&#8217;s easy to spot in a debugger.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/comment-page-1/#comment-22298</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Fri, 08 Jan 2010 00:28:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=261#comment-22298</guid>
		<description>Seems to me that &quot;int x = None;&quot; is an error, because None is not an int.

I am guessing this occurs because tinypyC++ needs to declare &quot;x&quot; before it is assigned a value.

Perhaps you can define a particular int (e.g. -sys.maxint-1) to mean None, analogous to NaN for floating point.

Alternatively, values can be represented internally by a 2-tuple (valid,value).

int x = None; would become &quot;Int x = (False, dont_care);&quot;.
int x = 42; would become &quot;Int x = (True,42);&quot;

define appropriate casts to convert back and forth between &quot;Int&#039;s&quot; and &quot;int&#039;s&quot;.</description>
		<content:encoded><![CDATA[<p>Seems to me that &#8220;int x = None;&#8221; is an error, because None is not an int.</p>
<p>I am guessing this occurs because tinypyC++ needs to declare &#8220;x&#8221; before it is assigned a value.</p>
<p>Perhaps you can define a particular int (e.g. -sys.maxint-1) to mean None, analogous to NaN for floating point.</p>
<p>Alternatively, values can be represented internally by a 2-tuple (valid,value).</p>
<p>int x = None; would become &#8220;Int x = (False, dont_care);&#8221;.<br />
int x = 42; would become &#8220;Int x = (True,42);&#8221;</p>
<p>define appropriate casts to convert back and forth between &#8220;Int&#8217;s&#8221; and &#8220;int&#8217;s&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: philhassey</title>
		<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/comment-page-1/#comment-22297</link>
		<dc:creator>philhassey</dc:creator>
		<pubDate>Thu, 07 Jan 2010 23:49:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=261#comment-22297</guid>
		<description>@Everyone - your responses are great :)  I&#039;m going to hold on really responding much myself with my final thoughts until everyone has said their piece.</description>
		<content:encoded><![CDATA[<p>@Everyone &#8211; your responses are great <img src='http://www.philhassey.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   I&#8217;m going to hold on really responding much myself with my final thoughts until everyone has said their piece.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug Napoleone</title>
		<link>http://www.philhassey.com/blog/2010/01/07/is-none-more-like-0-or-1/comment-page-1/#comment-22296</link>
		<dc:creator>Doug Napoleone</dc:creator>
		<pubDate>Thu, 07 Jan 2010 23:32:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=261#comment-22296</guid>
		<description>@andrew:

void main()
{
unsigned int a = (unsigned int)-1;
unsigned int b = 0xFFFFFFFF;
if (a == b)
{
    printf(&quot;Same thing!\n&quot;);
}
}

&gt;&gt; a.out
Same Thing!
&gt;&gt;</description>
		<content:encoded><![CDATA[<p>@andrew:</p>
<p>void main()<br />
{<br />
unsigned int a = (unsigned int)-1;<br />
unsigned int b = 0xFFFFFFFF;<br />
if (a == b)<br />
{<br />
    printf(&#8220;Same thing!\n&#8221;);<br />
}<br />
}</p>
<p>&gt;&gt; a.out<br />
Same Thing!<br />
&gt;&gt;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

