On My Language Beating up Your Language

Three semesters ago, when I began working as an adjunct, I was faced with a choice. I could start teaching my intro to programming course using the language and tools with which I was most comfortable (C#, VS.NET) or I could reuse the syllabus, quizzes, assignments and homeworks of the course as it had been taught in the prior semester (Python, Eclipse). I opted for the latter. Learning a new language seemed a more practical endeavor than learning to write a college course.

Since I’ve been working working with Python, I’ve started to let go of the “my language can beat up your language” attitude I’d held since leaving VB for C#. Of course C# can definitely beat up VB.NET, but I digress… As useful as type safety is, I no longer believe that it makes me a better person. I’ve grown very comfortable with writing code that is far less explicit than SomeClass sc = new SomeClass();.

I’ve been digging Python for some time now and have adopted IronPython as my favorite way to make my .NET apps extensible. Lately I’ve also been looking into Ruby. It’s clearly the product of a serious psychosis, but it’s proving to be a fascinating language. From strings to symbols to blocks, Ruby is just different enough to make learning a language exciting again.

Over the next few months as I continue my Python and Ruby exploration, I’ll share what I consider to be some of the more unique features that make these languages worth a look. I’ll end this post with one of my favorite features in Python – the else clause in while loops. Consider the following contrived example:

response = ""
while response != "valid":
     response = raw_input("Please enter a valid response: ")
else:
     print "Thank you for your valid response"

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

2 Responses to On My Language Beating up Your Language

  1. Ori Peleg says:

    Isn’t the code equivalent to the following?


    response = ""
    while response != "valid":
    response = raw_input("Please enter a valid response: ")
    print "Thank you for your valid response"

    I thought the else clause for loops was only relevant with break statements.

  2. I agree. My sample would have been better with a break…


    response = ""
    max_attempts = 3
    tries = 0
    while response != "valid":
        tries += 1
        if tries > max_attempts:
            print "Invalid response, you have no more attempts."
            break
        response = raw_input("Please enter a valid response: ").strip()
    else:
        print "Thank you for your valid response"

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">