War of the programming syntax II

I recently wrote a comparison of two popular and powerful scripting languages, Groovy and Python. In my example I walked a directory recursively printing out all of the files found. A couple of people (not related to me or employed by my company) decided to highlight a better approach. So I now present to you both examples revised: (Note the example is entirely trivial and not an accurate depiction of the power of either language rather it is a way for me to waste extra minutes on a task that is in no way related to my current project.)


import os
for root, dirs, files in os.walk('/home/ccc/apps/Warrior'):
    for file in files:
             print file


def listAllFiles = { path ->
  new File(path).eachFileRecurse { if (it.file) println it }
listAllFiles '/home/ccc/jedit/4.2'

From those examples I can see how the groovy version could be done in a one-liner but I didn’t post it that way because I would appear biased. I’m sure the Python example could be a one liner as well but since this is like only the second Python script I’ve ever written I couldn’t figure it out. The moral to the story is: both languages are bad as hell so use which ever one you’re most comfortable with.

2 thoughts on “War of the programming syntax II

  1. I don’t think the python script could be done in one line, as the whitespace has semantic value. But then, python prides itself on ensuring readability – so one liners are kinda discouraged.

  2. Understood. One-liners are many times indicative of “clever-code” and can take away from readability. Though not all one-liners should be considered harmful. I must admit that I do like the Python appraoch. For some reason, it just “feels” smooth. I can’t put my finger on it.

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s