{End Bracket}

Let My People Code

Charles Petzold

In the 1920s, Hollywood was in trouble. Plagued by scandals and a general perception that the movies had gone too far in portraying sex and violence, there was a distinct danger that the government might step in. The studios responded by creating the Hays Office to police themselves and clean up the silver screen. The Hays Office established rules involving everything from proper language to appropriate displays of affection, and became the main arm of non-governmental censorship of the movies.

Movie writers and directors responded in the mid-1930s by finding creative ways around these restrictions. One such workaround was a new genre called the screwball comedy, which featured romance, slapstick, and wisecracks. There was little danger of lewd kissing in the screwball comedy-the romantic leads were often at odds for much of the movie. Even better, the dialogue was so fast and so hip that the censors couldn't even hear it. The result: classics such as It Happened One Night, Twentieth Century, and Bringing Up Baby-movies that would never have been conceived if writers and directors were free to do whatever their filthy minds desired.

Creativity often blossoms not when there is total freedom, but when severe restrictions limit the creator. Engineers as well as artists are familiar with this concept. When an oxygen tank exploded in Apollo 13 on its way to the moon, great creativity and ingenuity were required to make fixes. The creativity arose directly from the limited materials at hand.

I was reminded of this paradox recently while enjoying some of the most challenging and amusing programming I've ever done-and I wasn't even using a proper programming language! Lately, I've been getting my programming kicks with XAML, the Extensible Application Markup Language that forms a significant part of the Microsoft® Windows® Presentation Foundation.

XAML can access powerful classes in the Windows Presentation Foundation for performing layout and displaying graphics and animations. XAML can even be classified as a declarative programming language. But compared to more familiar programming languages, XAML is missing many basic programming features: There are no loops in XAML, no conditionals, and no way even to add or multiply numbers.

And yet, the more I restricted myself to XAML-only problem-solving-a state of existence I thought of as "living on Planet XAML"-the more creative I got. I realized that I could define composite graphics transforms in XAML that would essentially multiply matrices, thereby providing all the multiplication and addition I needed. And I found that I could simulate arrays in XAML by using a ListBox to hold multiple elements and then index those elements with data bindings.

My proudest achievement came with a XAML clock application. I wanted circular tick marks around the circumference of the clock. Customarily a clock has 12 large tick marks and 48 small tick marks, but without a for loop these tick marks would normally require 60 separate XAML elements. Alas, I just couldn't bring myself to create that much repetitive markup. I moaned over this problem for days until the breakthrough came. I could create precisely the tick marks I wanted by drawing two circles using dotted lines. Not only did it work, but I realized that I had done the job with just two graphics objects rather than the sixty most other clock applications required.

Writing XAML is fun. Writing XAML is challenging. Writing XAML is mind-expanding. But in some people's minds, writing XAML is an aberration. XAML is not supposed to be hand-written. As one Microsoft blogger put it, "XAML is for Tools," and over the months prior to its release, some XAML features have been removed because they were strictly for the benefits of humans rather than tools. Of course, XAML-generating tools such as Visual Studio® and Microsoft Expression® Interactive Designer may stimulate our aesthetic creativity, but they do nothing for our coding creativity.

Will future programmers even bother to learn XAML syntax? Or will they treat it as just "some weird XML stuff" that Visual Studio generates to save the layout of buttons and comboboxes?

Interactive designers and code generators certainly have their place in the modern programmer's arsenal. I'm sure they save lots of time. But let's not forget who we are. We are programmers. We are skilled in the art of writing powerful code. We get our kicks from using minimum code for maximum effect. We can make languages like XAML do things it was never intended to do. We can make it sing.

Charles Petzold is a contributing editor to MSDN Magazine and the author of Applications = Code + Markup: A Guide to the Microsoft Windows Presentation Foundation (Microsoft Press, 2006).