<?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>No Open Blockers &#187; Java</title>
	<atom:link href="http://noopenblockers.com/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://noopenblockers.com</link>
	<description></description>
	<lastBuildDate>Fri, 06 Jan 2012 21:11:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>From Java to Python</title>
		<link>http://noopenblockers.com/2010/01/13/from-java-to-python/</link>
		<comments>http://noopenblockers.com/2010/01/13/from-java-to-python/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 14:10:29 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Planet Fedora]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://noopenblockers.com/?p=851</guid>
		<description><![CDATA[I&#8217;m not completely sure why, but I&#8217;m a bit embarrassed to admit to Planet Fedora how little my Python experience is; the majority of my experience is in Java. I was able to read and bug fix the Python code in Spacewalk, but I hadn&#8217;t really dug deep into my own project. Now that I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not completely sure why, but I&#8217;m a bit embarrassed to admit to <a href="http://planet.fedoraproject.org/" target="new">Planet Fedora</a> how little my Python experience is; the majority of my experience is in Java. I was able to read and bug fix the Python code in Spacewalk, but I hadn&#8217;t really dug deep into my own project. Now that I&#8217;m not teaching any longer and have some free time (one of my main reasons for quitting), I can finally sit down and dork around with the language. After spending some time working on <a href="http://inventwithpython.com/" target="new">some basic games</a> and a <a href="http://github.com/jdob/ircbot" target="new">simple IRC bot</a>, I figured I&#8217;d step back and think about what the transition from Java to Python has felt like.</p>
<h2>Don&#8217;t Fear The Whitespace</h2>
<p>I constantly hear people mention the indentation in Python as the first thing when talking about moving to the language. Not only is it not as jarring of an experience as people make it out to be, it&#8217;s downright awesome. I&#8217;ve always been compulsive about my code format anyway, so the biggest difference is the lack of curly braces.</p>
<h2>Collections Are Awesome</h2>
<p>It&#8217;s much lighter-weight to throw things into a list or map (dictionary in Python) than it is in Java. Get out of the mentality that you have to jump through import hoops and rigid notation to create, access, or return collections. In Python, they even let you do cool things like assign multiple variables as a return from a call:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">exceptionType, exceptionValue, exceptionTraceback = <span style="color: #dc143c;">sys</span>.<span style="color: black;">exc_info</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<h2>Looping Feels Weird At First</h2>
<p>I got a little thrown off by this initially. Most loops read really well:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">for</span> square <span style="color: #ff7700;font-weight:bold;">in</span> openSquares:</pre></div></div>

<p>However, when looping through a set of numbers, you need to use the <code>range</code> method:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>:</pre></div></div>

<p>Looking at both of those examples brings me to my next point&#8230;</p>
<h2>Don&#8217;t Forget The Colon</h2>
<p>This keeps throwing me off, but after declaring a function*, loop, or if statement, don&#8217;t forget to end the line with a colon. I&#8217;m happy to be rid of curly braces, but I get over-ambitious and forget the colon too.</p>
<h2>Don&#8217;t Over-engineer Configuration</h2>
<p>Depending on what you&#8217;re doing, you can likely just stuff configuration values into a script and import it (not needing to compile really is liberating in this respect). That&#8217;ll also give you the use of lists and maps by default. If you&#8217;re not reading between the lines I&#8217;ll spell it out: no need for XML-based configuration, which is one of the more evil trends in Java.<br />
<br/><br />
There are definitely more things I could mention; don&#8217;t take this to be the only lessons I&#8217;ve learned (any other hints/tips are appreciated). But I do want to avoid a mammoth blog post that causes readers to go into a zombie-like trance, so I&#8217;ll stop it here for now. I do want to thank <a href="http://rm-rf.ca/" target="new">Devan (dgoodwin)</a> and <a href="http://zeusville.wordpress.com/" target="new">Jesus (zeus)</a> for dealing with the Java-veteran-turned-Python-noob and not finding a way to crash my chat client to avoid more questions. </p>
<p>* I haven&#8217;t seen a solid explanation of &#8220;Call them &#8216;functions&#8217; because you&#8217;ll sound like a Java guy calling them &#8216;methods&#8217;&#8221;, but this feels like something where using the wrong term will make me stand out as a Java developer in a Python world. So I&#8217;ve been <a href="http://rm-rf.ca/" target="new">advised</a> to take a militant approach of &#8220;Yes, I&#8217;m a Java guy learning Python, deal with the occasional terminology missteps.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://noopenblockers.com/2010/01/13/from-java-to-python/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Comment of the Day: Yes, we do</title>
		<link>http://noopenblockers.com/2009/05/13/comment-of-the-day-yes-we-do/</link>
		<comments>http://noopenblockers.com/2009/05/13/comment-of-the-day-yes-we-do/#comments</comments>
		<pubDate>Wed, 13 May 2009 20:03:27 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
				<category><![CDATA[Comment of the Day]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://noopenblockers.com/?p=572</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 try &#123; String line = input.readLine&#40;&#41;; while &#40;line != null&#41; &#123; line = input.readLine&#40;&#41;; &#125; &#125; catch &#40;IOException ioe&#41; &#123; logger.debug&#40;&#34;IOException...really need better handling here&#34;&#41;; &#125; Everyone, at one point or another, is guilty for just swallowing an exception. Java tends to be a bit trigger [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span> line <span style="color: #339933;">=</span> input.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>line <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        line <span style="color: #339933;">=</span> input.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> ioe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;IOException...really need better handling here&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Everyone, at one point or another, is guilty for just swallowing an exception. Java tends to be a bit trigger happy with its checked exceptions (especially in the IO packages), so it&#8217;s inevitable to be in a position of having to deal with an exception that admittedly will probably not happen while trying to get something else accomplished.</p>
<p>The nice part is that I&#8217;m cleaning this up and actually providing the better handling. The cool part is that I&#8217;m using code I wrote for CodeTurtle to do it.  <img src='http://noopenblockers.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://noopenblockers.com/2009/05/13/comment-of-the-day-yes-we-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

