{"id":25,"date":"2007-04-22T18:02:08","date_gmt":"2007-04-22T22:02:08","guid":{"rendered":"http:\/\/hardlikesoftware.com\/weblog\/2007\/04\/22\/i-like-python\/"},"modified":"2007-04-22T18:02:08","modified_gmt":"2007-04-22T22:02:08","slug":"i-like-python","status":"publish","type":"post","link":"https:\/\/hardlikesoftware.com\/weblog\/2007\/04\/22\/i-like-python\/","title":{"rendered":"I Like Python"},"content":{"rendered":"<p>I recently started learning <a href=\"http:\/\/www.python.org\/\">Python<\/a> and to my surprise find it to be a very nice language.<\/p>\n<p>I had heard good things about it years ago but never gave it a look. I noticed that Joel Spolsky gave Python <a href=\"http:\/\/www.joelonsoftware.com\/items\/2006\/09\/01.html\">half credit<\/a> as a safe choice of language to develop enterprise applications in. Still, I was (and still am) <a href=\"http:\/\/hardlikesoftware.com\/weblog\/2006\/12\/01\/why-i-like-working-with-java-more-than-net\/\"> happy working in Java<\/a>.<\/p>\n<p>What prompted me to look at Python is my new Job. I now work at <a href=\"http:\/\/www.bea.com\/\">BEA<\/a>. The BEA WebLogic Server has a tool for configuring and managing domains called WebLogic Scripting Tool (WLST). WLST is based on <a href=\"http:\/\/www.jython.org\/Project\/\">Jython<\/a> (Jython is Python implemented in Java). <\/p>\n<p>I started reading a Python tutorial. The first thing I noticed is that code blocks are identified by indenting. This seemed very strange and uncomfortable after years of using curly brackets. Now it makes sense to me. I was going to indent my code anyway so why shouldn&#8217;t the language make use of that fact. A side benefit is no more arguing over if the curly brackets belong on the same line or a new line. If arguing about code style floats your boat be comforted that you can still argue over how many spaces to indent.<\/p>\n<p>So far I have created two small utility programs in Python. One gathers some information about files and outputs an XML file. The other processes an XML file using <a title=\"Simple API for XML\" href=\"http:\/\/en.wikipedia.org\/wiki\/SAX\">SAX<\/a> and outputs a new XML file. (I didn&#8217;t use <abbr title=\"Extensible Stylesheet Language Transformations\">XSLT<\/abbr> because I needed to write files, run a program and include it&#8217;s output as new element content.) Even with the learning curve I was able to write these programs faster then I could have in Java. Also the code is much smaller than their Java counter parts would be. <\/p>\n<p>Some things I like about Python:<\/p>\n<ul>\n<li>Simple but powerful syntax is quick and easy to learn. It seems to me to be minimally complete. In other words it doesn&#8217;t have lots of unnecessary junk.<\/li>\n<li>Very good documentation including tutorials.<\/li>\n<li>The interactive interpreter makes it easy to try things out. This facilitates learning.<\/li>\n<li>Like JavaScript, Python has a syntax for creating rich literal data structures. It is so much easier to do this:<br \/>\n<code>fruit = { \"apples\": [ \"Cortland\", \"Braeburn\"], 'pears': [ \"Bartlett\", \"Bosc\" ] }<\/code><\/p>\n<p>Than it is to do this:<br \/>\n<code><br \/>\n\tHashMap fruit = new HashMap();<br \/>\n\tArrayList apples = new ArrayList();<br \/>\n\tapples.add(\"Cortland\");<br \/>\n\tapples.add(\"Braeburn\");<br \/>\n\tArrayList pears = new ArrayList();<br \/>\n\tpears.add(\"Bartlett\");<br \/>\n\tpears.add(\"Bosc\");<br \/>\n\tfruit.put(\"apples\", apples);<br \/>\n\tfruit.put(\"pears\", pears);<br \/>\n<\/code>\n  <\/li>\n<li>List comprehension &#8211; a concise syntax to make new lists from existing lists without the usual for loop. Example: [ x**2 for x in range(5) ] produces this list: [0, 1, 4, 9, 16]<\/li>\n<li>An extensive standard library of functions and classes.<\/li>\n<li>The map() and reduce() functions.<\/li>\n<\/ul>\n<p>Python will replace Perl as my scripting language of choice. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently started learning Python and to my surprise find it to be a very nice language. I had heard good things about it years&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/hardlikesoftware.com\/weblog\/2007\/04\/22\/i-like-python\/\">Continue reading<span class=\"screen-reader-text\">I Like Python<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/posts\/25"}],"collection":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":0,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"wp:attachment":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}