I'll be giving my now re-tooled introduction to IronPython this evening at the Greater Lansing User Group .Net meeting. Entitled "Getting Started with IronPython", I'll be focusing on the syntax, rules and "gotchas" of IronPython by making comparisons to C# as well as writing lots of code. My end point - if there's enough time -  is to get started on a very simple windows application. Hope to see you there.

Posted by dhawley | with no comments

I gave my Looking Out For IronPython talk at AADND last night which went really well. People were asking questions and genuinely seemed engaged. But as far as knowledge gained is concerned, I think I was the big winner last night. After the meeting had cleared out, Bill Wagner gave me the most in-depth speaking critique I have ever gotten. Typically, the only feedback a speaker gets is a stack of evaluation forms with a bunch of numbers circled and an occasional useful comment. Bill's comments focused not only content, but also pace and physical movement. His comments in summary...

  • Only move to different locations in the room if there is a purpose in doing so. I have a tendency to pace which only distracts the audience from your point. Check out this post by Josh Holmes to hammer home the point. If you have the time, browse his blog in it's entirety. He has a lot to say about public speaking.
  • Posture is important. It magnifies your presence and conveys confidence. Putting your hands in your pockets kills your posture and thus your presence. Even worse, you loose credibility with your audience. Stand tall, keep your hands out of your pockets and use hand gestures only if necessary.
  • It's OK to say, "I don't know," but it's not OK to advertise it (yes, there is irony in this post). When you speak, you become the self-professed expert in the room. In this context, I viewed any question from the audience that I couldn't answer as a failure. Now that I've learned differently, I seemed to have gone too far. I LIKE to talk about the issues I'm trying to solve. Great for personal growth, not so much for presentations. I need to focus on what I know.
  • Looking out for IronPython was intended to be an introductory talk. People are showing-up to learn the basics of IronPython, not to be wowed by what IronPython can do. I spent too too much time on complex examples that had little value to the audience.
  • My talk was structured so that the first half was entirely PowerPoint and the second half was entirely code. This sort of thing can be taxing on an audience's attention span. Do a few slides, show a demo, do some more slides, then do another demo. This breaks things up into smaller, more digestable chunks.
  • Showing an audience something they already know and then morphing it into something new is an effective teaching technique. I did it in Looking out for IronPython and I should consider it for future talks.
  • Humor is risky which is why I have made the conscious decision to stay away from a lot of jokes in my presentations. I did insert one slide that last nights audience found entertaining (earlier audiences did not), but it was directly relevant to my point. My lesson here? Don't plan a joke. If the opportunity comes, jump on it. Otherwise, just be yourself.

Bill's comments were a nudge in the right direction. If I'm really serious about improving though, I need to find the nearest Toastmasters group. All I have to do is find the time!

I know I promised a post of IronPython resources. I'm still compiling my list and hope to have those posted by this weekend.

Posted by dhawley | with no comments

I'll be speaking at the Ann Arbor .NET Developers meeting tomorrow evening starting at 6:30. If you're interested, get there by 6:00 to present a topic of your choosing at the AADND lightning talks. These short presentations (up to 10 minutes) are a great way to ease your way into speaking in front of groups. Even if you have no desire to speak at user groups or conferences, giving an effective presentation to management or your fellow developers has a lot of advantages. Our meeting is held at SRT Solutions, 206 S Fifth Ave Suite 200 in Ann Arbor (click here for a map). Hope to see you there.

Posted by dhawley | with no comments

A while back, I came across this post from the Bitter Coder telling you how to use IronPython with NUnit. It's an interesting approach in that you actually put your *.py files inside of a C# project. Though you won't be able to easily test external IronPython code without using the Hosting APIs, it actually is a great way to introduce Python (and unit testing) into your environment. Of course you'll need to be willing to rip your tests apart as our method of communicating with the DLR languages evolves.

When you download the source code from the Bitter Coder, you'll need to make a couple of tweaks.

  • Rename IronPythonTest.Framework.PythonSuiteAttribute to PythonFixtureAttribute. Make sure you use a refactoring tool (either the one that comes with Visual Studio or a third party tool) so that you can be certain that all instances of PythonSuiteAttribute are changed.
  • I needed to update my nunit.framework reference in the IronPythonTest.Addin project. It may behoove you to update all of your NUnit references to the version you are using.
  • The nunit.framework reference I just mentioned was also set to copy local. This doesn't really hurt, but none of the NUnit libraries are set to do this. It's just aesthetics.
  • There are a couple of references throughout the solution - nunit.addin for one - that can't be found. They seem to be artifacts from an earlier iteration and can be removed.

That should do it. Tip o' the hat to the Bitter Coder.

Posted by dhawley | with no comments

I've been asking myself that question ever since my switch to Gmail, but really that is only one of many changes I've made. Sure, my life with email has been simplified for a number of reasons (backups are simpler, labeling makes email more searchable and my laptop is not nearly as busy) and I'm really excited about it, but my switch also encouraged me to investigate more of Google's offerings.

One item that has really bothered me for quite a while are RSS readers. I've used various readers over the years and I've never been able to adequately fold them into my daily habits. Every reader I've ever used has always required me to explicitly do something to view updated blogs as opposed to simply delivering the news. I want my RSS reader to act like a paperboy, not a newsstand. To my delight - and annoyance - Google Reader works exactly like a paperboy (reliability issues notwithstanding). If I open up Google Reader, all my news appears as a simple list of articles. No searching through feeds for new posts. It's that simple. What's the annoying part? Paperboys don't typically keep the five most recent papers on your doorstep. They keep delivering. It's up to you to get rid of old papers. In my world, an RSS aggregator should afford me the option of telling the paperboy to discard old news. With current tools, I have to separate my feeds from my news to avoid having 2,714 unread items when I get back from vacation.

Yes, I know many aggregators automatically update and some of them can even give me a view that I can acuatlly digest, but can you get them to show-up next to your unread email and upcoming appointments without scrolling or switching tabs? Using iGoogle, you can do exactly that with Google Gadgets. Below is a snapshot of my iGoogle page with my Google Calendar, unread Gmail, Google Reader feeds, several news feeds and a few miscellaneous tools.
iGoogle

Wow! The ability to absorb that amount of information in just a few seconds is simply astounding. Did I mention I can sync my phone directly to Google? All this because I decided to give Gmail a serious look. I can't help but wonder why it took me so long for me so long to switch to Gmail.

Posted by dhawley | with no comments
After my last post, a couple of people recommended GMobileSync, a tool for synchronizing your Windows Mobile 5/6 device with Google Calendar. Unfortunately for me, since GMobileSync does not address contacts I had to keep looking. After a bit of research, I finally landed on GooSync. Not only does it sync my Calendar directly to my phone, but also my Contacts, one of my stickiest requirements. It's not a free service, and maybe even a little steep with a £20 ($40) annual cost. But when all I have to do is click three times (opening the application is two of those clicks) and my Contacts and my Calendar sync, I'm happy. I do have the option of an AutoSync, but I don't have a data plan and don't want any surprises on the company phone bill, so I'll do it via Wi-Fi. It wasn't completely pain free. My initial import would not import any contacts from Outlook that had the same email address in Google. To get around this, I had to delete all of my contacts out of Google before retrying the import. Of course, by doing this, all the contacts were deleted from my phone during my first GooSync operation, proving that GooSync works (and possibly that I don't understand synchronization). The problem was quickly resolved after re-importing into Google and a GooSync sync operation. Whew! Thus far, I'm really happy with GooSync though it hasn't been part of my work life quite yet. That test starts tomorrow. My bigger question is, "will I be OK without email if I don't have internet access?"
Posted by dhawley | with no comments

After years as an Outlook user, I've finally decided that Gmail is the email solution for me. Why? The biggest reason is because I'm tired of running a very resource-intensive application to perform a relatively simple task. Viewing and responding to email is a basic need, not too different than water. For those of you that have city water, you don't think about where your water supply is, it simply comes into your home. Of course, to have this luxury you get no control over the water treatment process. I'm good with this. I have too much to think about in my daily life to be concerned about water. Email is the same. If someone has an application that will allow me to not think about my email delivery system, then I need really need to consider it.

But Gmail's web-based interface is not the only or even best reason for my switch. Google's system of organizing your email is a big improvement. Instead of putting your email into one folder or another, you can apply multiple Labels to any single email. Viewing emails with a specific label requires only a single click. Receiving email is no longer an "event" affecting computer performance. Instead, email just magically appears in your inbox. And, of course, searching your email is a snap.

It's not all roses, however. How do I sync my calendar and my contacts to my phone without Outlook? From what I've found, you really can't. And regardless of the buzz surrounding Web 2.0, RIA, etc., actually writing an email in Outlook is a more pleasant experience than in Gmail.

Of course, I'm still in the honeymoon phase of this switch. Some minor issue that I thought I could live with (syncing comes to mind), may be the pain-point that drives me back to Outlook. Hopefully, that's a blog post I'm not going to write.

Posted by dhawley | with no comments

I stopped down in Toledo on Tuesday to talk to the Northwest Ohio .NET Usergroup about IronPython. The talk went well, though the demo gods frowned upon me during my presentation. It all boiled down to adding my Python installtion to my IronPython path.

import sys sys.path.append("c:\python25\lib") import random

I kept getting a TypeError exception which I had not seen while building my demos. As it turns out, the reason I had not seen them was because I had been running them via Visual Studio using Ctrl+F5 (Start without Debugging) effectively masking the exception. During the demo, I was simply hitting F5 which of course displayed my dirty laundry for all to see. This doesn't solve the problem but certainly explains the behavior change. Though I'm not absolutely sure what the root cause is, I'm almost certain the problem is that I was trying to get code written for CPython to run inside IronPython. This definitely merits a bit more research.

Posted by dhawley | with no comments

Project Euler problem 3 reads as follows:

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?

There are no special Python features here that really require explaining. The logic is also straightforward: find the smallest prime that divides evenly into "number"; reset "number" to number/prime; if prime is greater than the square root of number, you have your answer. Solution works in both Python and IronPython.

def GetNextPrime(allPrimes):
    """Given a sequential list of prime numbers, return 
    the next prime number
    """
    value = allPrimes[-1]
    if value == 2:
        return 3
    
    while True:
        value += 2
        for prime in allPrimes:
            if value % prime == 0:
                break;
        else:
            return value

def Euler003(number = 600851475143):
    # import the square root function, seed the primes list
    # and determine what
    # the largest possible factor
    from math import sqrt
    primes = [2,3]
    limit = sqrt(number)
    
    # if the last prime number exceeds our limit, we're out
    while primes[-1] <= limit:
        for prime in primes:
            if number == prime:
                # if the prime and the number are the same, 
                # we've found our answer. break out of
                # the loop
                return number
            elif number % prime == 0:
                # number isn't prime! largest prime factor
                # will be in number/prime.
                number /= prime
                limit = sqrt(number)
                break
        else:
            # still didn't find number % prime == 0? Maybe
            # we need bigger prime numbers
            while primes[-1] <= limit:
                # get next prime number
                primes.append(GetNextPrime(primes))
                # if number is divisible by next prime number
                if number % primes[-1] == 0:
                    if number == primes[-1]:
                        break
                    number /= primes[-1]
                    limit = sqrt(number)
                    break
    return number

print Euler003()
Posted by dhawley | with no comments
Filed under: ,

for additional comments on this post, see http://www.darrellhawley.com/2008/04/central-ohio-day-of-net-and-what-i-wish.html

First off, the Central Ohio Day of .NET last Saturday (better late than never, right) was a very well done conference as expected. Hats off to Mike Wood, Carey Payette and Jim Holmes (in reverse alphabetical order) for all the hard work they did. Events are NOT easy. For a recap - and a reason to attend/support next years event - check out this video by Andy Erickson. Nice work, Andy!

Once specific thing I'd like to point out about the sessions, was the relatively large number of talks on alternative languages (one session, Why Ruby? by Joe O'Brien, wasn't even specific to .NET). Though it's really refreshing to see sessions that aren't C# or VB.NET, I wonder what talks are going to look like in another 5 years. Will C# still be the default language for demonstrating new tools or will a DLR-based language (VB.NET, IronPython, IronRuby, etc) or F# be equally as dominant? Hmmmm...

I'm rambling.

After my introductory talk on IronPython, I started thinking about a lot of things I wish I had said or demonstrated. Of course, I don't know how I was going to cram more stuff into the allotted one hour and 10 minutes but nonetheless, here is the list of "Things I Wish I Said and Did":

    • I didn't explore an IronPython executable or library with Reflector. When you do, the first thing you notice is that there is SIGNIFICANTLY more code with an IP app than with a similar C# app. This would have made for a nice discussion on choosing the right language for a given job.
    • I didn't spend enough time on the functional portion of Python. I did gave an example using the map() function and I did a bit with reduce(), but I didn't have a lambda or filter() example prepared.
    • Did I forget to mention that IronPython 2 is targeting .NET 2.0? Yup, I did. Kind of important if you were going to try to use Linq with IP.
    • What about the standard libraries? Python is known as a "batteries included" language, but how would you understand that if I didn't show you the libraries?

I know there are a couple of more items that I'm just forgetting at the moment, but this list discusses some big ones. Hopefully, my next talk will give me some more time.

Posted by dhawley | with no comments

Problem number 2 reads "Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million." The resolution to this problem is not quite as simple as the previous one, but it's not far off.

def fib(maxFibNumber):
    a, b = 0, 1
    while a < maxFibNumber:
        if (a % 2 == 0):
            yield a
        a, b = b, a + b

print sum([x for x in fib(4000000)])

This time we can't rely entirely on list comprehension for the answer. We have to define the fib(maxfibnumber) function that will calculate our Fibonacci sequence and return only even those that are even. I modified a Fibonacci function I found at literateprograms.org to do the job. I have to mention one of the little niceties that makes Python so useable: multiple assignment. Multiple assignment describes the technique of assigning - *binding* in Python - two variables simultaneously. We bind "a" and "b" as soon as we enter the "fib" function and then rebind them at the end of the while loop. This is just another way Python can help us with a simple programming idiom.

Posted by dhawley | with no comments
Filed under: ,

Lately a number of posts on Project Euler, a series of predefined mathematical/computer science puzzles, have come to my attention. Bill Wagner has started a series of posts solving the Euler problems in C# and Dustin Campbell has posted one solution in F#. Several of my co-workers at SRT Solutions have been working through solutions in Ruby, Scala and Boo. My contribution will be in Python.

Project Euler problem 1 reads as follow: "Add all the natural numbers below 1000 that are multiples of 3 or 5." Python's list comprehension makes the solution to this problem trivial.

print sum([x for x in range(1,1000) if x%5==0 or x%3==0])

List comprehension is really just shorthand for a loop that sticks a variable into a sequence. In this solution, the loop is represented by the "for x in range(1,1000)" portion of the statement and a condition is added immediately following. The first "x" really just represents any value that is added to the sequence assuming it gets by our condition. Use the built-in "sum(list)" function and we have our answer. Simple, elegant and very readable.

Posted by dhawley | with no comments
Filed under: ,

I *want* to talk about Project Euler, but it's been a few weeks since I last blogged so I feel I obligated to mention a couple of things.

  • Thing 1: I went to PyCon in Chicago. Good time, trip to Chicago aboard Amtrak was surprisingly pleasant, learned a lot, trip home aboard MegaBus was unpleasant (no need for a break 10 minutes from your destination, Ms. Bus Driver. Furthermore, it is important to train your drivers not punch cab drivers - it's apparently illegal).
  • Thing 2: Disappointed in PyCon lightening talks since they were dominated by vendors. To all vendors out there: standing up and talking about the history of your company and how great you are does not get through to people who are expecting technical content. Instead, come prepared to talk about an interesting *technical* topic.
  • Thing 3: If you are writing unit tests, but not doing Test Driven Development, then take a deep breath and just try to start writing your tests first. Yes, I have a lot more test code than production code, but debugging is so much easier and confidence in my code is so much higher. Do it and you'll never look back.
  • Thing 4: The more I write Python, the more I love Python AND the more I appreciate C#. I've been doing a lot of Python posts lately, but I think I need to step back and do a bit of comparison between my two favorite languages.

That more or less covers the past few weeks. Now that I have that out of the way, my next post will not only cover the first Project Euler problem in Python.

Posted by dhawley | with no comments

I just got confirmation that I'll be presenting "Looking Out for IronPython" at Central Ohio Day of .NET on April 19. I gave a talk on WCF at the event last year when it was still the Cincinnati-Dayton Area Code camp and it was really a great experience. Not only am I looking forward to attending this event again, but I'm excited to talk about IronPython. The more I learn about Python, the more excited I get about the language. It's not any single feature that does it for me, but a series of small details. Here's one I just learned at Michipug last week:

   seq = "Central Ohio Day of .NET".split()
   isInSeq = "Ohio" in seq
   print isInSeq
   >>>True

   isInSeq = "Michigan" in seq
   print isInSeq
   >>>False
That code is written exactly the way I think: Is "Ohio" in my sequence? Elegant.
Posted by dhawley | with no comments

I've been playing with IronPython Studio today and I've run into a *small* snag: I can't call any of the functions I write. For instance, I submitted this example to the IPS CodePlex site earlier today:

def add(x,y):
    return x + y

print add(1,2)
When I run the above as part of a console application, I get the following exception:

MissingMethodException was unhandled by user code Method not found: 'Void IronPython.Runtime.Operations.Ops.UpdateTraceBack(IronPython.Runtime.Calls.ICallerContext, System.String, Int32, System.String, Boolean ByRef)'.

Stack Trace: at Program.add$f5(Object x, Object y)
at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1)
at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext context, Object func, Object arg0, Object arg1)
at Program.Initialize() in Program.py:line 6
at IronPython.Runtime.Operations.Ops.ExecuteCompiled(InitializeModule init)

If I simply save the file and run it using ipy, the code works just fine. I just posted this in the discussions forum at CodePlex, so we'll see what comes of it.
Posted by dhawley | with no comments
More Posts Next page »