#52WeeksOfCode Week 4 – Python

Week: 4

 Language: Python

 IDE(s): Komodo Edit

Background:

There are programmers and then there are programming nerds. (I use the term ‘nerds’ affectionately as I consider them to be my people.). Python is a scripting language created by and for programming nerds. (Note that his is not necessarily a problem.) This attitude is exemplified by the document PEP 20 – The Zen of Python.

The philosophy of the language is encapsulated into 20 zen-like aphorisms (only 19 of which have been written down):

  • Beautiful is better than ugly.
  • Explicit is better than implicit.
  • Simple is better than complex.
  • Complex is better than complicated.
  • Flat is better than nested.
  • Sparse is better than dense.
  • Readability counts.
  • Special cases aren’t special enough to break the rules.
  • Although practicality beats purity.
  • Errors should never pass silently.
  • Unless explicitly silenced.
  • In the face of ambiguity, refuse the temptation to guess.
  • There should be one– and preferably only one –obvious way to do it.
  • Although that way may not be obvious at first unless you’re Dutch.
  • Now is better than never.
  • Although never is often better than *right* now.
  • If the implementation is hard to explain, it’s a bad idea.
  • If the implementation is easy to explain, it may be a good idea.
  • Namespaces are one honking great idea — let’s do more of those!

Geeky mysticism aside, Python was designed with a very simple, clear, English-like syntax (making it one of the easiest languages to learn). In fact, our standard HelloWorld program can be written with one line:

print 'Hello, world!'

But it’s also very extensible, not only by making the addition of functionality very easy as well as allowing the user to modify or re-implement even pre-defined functionality. If I don’t like the way a built-in method or object works, I can just re-define it. This makes Python very scalable, suitable for use in small one-off scripts to large, complex projects. Python runs on multiple computer platforms and has been ported to other language frameworks including Java and .NET.

Anyway, back to this week’s code. Unfortunately (or not, depending on your point of view) with Python I’m really spoiled for choice. There is plenty of documentation available so there only remains to figure out what I want to do with it. (This is the hardest part of picking up a programming language, by the way – coming up with a project idea.)

I’d like to keep up my tradition of building on the ‘Hello World’ canon. In addition, I have to make it simple in order to make my self-imposed deadline and still keep my title as World’s Slowest Coder (™). Not only that but despite the fact that I can use a simple text editor to write my program I decided to try out the free cross-platform IDE Komodo Edit.

Using my personal mantra of “If you’re not sure how to start, do the dumbest thing you can think of that gets you at least part of what you want.”

(Granted, as personal mantras go, it’s not quite up to the standard of ‘Just do it.’)

So I whipped up a quick script that has the word ‘Hello’ sneak up on ‘World’ and swallow it. Here’s the code, if anyone is interested. It’s pretty crappy but it doesn’t require anything apart from the standard Python installation. (I will likely jazz it up in future however, since it’s kind of fugly as it currently stands.)

Epilogue:

I had some trouble finding a hook for this week’s challenge. But as I dug into the subject, I was reminded that while there is a rigorous scientific and mathematical foundation to computing, this is mixed with a combination of mysticism, spirituality and philosophy. Software is at its heart a pure product of mind, where a programmer can create their own worlds. But to create a programming language is to create your own universe, where you set all of the rules.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s