<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Weird rocketry &#187; duck typing</title>
	<atom:link href="http://webapp.org.ua/tag/duck-typing/feed/" rel="self" type="application/rss+xml" />
	<link>https://webapp.org.ua</link>
	<description>Flights to outer code</description>
	<lastBuildDate>Sat, 16 Jul 2016 11:12:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Python vs. PHP duck typing</title>
		<link>https://webapp.org.ua/dev/python-vs-php-duck-typing/</link>
		<comments>https://webapp.org.ua/dev/python-vs-php-duck-typing/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 12:44:38 +0000</pubDate>
		<dc:creator>bananos</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[duck typing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[typecast]]></category>

		<guid isPermaLink="false">http://webapp.org.ua/?p=128</guid>
		<description><![CDATA[Having previous experience in writing PHP code could potentially lead you to hours of debugging in Python. Consider the following simple example in PHP: PHP $s = "0"; $my = (bool) $s; var_dump($s); var_dump($my) And the output would be: string(1) "0" bool(false) Which is pretty expectable behavior in PHP, since it first casts string to [...]]]></description>
			<content:encoded><![CDATA[<p>Having previous experience in writing PHP code could potentially lead you to hours of debugging in Python.<br />
Consider the following simple example in PHP:</p>
<h2>PHP</h2>
<pre><code class="php">
$s = "0";
$my = (bool) $s;

var_dump($s);
var_dump($my)
</code>
</pre>
<p><span id="more-128"></span></p>
<p>And the output would be:</p>
<pre><code class="bash">
string(1) "0"
bool(<strong>false</strong>)
</code></pre>
<p>Which is pretty expectable behavior in PHP, since it first casts string to int, and than to boolean.</p>
<p>Consider the same example in Python:</p>
<h2>Python</h2>
<pre><code class="python">
s = "0"
my = bool(s)
print type(s), s
print type(my), my
</code>
</pre>
<p>And the output would be:</p>
<pre><code class="bash">

&lt;type 'str'&gt; 0
&lt;type 'bool'&gt; <strong>True</strong>

</code></pre>
<p>We&#8217;re not going to debate here wether this is good or bad, but you should be aware such things before they&#8217;ll steal hours of your time</p>
<p>To achieve the same behavior as in PHP, you&#8217;ll need to add explicit integer typecast:</p>
<pre><code class="python">
s = "0"
my = bool(int(s))
print type(s), s
print type(my), my
</code>
</pre>
<p>And the output would be:</p>
<pre><code class="bash">

&lt;type 'str'&gt; 0
&lt;type 'bool'&gt; <strong>False</strong>

</code></pre>
]]></content:encoded>
			<wfw:commentRss>https://webapp.org.ua/dev/python-vs-php-duck-typing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
