<?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>Programming tips for newbies - CodeRookie &#187; Python</title>
	<atom:link href="http://www.coderookie.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coderookie.com</link>
	<description>Programming tips from a rookie developer to other rookie developers</description>
	<lastBuildDate>Wed, 17 Nov 2010 07:46:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Python versus Java</title>
		<link>http://www.coderookie.com/2006/java/python-versus-java/</link>
		<comments>http://www.coderookie.com/2006/java/python-versus-java/#comments</comments>
		<pubDate>Thu, 31 Aug 2006 09:22:01 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.coderookie.com/2006/java/python-versus-java/</guid>
		<description><![CDATA[Ever wondered why there are so many people that program in Python, although Java (along with .NET) is the main enterprise language? You can find out in this post at bitworking.org.




Joe talks about the things (technical term!) that Python has and Java misses. Here is the list of those abstractions with my comments and ways [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/ecosnake/215576226/"><img src="http://static.flickr.com/62/215576226_c60840e1df_m.jpg" alt="python" align="left" /></a>Ever wondered why there are so many people that program in Python, although Java (along with .NET) is the main enterprise language? You can find out in <a href="http://bitworking.org/news/Python_isnt_Java_without_the_compile">this post</a> at bitworking.org.<div style="float:right;margin-top:0px;margin-left:6px;">
<script type="text/javascript"><!--
google_ad_client = "pub-3846130357517643";
google_ad_width = 125;
google_ad_height = 125;
google_ad_format = "125x125_as";
google_ad_type = "text_image";
google_ad_channel ="6808781126";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "008000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></p>
<p>Joe talks about the things (technical term!) that Python has and Java misses. Here is the list of those abstractions with my comments and ways of simulating (give me a feedback with your propositions):<br />
<span id="more-10"></span></p>
<p><a href="http://www.gpsnavigatorsreview.com/garmin/garmin-nuvi-360-35-inch-bluetooth-portable-gps-navigator/" title="Garmin nuvi 360 info">Review of <strong>Garmin nüvi 360</strong> GPS with bargain price</a></p>
<p>   <strong>1.  First-class functions</strong><br />
This is known from C++, where you can define function pointer that can be passed around as e.g. a parameter to other function.</p>
<p>   <strong>2. Keyword parameters</strong><br />
OK, that's the one I would like to have in Java, it would add a better strictness to the language, now if you want to simulate this kind of behaviour you would have to create a class and add setters/getters.</p>
<p>   <strong>3. Default parameters</strong><br />
I don't know why did Sun skip this while creating Java, it is a very useful abstraction. The simulations of this can be achieved by many overloaded methods/constructors.</p>
<div class="syntax_hilite">
<div id="java-3">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> A <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> value;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #993333;">void</span> calculate<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; value = a;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #993333;">void</span> calculate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; calculate<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">10</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// this is the default</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>   <strong>4. Tuples</strong><br />
   <strong>5. Parallel assignment</strong><br />
   <strong>6. Efficient multiple return values</strong><br />
Here I can't give any proposition how to simulate this in Java (at some point arrays might be used). A very nice functionality of Python (and some other languages), especially in conjunction with the next one...<script type="text/javascript"><!--
google_ad_client = "pub-3846130357517643";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="9138240644";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
That is, returning a tuple out of a method. Again some may try to simulate it using arrays.</p>
<p>   <strong>7. Continuations</strong><br />
They are a way to save a function execution, and restore it at later time, it's as if you could jump out of a function during it's execution, and than, when by calling the function again, returning to the exact point where the function has been saved.</p>
<p>Here's an example to give you a better understanding of this. It is a function that will return values from the beginning to the end:</p>
<div class="syntax_hilite">
<div id="python-4">
<div class="python">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">def</span> fun<span style="color: black;">&#40;</span>begin, end<span style="color: black;">&#41;</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; i = begin</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff7700;font-weight:bold;">while</span> i &lt;end:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">yield</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; i = i + <span style="color: #ff4500;color:#800000;">1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">f=fun<span style="color: black;">&#40;</span><span style="color: #ff4500;color:#800000;">10</span>,<span style="color: #ff4500;color:#800000;">100</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">f.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">f.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">f.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Executing above code gives:<br />
<code>10<br />
11<br />
12<br />
</code></p>
<p>   <strong>8. User-defined operators</strong><br />
That one was probably a mistake, I don't know a way to add a user-defined operator to Python (give me a hint if I am wrong)</p>
<p>   <strong>9. Closures</strong><br />
In one of the <a href="http://www.coderookie.com/2006/java/closures-in-java/">previous posts</a> I mentioned about proposition to add closures to Java.</p>
<p>   <strong>10. Meta-programming</strong><br />
I haven't used much of this in Python, but it allows e.g. to assigning methods to classes on the fly. A nice functionality but I don't know how could it be used in a corporate environment, with more than 5 developers creating the code.</p>
<p><script>reddit_url='http://www.coderookie.com/2006/java/python-versus-java/'</script><br />
<script language="javascript" src="http://reddit.com/button.js?t=3"></script> &nbsp;&nbsp; <script></p>

<div class="sociable">
<span class="sociable_tagline">
<strong>Share and Enjoy:</strong>
	<span>These icons link to social bookmarking sites where readers can share and discover new web pages.</span>
</span>
<ul>
	<li><a href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Fwww.coderookie.com%2F2006%2Fjava%2Fpython-versus-java%2F&amp;title=Python+versus+Java" title="DZone" onfocus="sociable_description_link(this, 'description')"><img src="http://www.coderookie.com/wp-content/plugins/sociable/images/dzone.png" title="DZone" alt="DZone" class="sociable-hovers" /></a></li>
	<li><a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.coderookie.com%2F2006%2Fjava%2Fpython-versus-java%2F&amp;title=Python+versus+Java" title="del.icio.us"><img src="http://www.coderookie.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.coderookie.com%2F2006%2Fjava%2Fpython-versus-java%2F&amp;title=Python+versus+Java" title="Digg" onfocus="sociable_description_link(this, 'bodytext')"><img src="http://www.coderookie.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.coderookie.com%2F2006%2Fjava%2Fpython-versus-java%2F" title="Technorati"><img src="http://www.coderookie.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.coderookie.com/2006/java/python-versus-java/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

