IronPython's niche

Embedding and interaction are key themes

I was right. When I spoke last night at the Houston Dynamic Language User Group , I learned more than the audience.

More precisely, I'll be reporting back for at least the next week with ideas that I picked up at the meeting. Most striking was that, despite all the advances in IDEs and methodologies and technologic conveniences, programmers like interactive keyboard sessions. Apparently we don't yet have a better way to work out, "how do you ...?", and how-tos are of course what whets our appetite.

Suppose you wanted a feel for use of Microsoft's XAML, and how it co-operates with programmatic management of WPF attributes. Starting from zero, you can experience that for yourself in under 10 minutes with IronPython.

An example console session

IronPython's basic download is available at no charge, of course, and well under 8 megabytes as of this writing; its installation adds only a few seconds. Launch the console, and start typing (lines that begin with '#' are only comments -- they paraphrase what I said during the meeting):

       # We're going to configure IronPython slightly. 
   import sys
        # We need to tell it where to look for modules.
   T = "/Program Files/ironpython 2.6/Tutorial/"
       # The original code-name for WPF was 'Avalon'.
       # The audience *prefers* 'Avalon'.
    from avalon import *
       # Let's instantiate one window ...
    w = Window()
       # ... and have it come up on the screen.
        # At this point, on our screen are two windows:  the IronPython 
        # console, in which we're typing, and a bare WPF window.
        # The audience immediately wanted to color it blue.  I'm not a 
        # WPF programmer, so I don't know how to do that--but a little
        # Python introspection ...
        # ... soon clued us to a likely candidate:
    w.Background = SolidColorBrush(Colors.Blue)
        # We decorate our blue window:
    w.Title = "An HDLUG example"
        # After more conversation and basic examples, we turn to XAML.
    w.Content = LoadXaml(T + "Calc.xaml")
        # Cool:  now there's a calculator layout in out window.  
        # Let's collect the buttons with a list comprehension.
    buttons = [o for o in Walk(w) if isinstance(o, Button)]
        # Re-draw the calculator for those who've lost their visual acuity.
    for b in buttons:  b.FontSize *= 2
        # ...
calculator screen-shot
calculator screen-shot

REPL "watch-this!" sessions go back at least to the '60s; I keep waiting for our industry to leave them behind. The reality, though, is that a lot of programmers work daily with heavy development environments in which touching a sensitive base class initiates an hour of recompilation. The immediate response of a lightweight console for a nimble language like Python remains intoxicating.

That's not all that IronPython's good for, though; more of the story, tomorrow ...

ITWorld DealPost: The best in tech deals and discounts.
Shop Tech Products at Amazon