<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>DevHawk</title><link>http://devhawk.net/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Devhawk" /><description>Passion * Technology * Ruthless Competence</description><language>en-us</language><copyright>Harry Pierson</copyright><managingEditor>harry@devhawk.net</managingEditor><lastBuildDate>Mon, 17 May 2010 09:58:42 PDT</lastBuildDate><generator>newtelligence dasBlog 2.0.7226.0</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Devhawk" /><feedburner:info uri="devhawk" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>47.640972</geo:lat><geo:long>-122.033189</geo:long><feedburner:browserFriendly>(Enter a personal message you would like to have appear at the top of your feed.)</feedburner:browserFriendly><item><title>Washington Stealth Lacrosse</title><link>http://devhawk.net/2010/05/17/Washington+Stealth+Lacrosse.aspx</link><category>Indoor Lacrosse</category><category>Sports</category><category>Washington Stealth</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Mon, 17 May 2010 09:58:42 PDT</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,2bdd5c99-733f-4efe-a135-60d4786eca64.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.stealthlax.com/">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" align="right" src="http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs159.snc1/5932_111961876044_93620706044_2350467_25193_n.jpg" width="240" height="107"></img>
          </a>Last
Saturday night, my family and I went with some friends from the neighborhood up to
Everett to catch the <a href="http://www.stealthlax.com/">Washington Stealth</a> in
the <a href="http://www.nll.com">National Lacrosse League</a> Champion’s Cup final.
This was my first indoor lacrosse game, and it was a <a href="http://seattletimes.nwsource.com/html/othersports/2011876936_stealth16.html">doozy</a> -
the Stealth were down four goals with a a minute to go in the third quarter, but scored
eight goals in a row to take the Champions Cup 15-11. After watching my Capitals <a href="http://sports.espn.go.com/nhl/playoffs/2010/columns/story?columnist=burnside_scott&amp;id=5146185">collapse</a> in
the NHL playoffs, it was awesome to see the home team come out on top.
</p>
        <p>
(Side Note, at least the Caps aren’t alone when it comes to embarrassing playoff performances
this year. Boston <a href="http://espn.go.com/nhl/playoffs/2010/matchup/_/teams/bruins-flyers">blew
a 3-0 series lead</a> against Philly and Pittsburg blew a 3-2 series lead against
Montreal <em>and </em><a href="http://espn.go.com/nhl/recap?gameId=300512016">got
beat like a drum</a> in game 7. I’d argue that the Caps performance was still the
most embarrassing of the three, but not by much)
</p>
        <p>
          <img style="margin: 0px 10px 0px 0px; display: inline" align="left" src="http://upload.wikimedia.org/wikipedia/en/thumb/c/cd/NLLLogo.svg/200px-NLLLogo.svg.png" width="132" height="234"></img>As
I said, this was my first indoor lacrosse game. The game is basically ice hockey without
the ice. In fact, the Stealth’s advertising slogan this year was “It’s like hockey…with
balls”. [1] As far as I could tell, the playing area is identical to a hockey rink
except for the no ice thing. Benches, boards, penalty boxes, goal position – all the
same. There are five players + a goalie per side, with lots of line changes and plenty
of hitting. I might not have been to a game before, but I was able to pick up the
basics of strategy and rules just based on the similarity to hockey. 
</p>
        <p>
Since it’s so similar to hockey, it’s probably easier to talk about the things that
are different - like the shot clock. Similar to basketball, in indoor lacrosse you
have a limited amount of time to take a shot or else you lose possession. Maintaining
possession in lacrosse seems easier than in does in hockey, so the shot clock is an
important addition. Otherwise, killing penalties and running out the clock with a
lead would be child’s play once you got possession. But with the shot clock, you can
only chew up thirty seconds at a time.
</p>
        <p>
The combination of the basketball-esque shot clock and hockey-esque line changes creates
for an interesting dynamic, but not always positive. I was expecting there to be more
fast breaks, But instead, unless it’s a clear one-on-none or two-on-one, the breaking
player almost always pulls up and waits for the line change to finish – often going
off himself. There are line changes in hockey, but it’s rare for a guy in the offensive
zone to be able to just hold onto the puck and wait for the rest of the team to line
change.
</p>
        <p>
On the other hand, I really liked how indoor lacrosse doesn’t have constant face-offs
like hockey does. Face offs in indoor lacrosse are only to start quarters and after
goals. Otherwise, when the ball goes out of play or there’s a penalty, there are simple
possession rules to determine who gets the ball. Face-offs are exciting, and they
happen often enough given the amount of scoring in indoor lacrosse (26 goals total
Sat. night, which was close to the season average for the Stealth of 24.375 total
goals scored per game) without being overwhelming (there were 68 face-offs in yesterday’s
Sharks/Hawks game – that’s more than one per minute). 
</p>
        <p>
Of course, having a good game with a come-from-behind victory by the home team certainly
casts the game in the best light. Having a packed house also helped. 8,600 fans there
last night – a sellout – many of whom appeared to be involved in lacrosse leagues
around the Puget Sound area. The friends we went with have a teenage son who plays,
which is how they got into it. Patrick says he wants to learn to play to, so I’m guessing
this won’t be our last Stealth game.
</p>
        <p>
This being primarily a geek blog, I’ll add that both the Stealth and the NLL in general
need to modernize their marketing and fan base building efforts. The Stealth website
is old school to put it mildly – I especially like the full screen ad to buy tickets
for Saturday’s game that still pops up, two days after the game. Lacrosse fans claim
it’s the <a href="http://blog.fortiusone.com/2008/01/24/lacrosse-the-fastest-growing-sport-in-the-country/">fastest
growing sport in the nation</a>, but it gets almost zero media attention. So why not
encourage citizen media by issuing press credentials to fans who blog about the Stealth
like the <a href="http://offwing.com/2006/08/guidelines-for-issuing-press-credentials-to-bloggers">Caps
did a few years ago</a>? Selling NLL TV rights for any significant dollars is a pipe
dream right now, so why not stream the games online? I suspect the main revenue source
for NLL teams is ticket sales and merchandise – streaming the games would be a good
way to push both.
</p>
        <hr></hr>
        <p>
[1] Cute slogan, but the implication that lacrosse players are tougher than hockey
players is ludicrous. NLL season lasts 16 games and the playoff are three rounds of
single elimination. NHL season lasts 82 games and the playoffs are four rounds of
best of seven series.
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=2bdd5c99-733f-4efe-a135-60d4786eca64"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=qfjkwoOV6Sw:kTCMh3g-5PU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=qfjkwoOV6Sw:kTCMh3g-5PU:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=qfjkwoOV6Sw:kTCMh3g-5PU:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=qfjkwoOV6Sw:kTCMh3g-5PU:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=qfjkwoOV6Sw:kTCMh3g-5PU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=qfjkwoOV6Sw:kTCMh3g-5PU:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/qfjkwoOV6Sw" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
&lt;a href="http://www.stealthlax.com/"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" align="right" src="http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs159.snc1/5932_111961876044_93620706044_2350467_25193_n.jpg" width="240" height="107" /&gt;&lt;/a&gt;Last
Saturday night, my family and I went with some friends from the neighborhood up to
Everett to catch the &lt;a href="http://www.stealthlax.com/"&gt;Washington Stealth&lt;/a&gt; in
the &lt;a href="http://www.nll.com"&gt;National Lacrosse League&lt;/a&gt; Champion’s Cup final.
This was my first indoor lacrosse game, and it was a &lt;a href="http://seattletimes.nwsource.com/html/othersports/2011876936_stealth16.html"&gt;doozy&lt;/a&gt; -
the Stealth were down four goals with a a minute to go in the third quarter, but scored
eight goals in a row to take the Champions Cup 15-11. After watching my Capitals &lt;a href="http://sports.espn.go.com/nhl/playoffs/2010/columns/story?columnist=burnside_scott&amp;amp;id=5146185"&gt;collapse&lt;/a&gt; in
the NHL playoffs, it was awesome to see the home team come out on top.
&lt;/p&gt;
&lt;p&gt;
(Side Note, at least the Caps aren’t alone when it comes to embarrassing playoff performances
this year. Boston &lt;a href="http://espn.go.com/nhl/playoffs/2010/matchup/_/teams/bruins-flyers"&gt;blew
a 3-0 series lead&lt;/a&gt; against Philly and Pittsburg blew a 3-2 series lead against
Montreal &lt;em&gt;and &lt;/em&gt;&lt;a href="http://espn.go.com/nhl/recap?gameId=300512016"&gt;got
beat like a drum&lt;/a&gt; in game 7. I’d argue that the Caps performance was still the
most embarrassing of the three, but not by much)
&lt;/p&gt;
&lt;p&gt;
&lt;img style="margin: 0px 10px 0px 0px; display: inline" align="left" src="http://upload.wikimedia.org/wikipedia/en/thumb/c/cd/NLLLogo.svg/200px-NLLLogo.svg.png" width="132" height="234" /&gt;As
I said, this was my first indoor lacrosse game. The game is basically ice hockey without
the ice. In fact, the Stealth’s advertising slogan this year was “It’s like hockey…with
balls”. [1] As far as I could tell, the playing area is identical to a hockey rink
except for the no ice thing. Benches, boards, penalty boxes, goal position – all the
same. There are five players + a goalie per side, with lots of line changes and plenty
of hitting. I might not have been to a game before, but I was able to pick up the
basics of strategy and rules just based on the similarity to hockey. 
&lt;/p&gt;
&lt;p&gt;
Since it’s so similar to hockey, it’s probably easier to talk about the things that
are different - like the shot clock. Similar to basketball, in indoor lacrosse you
have a limited amount of time to take a shot or else you lose possession. Maintaining
possession in lacrosse seems easier than in does in hockey, so the shot clock is an
important addition. Otherwise, killing penalties and running out the clock with a
lead would be child’s play once you got possession. But with the shot clock, you can
only chew up thirty seconds at a time.
&lt;/p&gt;
&lt;p&gt;
The combination of the basketball-esque shot clock and hockey-esque line changes creates
for an interesting dynamic, but not always positive. I was expecting there to be more
fast breaks, But instead, unless it’s a clear one-on-none or two-on-one, the breaking
player almost always pulls up and waits for the line change to finish – often going
off himself. There are line changes in hockey, but it’s rare for a guy in the offensive
zone to be able to just hold onto the puck and wait for the rest of the team to line
change.
&lt;/p&gt;
&lt;p&gt;
On the other hand, I really liked how indoor lacrosse doesn’t have constant face-offs
like hockey does. Face offs in indoor lacrosse are only to start quarters and after
goals. Otherwise, when the ball goes out of play or there’s a penalty, there are simple
possession rules to determine who gets the ball. Face-offs are exciting, and they
happen often enough given the amount of scoring in indoor lacrosse (26 goals total
Sat. night, which was close to the season average for the Stealth of 24.375 total
goals scored per game) without being overwhelming (there were 68 face-offs in yesterday’s
Sharks/Hawks game – that’s more than one per minute). 
&lt;/p&gt;
&lt;p&gt;
Of course, having a good game with a come-from-behind victory by the home team certainly
casts the game in the best light. Having a packed house also helped. 8,600 fans there
last night – a sellout – many of whom appeared to be involved in lacrosse leagues
around the Puget Sound area. The friends we went with have a teenage son who plays,
which is how they got into it. Patrick says he wants to learn to play to, so I’m guessing
this won’t be our last Stealth game.
&lt;/p&gt;
&lt;p&gt;
This being primarily a geek blog, I’ll add that both the Stealth and the NLL in general
need to modernize their marketing and fan base building efforts. The Stealth website
is old school to put it mildly – I especially like the full screen ad to buy tickets
for Saturday’s game that still pops up, two days after the game. Lacrosse fans claim
it’s the &lt;a href="http://blog.fortiusone.com/2008/01/24/lacrosse-the-fastest-growing-sport-in-the-country/"&gt;fastest
growing sport in the nation&lt;/a&gt;, but it gets almost zero media attention. So why not
encourage citizen media by issuing press credentials to fans who blog about the Stealth
like the &lt;a href="http://offwing.com/2006/08/guidelines-for-issuing-press-credentials-to-bloggers"&gt;Caps
did a few years ago&lt;/a&gt;? Selling NLL TV rights for any significant dollars is a pipe
dream right now, so why not stream the games online? I suspect the main revenue source
for NLL teams is ticket sales and merchandise – streaming the games would be a good
way to push both.
&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;
[1] Cute slogan, but the implication that lacrosse players are tougher than hockey
players is ludicrous. NLL season lasts 16 games and the playoff are three rounds of
single elimination. NHL season lasts 82 games and the playoffs are four rounds of
best of seven series.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=2bdd5c99-733f-4efe-a135-60d4786eca64" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=2bdd5c99-733f-4efe-a135-60d4786eca64</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,2bdd5c99-733f-4efe-a135-60d4786eca64.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,2bdd5c99-733f-4efe-a135-60d4786eca64.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=2bdd5c99-733f-4efe-a135-60d4786eca64</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">3</slash:comments></item><item><title>Weakly Typed Dynamic Languages and Natural Selection</title><link>http://devhawk.net/2010/02/18/Weakly+Typed+Dynamic+Languages+And+Natural+Selection.aspx</link><category>Development</category><category>Development/Lanugages</category><category>Dynamic Languages</category><category>Visual Basic</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Wed, 17 Feb 2010 17:31:35 PST</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,7e10e7c7-af7c-494d-aab5-eba47d58d67f.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’m not reading much in the way of blogs or twitter these days – way to heads down
in my new job for that right now. But I did see Scott Hanselman’s post on <a href="http://www.hanselman.com/blog/BackToBasicsC4MethodOverloadingAndDynamicTypes.aspx">method
overloading and dynamic types</a> and Ted Neward’s follow-on post <a href="http://blogs.tedneward.com/2010/02/14/Dont+Fear+The+DynamicVARIANTReaper.aspx">static-typing
fundamentalism</a>. Even though I’ve moved on from the IronPython team, dynamic typing
is a topic that’s still <a href="http://www.zazzle.com/you_had_me_at_dynamic_shirt-235421109922997983">near
and dear to my heart</a> so I can’t resist throwing in my 2¢.
</p>
        <p>
First off, I agree 100% with Ted’s post - though not the over-the-top mocking tone.
These static &gt; dynamic flame bait comments are so tired that they’ve literally
become cliché. I agree with Ted’s points, but by answering fire with fire he’s just
perpetuating the flame war that he claims to be so tired of. I really am tired of
it, so I’m not going to bother to address any of the original anti-dynamic typing
faux-arguments (fauxguments?) nor Ted’s artful and devastatingly mocking takedown
of them.
</p>
        <p>
But I do have a question for any static-typing fundamentalists in the audience: if
static typing is so much better than dynamic typing, then how come dynamically typed
languages are so popular? Doesn’t natural selection apply to type systems?
</p>
        <p>
Those aren’t rhetorical questions. Building software takes time and effort. While
developers often donate time and effort to projects (see: open source) typically they
work for money. That money has to come from somewhere – usually it comes from someone
who needs the software built for some business reason. And the people footing the
bill for software construction demand the highest return on investment they can get.
</p>
        <p>
If dynamic typing or VARIANT (which is actually weak not dynamic typing, but I digress)
really did create “horrific devastation”, wouldn’t that have caused a negative feedback
loop where the business people who actually foot the bills for creating software became
wary and untrusting of using VB as the language of choice for their projects in favor
of strong and statically typed languages that helped developers “make good choices”?
</p>
        <p>
Yet the opposite happened. VB was the most popular programming language in the world
for the better part of a decade. And while VB’s reign at the top is over, I’d argue
that these days the most popular programming languages are PHP and JavaScript, both
of which are weakly typed dynamic languages too. 
</p>
        <p>
Now clearly, popular != better. However, static-typing fundamentalism isn’t an argument
about which way is “better” so much as an argument about which way is “worthy”. But
how can you argue that you’re approach is the only worthy path when the opposite approach
has been so successful? Remember, one developer’s “horrific devastation” might be
another businessman's “successful project because it helped me enter a new market
faster than my competitors”.  
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=7e10e7c7-af7c-494d-aab5-eba47d58d67f"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=NrOeDtgLqmc:wp4k8JMHVq0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=NrOeDtgLqmc:wp4k8JMHVq0:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=NrOeDtgLqmc:wp4k8JMHVq0:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=NrOeDtgLqmc:wp4k8JMHVq0:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=NrOeDtgLqmc:wp4k8JMHVq0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=NrOeDtgLqmc:wp4k8JMHVq0:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/NrOeDtgLqmc" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
I’m not reading much in the way of blogs or twitter these days – way to heads down
in my new job for that right now. But I did see Scott Hanselman’s post on &lt;a href="http://www.hanselman.com/blog/BackToBasicsC4MethodOverloadingAndDynamicTypes.aspx"&gt;method
overloading and dynamic types&lt;/a&gt; and Ted Neward’s follow-on post &lt;a href="http://blogs.tedneward.com/2010/02/14/Dont+Fear+The+DynamicVARIANTReaper.aspx"&gt;static-typing
fundamentalism&lt;/a&gt;. Even though I’ve moved on from the IronPython team, dynamic typing
is a topic that’s still &lt;a href="http://www.zazzle.com/you_had_me_at_dynamic_shirt-235421109922997983"&gt;near
and dear to my heart&lt;/a&gt; so I can’t resist throwing in my 2¢.
&lt;/p&gt;
&lt;p&gt;
First off, I agree 100% with Ted’s post - though not the over-the-top mocking tone.
These static &amp;gt; dynamic flame bait comments are so tired that they’ve literally
become cliché. I agree with Ted’s points, but by answering fire with fire he’s just
perpetuating the flame war that he claims to be so tired of. I really am tired of
it, so I’m not going to bother to address any of the original anti-dynamic typing
faux-arguments (fauxguments?) nor Ted’s artful and devastatingly mocking takedown
of them.
&lt;/p&gt;
&lt;p&gt;
But I do have a question for any static-typing fundamentalists in the audience: if
static typing is so much better than dynamic typing, then how come dynamically typed
languages are so popular? Doesn’t natural selection apply to type systems?
&lt;/p&gt;
&lt;p&gt;
Those aren’t rhetorical questions. Building software takes time and effort. While
developers often donate time and effort to projects (see: open source) typically they
work for money. That money has to come from somewhere – usually it comes from someone
who needs the software built for some business reason. And the people footing the
bill for software construction demand the highest return on investment they can get.
&lt;/p&gt;
&lt;p&gt;
If dynamic typing or VARIANT (which is actually weak not dynamic typing, but I digress)
really did create “horrific devastation”, wouldn’t that have caused a negative feedback
loop where the business people who actually foot the bills for creating software became
wary and untrusting of using VB as the language of choice for their projects in favor
of strong and statically typed languages that helped developers “make good choices”?
&lt;/p&gt;
&lt;p&gt;
Yet the opposite happened. VB was the most popular programming language in the world
for the better part of a decade. And while VB’s reign at the top is over, I’d argue
that these days the most popular programming languages are PHP and JavaScript, both
of which are weakly typed dynamic languages too. 
&lt;/p&gt;
&lt;p&gt;
Now clearly, popular != better. However, static-typing fundamentalism isn’t an argument
about which way is “better” so much as an argument about which way is “worthy”. But
how can you argue that you’re approach is the only worthy path when the opposite approach
has been so successful? Remember, one developer’s “horrific devastation” might be
another businessman's “successful project because it helped me enter a new market
faster than my competitors”.&amp;#160; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=7e10e7c7-af7c-494d-aab5-eba47d58d67f" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=7e10e7c7-af7c-494d-aab5-eba47d58d67f</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,7e10e7c7-af7c-494d-aab5-eba47d58d67f.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,7e10e7c7-af7c-494d-aab5-eba47d58d67f.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=7e10e7c7-af7c-494d-aab5-eba47d58d67f</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">7</slash:comments></item><item><title>Fixing Powershell&amp;rsquo;s Busted Resolve-Path Cmdlet</title><link>http://devhawk.net/2010/01/22/Fixing+Powershellrsquos+Busted+ResolvePath+Cmdlet.aspx</link><category>PowerShell</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Thu, 21 Jan 2010 23:38:51 PST</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,0f11ab8d-df0d-458c-8ee5-105b1fdedcd3.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Usually, my <a href="http://devhawk.net/CategoryView,category,PowerShell.aspx">PowerShell
posts</a> are effusive in their praise. However, who thought up this “feature” gets
no praise from me:
</p>
        <div style="font-family: consolas,lucida console,courier,monospace">
          <span style="color: #008000; font-weight: bold">PS»</span>
          <span style="color: #19177c; font-weight: bold">Resolve-Path</span> ~\missing.file 
<br><span style="color: red">Resolve-Path : Cannot find path 'C:\Users\hpierson\missing.file'
because it does not exist. </span></div>
        <p>
In my opinion, this is a bad design. Resolve-Path assumes that if the filename being
resolved doesn’t exist, then it must be an error. But in the script I’m building,
I’m resolving the path of a file that I’m going to create. In other words, I know
a priori that the file doesn’t exist. Yet Resolve-Path insists on throwing an error.
I would have expected there to be some switch you could pass to Resolve-Path telling
it to skip path validation, but there’s not.
</p>
        <p>
And the worst thing is, I can see that Resolve-Path came up with the “right” answer
– it’s right there in the error message!
</p>
        <p>
Searching around, I found <a href="http://www.vistax64.com/powershell/24603-resolve-path-non-existing-file.html">a
thread</a> where someone else was having the same problem. Jeffrey Snover – aka Distinguished
Engineer, inventor of Powershell and <a href="http://www.langnetsymposium.com/2009/talks/23-ErikMeijer-LiveLabsReactiveFramework.html">target
of Erik Meijer’s Lang.NET coin throwing stunt</a> – suggested using <a href="http://blogs.msdn.com/powershell/archive/2006/11/03/erroraction-and-errorvariable.aspx">–ErrorAction
and –ErrorVariable</a> to ignore the error and retrieve the resolved path from the
TargetObject property error variable. Like Maximilian from the thread, using this
approach feels fragile and frankly kinda messy, but I needed a solution. So I wrote
the following function that wraps up access to the error variable so at least I don’t
have fragile messy code sprinkled through out my script.  
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:9c646c59-4051-4237-abb4-0d03e3b5e20d" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>function </b>
            </span>force-resolve-path<span style="color:#666666">(</span><span style="color:#19177C">$filename</span><span style="color:#666666">)</span><br><span style="color:#666666">{</span><br>
  <span style="color:#19177C">$filename</span> <span style="color:#666666">=</span> Resolve-Path <span style="color:#19177C">$filename</span> -ErrorAction SilentlyContinue<br>
                                     -ErrorVariable _frperror<br>
  <span style="color:#008000"><b>if</b></span> <span style="color:#666666">(</span>!<span style="color:#19177C">$filename</span><span style="color:#666666">)</span><br>
  <span style="color:#666666">{</span><br>
    <span style="color:#008000"><b>return</b></span> <span style="color:#19177C">$_frperror</span><span style="color:#666666">[</span>0<span style="color:#666666">]</span>.TargetObject<br>
  <span style="color:#666666">}</span><br>
  <span style="color:#008000"><b>return</b></span> <span style="color:#19177C">$filename</span><br><span style="color:#666666">}</span><br></div>
        </div>
        <p>
        </p>
        <p>
The script is pretty straightforward. –ErrorAction SilentlyContinue is PowerShell’s
version of <a href="http://msdn.microsoft.com/en-us/library/5hsw66as.aspx">On Error
Resume Next</a> in Visual Basic. If the cmdlet encounters an error, it gets stashed
away in the variable specified by ErrorVariable (it’s also added to $Error so you
can still retrieve the error object if ErrorVariable isn’t specified) and continues
processing. Then I manually check to see if resolve-path succeeded – i.e. did it return
a value – and return the TargetObject of the Error object if it didn’t. 
</p>
        <p>
As I said, fragile and kinda messy. But it works. 
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=0f11ab8d-df0d-458c-8ee5-105b1fdedcd3"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=xpjUpyr-K2o:hFyKaC9FtiA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=xpjUpyr-K2o:hFyKaC9FtiA:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=xpjUpyr-K2o:hFyKaC9FtiA:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=xpjUpyr-K2o:hFyKaC9FtiA:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=xpjUpyr-K2o:hFyKaC9FtiA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=xpjUpyr-K2o:hFyKaC9FtiA:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/xpjUpyr-K2o" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
Usually, my &lt;a href="http://devhawk.net/CategoryView,category,PowerShell.aspx"&gt;PowerShell
posts&lt;/a&gt; are effusive in their praise. However, who thought up this “feature” gets
no praise from me:
&lt;/p&gt;
&lt;div style="font-family: consolas,lucida console,courier,monospace"&gt;&lt;span style="color: #008000; font-weight: bold"&gt;PS»&lt;/span&gt; &lt;span style="color: #19177c; font-weight: bold"&gt;Resolve-Path&lt;/span&gt; ~\missing.file 
&lt;br /&gt;
&lt;span style="color: red"&gt;Resolve-Path : Cannot find path 'C:\Users\hpierson\missing.file'
because it does not exist. &lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;
In my opinion, this is a bad design. Resolve-Path assumes that if the filename being
resolved doesn’t exist, then it must be an error. But in the script I’m building,
I’m resolving the path of a file that I’m going to create. In other words, I know
a priori that the file doesn’t exist. Yet Resolve-Path insists on throwing an error.
I would have expected there to be some switch you could pass to Resolve-Path telling
it to skip path validation, but there’s not.
&lt;/p&gt;
&lt;p&gt;
And the worst thing is, I can see that Resolve-Path came up with the “right” answer
– it’s right there in the error message!
&lt;/p&gt;
&lt;p&gt;
Searching around, I found &lt;a href="http://www.vistax64.com/powershell/24603-resolve-path-non-existing-file.html"&gt;a
thread&lt;/a&gt; where someone else was having the same problem. Jeffrey Snover – aka Distinguished
Engineer, inventor of Powershell and &lt;a href="http://www.langnetsymposium.com/2009/talks/23-ErikMeijer-LiveLabsReactiveFramework.html"&gt;target
of Erik Meijer’s Lang.NET coin throwing stunt&lt;/a&gt; – suggested using &lt;a href="http://blogs.msdn.com/powershell/archive/2006/11/03/erroraction-and-errorvariable.aspx"&gt;–ErrorAction
and –ErrorVariable&lt;/a&gt; to ignore the error and retrieve the resolved path from the
TargetObject property error variable. Like Maximilian from the thread, using this
approach feels fragile and frankly kinda messy, but I needed a solution. So I wrote
the following function that wraps up access to the error variable so at least I don’t
have fragile messy code sprinkled through out my script.&amp;#160; 
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:9c646c59-4051-4237-abb4-0d03e3b5e20d" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;function&amp;#160;&lt;/b&gt;&lt;/span&gt;force-resolve-path&lt;span style="color:#666666"&gt;(&lt;/span&gt;&lt;span style="color:#19177C"&gt;$filename&lt;/span&gt;&lt;span style="color:#666666"&gt;)&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color:#666666"&gt;{&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&lt;span style="color:#19177C"&gt;$filename&lt;/span&gt;&amp;#160;&lt;span style="color:#666666"&gt;=&lt;/span&gt;&amp;#160;Resolve-Path&amp;#160;&lt;span style="color:#19177C"&gt;$filename&lt;/span&gt;&amp;#160;-ErrorAction&amp;#160;SilentlyContinue&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;-ErrorVariable&amp;#160;_frperror&lt;br /&gt;
&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#666666"&gt;(&lt;/span&gt;!&lt;span style="color:#19177C"&gt;$filename&lt;/span&gt;&lt;span style="color:#666666"&gt;)&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&lt;span style="color:#666666"&gt;{&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#19177C"&gt;$_frperror&lt;/span&gt;&lt;span style="color:#666666"&gt;[&lt;/span&gt;0&lt;span style="color:#666666"&gt;]&lt;/span&gt;.TargetObject&lt;br /&gt;
&amp;#160;&amp;#160;&lt;span style="color:#666666"&gt;}&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#19177C"&gt;$filename&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color:#666666"&gt;}&lt;/span&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
The script is pretty straightforward. –ErrorAction SilentlyContinue is PowerShell’s
version of &lt;a href="http://msdn.microsoft.com/en-us/library/5hsw66as.aspx"&gt;On Error
Resume Next&lt;/a&gt; in Visual Basic. If the cmdlet encounters an error, it gets stashed
away in the variable specified by ErrorVariable (it’s also added to $Error so you
can still retrieve the error object if ErrorVariable isn’t specified) and continues
processing. Then I manually check to see if resolve-path succeeded – i.e. did it return
a value – and return the TargetObject of the Error object if it didn’t. 
&lt;/p&gt;
&lt;p&gt;
As I said, fragile and kinda messy. But it works. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=0f11ab8d-df0d-458c-8ee5-105b1fdedcd3" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=0f11ab8d-df0d-458c-8ee5-105b1fdedcd3</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,0f11ab8d-df0d-458c-8ee5-105b1fdedcd3.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,0f11ab8d-df0d-458c-8ee5-105b1fdedcd3.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=0f11ab8d-df0d-458c-8ee5-105b1fdedcd3</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">2</slash:comments></item><item><title>Job Opening on my Team</title><link>http://devhawk.net/2009/12/07/Job+Opening+On+My+Team.aspx</link><category>Other/Working at MSFT</category><category>Windows</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Mon, 07 Dec 2009 11:49:10 PST</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,8b7ad043-5c02-4753-b59a-c897bce205b5.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’m just starting the third week in my new job – though between Thanksgiving and an
intestinal virus, I’ve only been in my office for five days total so far. That’s not
enough time to establish enough groundwork to be comfortable talking about what my
team is doing yet. However, I just found out we’re still hiring and better yet there’s
a public description of the job opening. So if you’ve ever thought “I want to work
for Microsoft/Windows Division/With Harry”, here’s your chance! And if you aren’t
looking for a new job, at least you can get some small hints as to what I’m doing
in my new gig - “building substantial improvements into the Windows development platform”
sounds interesting, doesn’t it?
</p>
        <blockquote>
          <p>
            <strong>
              <a href="https://careers.microsoft.com/JobDetails.aspx?jid=9986">Senior Program
Manager(708846 -External)</a>
            </strong>
          </p>
          <p>
Job Category: Software Engineering: Program Management 
<br>
Location: United States, WA, Redmond 
<br>
Job ID: 708846 9986 
<br>
Product: Windows  
<br>
Division: Windows Division
</p>
          <p>
Developers! Developers! Developers!
</p>
          <p>
Developers are the key to the success of Windows and at the center of a software ecosystem
that represents hundreds of billions of dollars. Our team is chartered with reinvigorating
the Windows developer ecosystem by building substantial improvements into the Windows
development platform (APIs, tools and the underlying infrastructure) and making developing
for Windows fun!
</p>
          <p>
The team is currently seeking a Senior Program Manager to help us achieve our mission.
The ideal candidate will have:
</p>
          <ul>
            <li>
Strong core PM competencies with special emphasis on developer tools and collaboration
skills.</li>
            <li>
Proven track-record of delivering results in a cross-team (ideally cross-division)
environment. 
</li>
            <li>
Has been a Program Manager shipping key products for at least 6 years.</li>
            <li>
Deep empathy for the developer as a customer; ability to empathize through 1st hand
experience of writing apps some of the issues developers are facing with respect to
APIs, tooling such as Visual Studio and SDK.</li>
            <li>
A demonstrated track record of excellence and delivering in ambiguous V1 situations.</li>
            <li>
Has Bachelors in Computer Science or engineering.</li>
          </ul>
        </blockquote>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=8b7ad043-5c02-4753-b59a-c897bce205b5"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=-3KUfaai87Y:2UCHKDsC1v0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=-3KUfaai87Y:2UCHKDsC1v0:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=-3KUfaai87Y:2UCHKDsC1v0:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=-3KUfaai87Y:2UCHKDsC1v0:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=-3KUfaai87Y:2UCHKDsC1v0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=-3KUfaai87Y:2UCHKDsC1v0:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/-3KUfaai87Y" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
I’m just starting the third week in my new job – though between Thanksgiving and an
intestinal virus, I’ve only been in my office for five days total so far. That’s not
enough time to establish enough groundwork to be comfortable talking about what my
team is doing yet. However, I just found out we’re still hiring and better yet there’s
a public description of the job opening. So if you’ve ever thought “I want to work
for Microsoft/Windows Division/With Harry”, here’s your chance! And if you aren’t
looking for a new job, at least you can get some small hints as to what I’m doing
in my new gig - “building substantial improvements into the Windows development platform”
sounds interesting, doesn’t it?
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;strong&gt;&lt;a href="https://careers.microsoft.com/JobDetails.aspx?jid=9986"&gt;Senior Program
Manager(708846 -External)&lt;/a&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Job Category: Software Engineering: Program Management 
&lt;br /&gt;
Location: United States, WA, Redmond 
&lt;br /&gt;
Job ID: 708846 9986 
&lt;br /&gt;
Product: Windows&amp;#160; 
&lt;br /&gt;
Division: Windows Division
&lt;/p&gt;
&lt;p&gt;
Developers! Developers! Developers!
&lt;/p&gt;
&lt;p&gt;
Developers are the key to the success of Windows and at the center of a software ecosystem
that represents hundreds of billions of dollars. Our team is chartered with reinvigorating
the Windows developer ecosystem by building substantial improvements into the Windows
development platform (APIs, tools and the underlying infrastructure) and making developing
for Windows fun!
&lt;/p&gt;
&lt;p&gt;
The team is currently seeking a Senior Program Manager to help us achieve our mission.
The ideal candidate will have:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Strong core PM competencies with special emphasis on developer tools and collaboration
skills.&lt;/li&gt;
&lt;li&gt;
Proven track-record of delivering results in a cross-team (ideally cross-division)
environment. 
&lt;/li&gt;
&lt;li&gt;
Has been a Program Manager shipping key products for at least 6 years.&lt;/li&gt;
&lt;li&gt;
Deep empathy for the developer as a customer; ability to empathize through 1st hand
experience of writing apps some of the issues developers are facing with respect to
APIs, tooling such as Visual Studio and SDK.&lt;/li&gt;
&lt;li&gt;
A demonstrated track record of excellence and delivering in ambiguous V1 situations.&lt;/li&gt;
&lt;li&gt;
Has Bachelors in Computer Science or engineering.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=8b7ad043-5c02-4753-b59a-c897bce205b5" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=8b7ad043-5c02-4753-b59a-c897bce205b5</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,8b7ad043-5c02-4753-b59a-c897bce205b5.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,8b7ad043-5c02-4753-b59a-c897bce205b5.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=8b7ad043-5c02-4753-b59a-c897bce205b5</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">1</slash:comments></item><item><title>The SOA Manifesto &amp;ndash; Pointlessness Manifested</title><link>http://devhawk.net/2009/10/28/The+SOA+Manifesto+Ndash+Pointlessness+Manifested.aspx</link><category>Architecture</category><category>Architecture/SOA</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Tue, 27 Oct 2009 17:31:37 PDT</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,5b689c6b-a26f-4f71-8a1a-fe2f1e876e42.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.agilemanifesto.org/">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" border="0" align="right" src="http://www.agilemanifesto.org/background.jpg" width="240" height="180"></img>
          </a>You
know what the <a href="http://www.agilemanifesto.org/">Agile Manifesto</a> doesn’t
have? Video of a “very formal ceremony” announcing said manifesto. Instead, we just
have <a href="http://www.agilemanifesto.org/background.jpg">artistically rendered
picture</a> of what sure looks like <a href="http://www.martinfowler.com/">Martin
Fowler</a> pointing at a white board while some of the other original signatories
look on. Sure, it’s a cool picture, but wouldn’t it have been much cooler if they
had captured that moment on video instead? Especially if it was video of them all
standing around looking vaguely uncomfortable while photographers took their picture
and someone gravely read the manifesto to give it artificially inflated importance. 
</p>
        <p>
I only watched ten seconds of the <a href="http://soa-manifesto.org/">SOA Manifesto</a><a href="http://www.youtube.com/watch?v=TCg16oTZSV0">announcement
video</a> before I realized there’s nothing to see here, move along, just a bunch
of navel gazing from the <a href="http://thomaserl.com/">usual SOA suspects</a>. 
</p>
        <p>
Seriously, if you having a big announcement about how cool, earth shattering, significant
or, hell, even interesting your manifesto is, then it’s not any of those things. It’s
a waste of my time.
</p>
        <p>
Then I noticed that my previous manager and personal friend <a href="http://blogs.msdn.com/jdevados/">John
deVadoss</a> is one of the signatories. I have metric tons of respect for John, so
I gave the SOA Manifesto a second chance. 
</p>
        <p>
It lost me at the second sentence. 
</p>
        <blockquote>
          <p>
Service orientation is a paradigm that frames what you do. <strong>Service-oriented
architecture (SOA) is a type of architecture that results from applying service orientation. </strong>We
have been applying service orientation to help organizations consistently deliver
sustainable business value, with increased agility and cost effectiveness, in line
with changing business needs.
</p>
        </blockquote>
        <p>
Are you frakking kidding me? “Service-oriented architecture (SOA) is a type of architecture
that results from applying service orientation.” Who the hell came up with that? I
didn’t realize the <a href="http://soasymposium.com/">International SOA Symposium</a> had
a Department of Redundancy Department. 
</p>
        <p>
When you define SOA in terms of SO, then you can’t possibly score well on the practicality
quotient.
</p>
        <p>
The rest of the manifesto isn’t much better. What made the Agile manifesto great IMO
was that it ran counter to “common” beliefs like “changing requirements late in the
process is bad” and “shipping software cycles should take years”. Sure, we all realize
how right those Agile manifesto guys were <em><u>now</u></em>, but at the time it
was the next best thing to heresy for many organizations. Those guys were agents of
change. And I mean real change, not “this will help me sell books” change.
</p>
        <p>
SOA manifesto on the other hand is basically repackaged common sense. Stuff like “Recognize
that SOA ultimately demands change on many levels” and “The scope of SOA adoption
can vary. Keep efforts manageable and within meaningful boundaries” Any help figuring
out what that change is or what the scope should be? Nope. Thanks for the advice guys,
but I had your so called “Guiding Principles” figured out long ago. 
</p>
        <p>
But hey, I’m sure the manifesto will help Thomas Erl et. al. sell more SOA books.
So, I guess from that perspective it’s mission accomplished.
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=5b689c6b-a26f-4f71-8a1a-fe2f1e876e42"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=fvP9DMqKzU0:lxyPeoNJc0E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=fvP9DMqKzU0:lxyPeoNJc0E:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=fvP9DMqKzU0:lxyPeoNJc0E:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=fvP9DMqKzU0:lxyPeoNJc0E:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=fvP9DMqKzU0:lxyPeoNJc0E:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=fvP9DMqKzU0:lxyPeoNJc0E:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/fvP9DMqKzU0" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
&lt;a href="http://www.agilemanifesto.org/"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" border="0" align="right" src="http://www.agilemanifesto.org/background.jpg" width="240" height="180" /&gt;&lt;/a&gt;You
know what the &lt;a href="http://www.agilemanifesto.org/"&gt;Agile Manifesto&lt;/a&gt; doesn’t
have? Video of a “very formal ceremony” announcing said manifesto. Instead, we just
have &lt;a href="http://www.agilemanifesto.org/background.jpg"&gt;artistically rendered
picture&lt;/a&gt; of what sure looks like &lt;a href="http://www.martinfowler.com/"&gt;Martin
Fowler&lt;/a&gt; pointing at a white board while some of the other original signatories
look on. Sure, it’s a cool picture, but wouldn’t it have been much cooler if they
had captured that moment on video instead? Especially if it was video of them all
standing around looking vaguely uncomfortable while photographers took their picture
and someone gravely read the manifesto to give it artificially inflated importance. 
&lt;/p&gt;
&lt;p&gt;
I only watched ten seconds of the &lt;a href="http://soa-manifesto.org/"&gt;SOA Manifesto&lt;/a&gt; &lt;a href="http://www.youtube.com/watch?v=TCg16oTZSV0"&gt;announcement
video&lt;/a&gt; before I realized there’s nothing to see here, move along, just a bunch
of navel gazing from the &lt;a href="http://thomaserl.com/"&gt;usual SOA suspects&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
Seriously, if you having a big announcement about how cool, earth shattering, significant
or, hell, even interesting your manifesto is, then it’s not any of those things. It’s
a waste of my time.
&lt;/p&gt;
&lt;p&gt;
Then I noticed that my previous manager and personal friend &lt;a href="http://blogs.msdn.com/jdevados/"&gt;John
deVadoss&lt;/a&gt; is one of the signatories. I have metric tons of respect for John, so
I gave the SOA Manifesto a second chance. 
&lt;/p&gt;
&lt;p&gt;
It lost me at the second sentence. 
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Service orientation is a paradigm that frames what you do. &lt;strong&gt;Service-oriented
architecture (SOA) is a type of architecture that results from applying service orientation. &lt;/strong&gt;We
have been applying service orientation to help organizations consistently deliver
sustainable business value, with increased agility and cost effectiveness, in line
with changing business needs.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Are you frakking kidding me? “Service-oriented architecture (SOA) is a type of architecture
that results from applying service orientation.” Who the hell came up with that? I
didn’t realize the &lt;a href="http://soasymposium.com/"&gt;International SOA Symposium&lt;/a&gt; had
a Department of Redundancy Department. 
&lt;/p&gt;
&lt;p&gt;
When you define SOA in terms of SO, then you can’t possibly score well on the practicality
quotient.
&lt;/p&gt;
&lt;p&gt;
The rest of the manifesto isn’t much better. What made the Agile manifesto great IMO
was that it ran counter to “common” beliefs like “changing requirements late in the
process is bad” and “shipping software cycles should take years”. Sure, we all realize
how right those Agile manifesto guys were &lt;em&gt;&lt;u&gt;now&lt;/u&gt;&lt;/em&gt;, but at the time it
was the next best thing to heresy for many organizations. Those guys were agents of
change. And I mean real change, not “this will help me sell books” change.
&lt;/p&gt;
&lt;p&gt;
SOA manifesto on the other hand is basically repackaged common sense. Stuff like “Recognize
that SOA ultimately demands change on many levels” and “The scope of SOA adoption
can vary. Keep efforts manageable and within meaningful boundaries” Any help figuring
out what that change is or what the scope should be? Nope. Thanks for the advice guys,
but I had your so called “Guiding Principles” figured out long ago. 
&lt;/p&gt;
&lt;p&gt;
But hey, I’m sure the manifesto will help Thomas Erl et. al. sell more SOA books.
So, I guess from that perspective it’s mission accomplished.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=5b689c6b-a26f-4f71-8a1a-fe2f1e876e42" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=5b689c6b-a26f-4f71-8a1a-fe2f1e876e42</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,5b689c6b-a26f-4f71-8a1a-fe2f1e876e42.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,5b689c6b-a26f-4f71-8a1a-fe2f1e876e42.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=5b689c6b-a26f-4f71-8a1a-fe2f1e876e42</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">3</slash:comments></item><item><title>IronPython 2.0.3 and 2.6 RC2</title><link>http://devhawk.net/2009/10/27/IronPython+203+And+26+RC2.aspx</link><category>IronPython</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Tue, 27 Oct 2009 14:29:29 PDT</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,a105b675-f06a-4548-a8f3-3525a5b96654.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It has been a very busy week for the IronPython team. Just under a week ago, we shipped
a <a href="http://devhawk.net/2009/10/21/IronPython+And+IronRuby+CTPs+For+NET+40+Beta+2.aspx">CTP
for .NET Framework 4.0</a>. Since then, we’ve shipped two – yes, two! – more versions
of IronPython. Three releases in one week! If we could keep up that pace, we’d be
shipping like 27 more releases of IronPython by the end of the year!
</p>
        <p>
FYI, we’re not going to keep up the pace of shipping three releases a week for the
next two months. We may be a little crazy on the IronPython team, but we’re not THAT
crazy!
</p>
        <p>
Actually, all three of these releases represent fairly small changes in the IronPython
source tree. The .NET 4.0 beta was a CTP, so it’s basically whatever we had in our
main trunk when they forked .NET Framework for the beta. 
</p>
        <p>
          <a href="http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=30416">IronPython
2.0.3</a> is a minor point release in the 2.0 branch (duh). In addition to backporting
some fixes from 2.6, we had to fix an CLR breaking change in partial trust on Windows
7. If you’re using IronPython 2.0.x in partial trust on Windows 7 you *MUST* upgrade
to 2.0.3 (or 2.6 when it’s released). Sorry about that – but it was out of our hands. 
</p>
        <p>
          <a href="http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=34451">IronPython
2.6 RC2</a> is – as you would expect - a minor update over the first release candidate.
There was a memory leak discovered in the hosting APIs which forced us to do a second
release candidate. Since we had to fix that, we took in a few of other fixes including
some standard library changes (we left out json by accident in RC1 and Michael Foord
got logging updated to work better with IronPython so we took the latest version of
it). As per the release notes, we expect this to be the final RC and will re-ship
it as RTM in about a month. Please start using this latest release and let us know
if you find anything.
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=a105b675-f06a-4548-a8f3-3525a5b96654"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=c-8lzy9AXWQ:C4wpam1egaI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=c-8lzy9AXWQ:C4wpam1egaI:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=c-8lzy9AXWQ:C4wpam1egaI:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=c-8lzy9AXWQ:C4wpam1egaI:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=c-8lzy9AXWQ:C4wpam1egaI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=c-8lzy9AXWQ:C4wpam1egaI:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/c-8lzy9AXWQ" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
It has been a very busy week for the IronPython team. Just under a week ago, we shipped
a &lt;a href="http://devhawk.net/2009/10/21/IronPython+And+IronRuby+CTPs+For+NET+40+Beta+2.aspx"&gt;CTP
for .NET Framework 4.0&lt;/a&gt;. Since then, we’ve shipped two – yes, two! – more versions
of IronPython. Three releases in one week! If we could keep up that pace, we’d be
shipping like 27 more releases of IronPython by the end of the year!
&lt;/p&gt;
&lt;p&gt;
FYI, we’re not going to keep up the pace of shipping three releases a week for the
next two months. We may be a little crazy on the IronPython team, but we’re not THAT
crazy!
&lt;/p&gt;
&lt;p&gt;
Actually, all three of these releases represent fairly small changes in the IronPython
source tree. The .NET 4.0 beta was a CTP, so it’s basically whatever we had in our
main trunk when they forked .NET Framework for the beta. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=30416"&gt;IronPython
2.0.3&lt;/a&gt; is a minor point release in the 2.0 branch (duh). In addition to backporting
some fixes from 2.6, we had to fix an CLR breaking change in partial trust on Windows
7. If you’re using IronPython 2.0.x in partial trust on Windows 7 you *MUST* upgrade
to 2.0.3 (or 2.6 when it’s released). Sorry about that – but it was out of our hands. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=34451"&gt;IronPython
2.6 RC2&lt;/a&gt; is – as you would expect - a minor update over the first release candidate.
There was a memory leak discovered in the hosting APIs which forced us to do a second
release candidate. Since we had to fix that, we took in a few of other fixes including
some standard library changes (we left out json by accident in RC1 and Michael Foord
got logging updated to work better with IronPython so we took the latest version of
it). As per the release notes, we expect this to be the final RC and will re-ship
it as RTM in about a month. Please start using this latest release and let us know
if you find anything.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=a105b675-f06a-4548-a8f3-3525a5b96654" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=a105b675-f06a-4548-a8f3-3525a5b96654</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,a105b675-f06a-4548-a8f3-3525a5b96654.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,a105b675-f06a-4548-a8f3-3525a5b96654.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=a105b675-f06a-4548-a8f3-3525a5b96654</wfw:commentRss></item><item><title>Joining Windows</title><link>http://devhawk.net/2009/10/27/Joining+Windows.aspx</link><category>IronPython</category><category>Other/Working at MSFT</category><category>Windows</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Mon, 26 Oct 2009 17:22:43 PDT</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,16570446-12d5-47c1-be94-5a8d1754110a.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Big news in DevHawk land: I’ll be taking on a new role in the <a href="http://www.microsoft.com/windows/">Windows</a> division
after I come back from <a href="http://www.msteched.com/europe/Public/">TechEd Europe</a> (plus
a week vacation visiting my bro-in-law in Germany after TechEd). 
</p>
        <p>
You guys have heard of Windows, right? They just released <a href="http://www.microsoft.com/Windows/windows-7/default.aspx">a
new version</a> recently you might be aware of…Actually, I hear it was <a href="http://seattletimes.nwsource.com/html/microsoftpri0/2010119125_windows_7_launch_microsoft_new_ads_say_windows_was.html">your
idea</a>!
</p>
        <p>
Seriously, I am <em><u>stoked</u></em>to be joining the Windows team. I can’t say
much about the new job beyond a) it’s in Windows Client (as opposed to Windows Server)
and b) I’m working on a team that’s focused on the Windows developer experience. The
Windows team is deep in what you might call “building on teh awesome that is Windows
7” but that they simply call “planning”, so sorry if specifics are kinda sparse. I’ll
be back working for <a href="http://twitter.com/maheshp">Mahesh Prakriya</a>, who
originally hired me into my current role on the IronPython team. Someday I might tell
you the Mahesh PyCon Lego Story, but for now I’ll just say I was great working for
Mahesh the first time and I think this time is going to be even better. 
</p>
        <p>
Working on Windows…focused on developer experience…for Mahesh - It’s like the perfect
storm of work geekdom for me.
</p>
        <p>
Of course, starting a new job means my time on the IronPython team is coming to an
end. As excited as I am about this new opportunity in the Windows division, I’m a
little sad to be leaving Developer Division and the IronPython team. I’ve joked with
audiences that I care about Python because Microsoft pays me to care about Python,
but that’s not completely true. <a href="http://python.org/">Python</a> is a fantastic
language and IronPython’s combination of Python + .NET is hard to beat in my opinion.
IronPython has made significant progress while I’ve been here the last eighteen months
– two major releases (well, 2.6 is almost done), redisting the Python standard library,
Visual Studio 2010 compat - but there’s still much for IronPython to accomplish. And
of course, leaving behind such great teammates like <a href="http://twitter.com/dinoviehland">Dino</a>, <a href="http://twitter.com/davefugate">Dave</a>, <a href="http://twitter.com/jredville">Jim</a> and <a href="http://twitter.com/jschementi">Jimmy</a> is
ALWAYS hard. 
</p>
        <p>
The Windows team is somewhat tighter lipped than the totally transparent approach
we use in IronPython. Not to worry, my evangelism skills were part of the reason I
got the job so you’ll be hearing plenty from me soon enough. However, my posting here
will be kinda sparse until I get my bearings over there. Until then, I’m sure that
you will be absolutely fascinated by non-work-related-but-still-sometimes-geeky minutia
I <a href="http://twitter.com/devhawk">post on Twitter</a>.
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=16570446-12d5-47c1-be94-5a8d1754110a"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=cdg-0GFJTHU:OuyJwrL5PoQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=cdg-0GFJTHU:OuyJwrL5PoQ:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=cdg-0GFJTHU:OuyJwrL5PoQ:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=cdg-0GFJTHU:OuyJwrL5PoQ:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=cdg-0GFJTHU:OuyJwrL5PoQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=cdg-0GFJTHU:OuyJwrL5PoQ:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/cdg-0GFJTHU" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
Big news in DevHawk land: I’ll be taking on a new role in the &lt;a href="http://www.microsoft.com/windows/"&gt;Windows&lt;/a&gt; division
after I come back from &lt;a href="http://www.msteched.com/europe/Public/"&gt;TechEd Europe&lt;/a&gt; (plus
a week vacation visiting my bro-in-law in Germany after TechEd). 
&lt;/p&gt;
&lt;p&gt;
You guys have heard of Windows, right? They just released &lt;a href="http://www.microsoft.com/Windows/windows-7/default.aspx"&gt;a
new version&lt;/a&gt; recently you might be aware of…Actually, I hear it was &lt;a href="http://seattletimes.nwsource.com/html/microsoftpri0/2010119125_windows_7_launch_microsoft_new_ads_say_windows_was.html"&gt;your
idea&lt;/a&gt;!
&lt;/p&gt;
&lt;p&gt;
Seriously, I am &lt;em&gt;&lt;u&gt;stoked&lt;/u&gt; &lt;/em&gt;to be joining the Windows team. I can’t say
much about the new job beyond a) it’s in Windows Client (as opposed to Windows Server)
and b) I’m working on a team that’s focused on the Windows developer experience. The
Windows team is deep in what you might call “building on teh awesome that is Windows
7” but that they simply call “planning”, so sorry if specifics are kinda sparse. I’ll
be back working for &lt;a href="http://twitter.com/maheshp"&gt;Mahesh Prakriya&lt;/a&gt;, who
originally hired me into my current role on the IronPython team. Someday I might tell
you the Mahesh PyCon Lego Story, but for now I’ll just say I was great working for
Mahesh the first time and I think this time is going to be even better. 
&lt;/p&gt;
&lt;p&gt;
Working on Windows…focused on developer experience…for Mahesh - It’s like the perfect
storm of work geekdom for me.
&lt;/p&gt;
&lt;p&gt;
Of course, starting a new job means my time on the IronPython team is coming to an
end. As excited as I am about this new opportunity in the Windows division, I’m a
little sad to be leaving Developer Division and the IronPython team. I’ve joked with
audiences that I care about Python because Microsoft pays me to care about Python,
but that’s not completely true. &lt;a href="http://python.org/"&gt;Python&lt;/a&gt; is a fantastic
language and IronPython’s combination of Python + .NET is hard to beat in my opinion.
IronPython has made significant progress while I’ve been here the last eighteen months
– two major releases (well, 2.6 is almost done), redisting the Python standard library,
Visual Studio 2010 compat - but there’s still much for IronPython to accomplish. And
of course, leaving behind such great teammates like &lt;a href="http://twitter.com/dinoviehland"&gt;Dino&lt;/a&gt;, &lt;a href="http://twitter.com/davefugate"&gt;Dave&lt;/a&gt;, &lt;a href="http://twitter.com/jredville"&gt;Jim&lt;/a&gt; and &lt;a href="http://twitter.com/jschementi"&gt;Jimmy&lt;/a&gt; is
ALWAYS hard. 
&lt;/p&gt;
&lt;p&gt;
The Windows team is somewhat tighter lipped than the totally transparent approach
we use in IronPython. Not to worry, my evangelism skills were part of the reason I
got the job so you’ll be hearing plenty from me soon enough. However, my posting here
will be kinda sparse until I get my bearings over there. Until then, I’m sure that
you will be absolutely fascinated by non-work-related-but-still-sometimes-geeky minutia
I &lt;a href="http://twitter.com/devhawk"&gt;post on Twitter&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=16570446-12d5-47c1-be94-5a8d1754110a" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=16570446-12d5-47c1-be94-5a8d1754110a</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,16570446-12d5-47c1-be94-5a8d1754110a.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,16570446-12d5-47c1-be94-5a8d1754110a.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=16570446-12d5-47c1-be94-5a8d1754110a</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">5</slash:comments></item><item><title>IronPython and IronRuby CTPs for .NET 4.0 Beta 2</title><link>http://devhawk.net/2009/10/21/IronPython+And+IronRuby+CTPs+For+NET+40+Beta+2.aspx</link><category>IronPython</category><category>IronRuby</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Wed, 21 Oct 2009 15:27:16 PDT</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,f7eb4d9e-0459-4fc6-a8be-0dd56f902d9d.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="VS_v_rgb" border="0" alt="VS_v_rgb" align="right" src="http://devhawk.net/content/binary/WindowsLiveWriter/IronPythonandIronRubyCTPsfor.NET4.0Beta2_D952/VS_v_rgb_3.png" width="300" height="117"></img>
          </a> In
case you’ve been hiding under a rock (or maybe just aren’t tracking developments in
the .NET community outside of IronPython), Microsoft <a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx">released
Visual Studio 2010 beta 2</a> this week. Of course for me personally, the most important
feature in Visual Studio 2010 is <a href="http://msdn.microsoft.com/en-us/library/dd264736(VS.100).aspx">C#
4.0 new dynamic type</a> (<a href="http://msdn.microsoft.com/en-us/library/dd537660(VS.100).aspx">also
available in Visual Basic</a>, but since VB already supported some level of late binding
it’s not exactly “new” to VB). 
</p>
        <p>
For those of you who want to experiment with this cool new feature, may I present <a href="http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28125">IronPython
2.6 CTP for .NET 4.0 Beta 2</a>. If you can’t think of any cool things to try with
this new feature, the VB team blog <a href="http://blogs.msdn.com/vbteam/archive/2008/12/17/walkthrough-dynamic-programming-in-visual-basic-10-0-and-c-4-0-lisa-feigenbaum.aspx">has
some scenarios</a> to get your started. 
</p>
        <p>
Also available: <a href="http://ironruby.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=33305">IronRuby
CTP for .NET 4.0 Beta 2</a> if you’re more into gemstones than snakes.
</p>
        <p>
These are preview releases, which means they’ve gone thru basic testing. If you find
any bugs, PLEASE report them via <a href="http://ironpython.codeplex.com/WorkItem/Create.aspx">the
usual channel</a>. I wrote in my Post 2.6 Roadmap post, “we are committed to shipping
the RTM of our .NET 4.0 version the day that Visual Studio 2010 is publicly available”
but that means shaking out the bugs between now and then. We need your help so we’re
ready to go by Visual Studio 2010 launch - March 22, 2010 <a href="http://blogs.msdn.com/somasegar/archive/2009/10/19/announcing-visual-studio-2010-and-net-fx-4-beta-2.aspx">as
per Soma’s blog</a>.
</p>
        <p>
BTW, <a href="http://alcidesfonseca.com">Alcides Fonseca</a> <a href="http://devhawk.net/CommentView,guid,dbf7d543-5a65-4642-a1f0-44f25aa1ff37.aspx#commentstart">suggested</a> we
call this release “IronPython 2.6 N4” since it’s designed to run on .NET Framework
4.0. I like that. What do you think?
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=f7eb4d9e-0459-4fc6-a8be-0dd56f902d9d"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=5op03ATVAuw:Na1n86xIm4A:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=5op03ATVAuw:Na1n86xIm4A:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=5op03ATVAuw:Na1n86xIm4A:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=5op03ATVAuw:Na1n86xIm4A:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=5op03ATVAuw:Na1n86xIm4A:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=5op03ATVAuw:Na1n86xIm4A:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/5op03ATVAuw" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="VS_v_rgb" border="0" alt="VS_v_rgb" align="right" src="http://devhawk.net/content/binary/WindowsLiveWriter/IronPythonandIronRubyCTPsfor.NET4.0Beta2_D952/VS_v_rgb_3.png" width="300" height="117" /&gt;&lt;/a&gt; In
case you’ve been hiding under a rock (or maybe just aren’t tracking developments in
the .NET community outside of IronPython), Microsoft &lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;released
Visual Studio 2010 beta 2&lt;/a&gt; this week. Of course for me personally, the most important
feature in Visual Studio 2010 is &lt;a href="http://msdn.microsoft.com/en-us/library/dd264736(VS.100).aspx"&gt;C#
4.0 new dynamic type&lt;/a&gt; (&lt;a href="http://msdn.microsoft.com/en-us/library/dd537660(VS.100).aspx"&gt;also
available in Visual Basic&lt;/a&gt;, but since VB already supported some level of late binding
it’s not exactly “new” to VB). 
&lt;/p&gt;
&lt;p&gt;
For those of you who want to experiment with this cool new feature, may I present &lt;a href="http://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28125"&gt;IronPython
2.6 CTP for .NET 4.0 Beta 2&lt;/a&gt;. If you can’t think of any cool things to try with
this new feature, the VB team blog &lt;a href="http://blogs.msdn.com/vbteam/archive/2008/12/17/walkthrough-dynamic-programming-in-visual-basic-10-0-and-c-4-0-lisa-feigenbaum.aspx"&gt;has
some scenarios&lt;/a&gt; to get your started. 
&lt;/p&gt;
&lt;p&gt;
Also available: &lt;a href="http://ironruby.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=33305"&gt;IronRuby
CTP for .NET 4.0 Beta 2&lt;/a&gt; if you’re more into gemstones than snakes.
&lt;/p&gt;
&lt;p&gt;
These are preview releases, which means they’ve gone thru basic testing. If you find
any bugs, PLEASE report them via &lt;a href="http://ironpython.codeplex.com/WorkItem/Create.aspx"&gt;the
usual channel&lt;/a&gt;. I wrote in my Post 2.6 Roadmap post, “we are committed to shipping
the RTM of our .NET 4.0 version the day that Visual Studio 2010 is publicly available”
but that means shaking out the bugs between now and then. We need your help so we’re
ready to go by Visual Studio 2010 launch - March 22, 2010 &lt;a href="http://blogs.msdn.com/somasegar/archive/2009/10/19/announcing-visual-studio-2010-and-net-fx-4-beta-2.aspx"&gt;as
per Soma’s blog&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
BTW, &lt;a href="http://alcidesfonseca.com"&gt;Alcides Fonseca&lt;/a&gt;&amp;#160;&lt;a href="http://devhawk.net/CommentView,guid,dbf7d543-5a65-4642-a1f0-44f25aa1ff37.aspx#commentstart"&gt;suggested&lt;/a&gt; we
call this release “IronPython 2.6 N4” since it’s designed to run on .NET Framework
4.0. I like that. What do you think?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=f7eb4d9e-0459-4fc6-a8be-0dd56f902d9d" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=f7eb4d9e-0459-4fc6-a8be-0dd56f902d9d</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,f7eb4d9e-0459-4fc6-a8be-0dd56f902d9d.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,f7eb4d9e-0459-4fc6-a8be-0dd56f902d9d.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=f7eb4d9e-0459-4fc6-a8be-0dd56f902d9d</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">1</slash:comments></item><item><title>Hybrid App Debugging &amp;ndash; The Debug Window</title><link>http://devhawk.net/2009/10/09/Hybrid+App+Debugging+Ndash+The+Debug+Window.aspx</link><category>Debugger</category><category>IronPython</category><category>Lightweight Debugger</category><category>Polyglot</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Fri, 09 Oct 2009 11:18:35 PDT</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,fe530c58-39d6-46d5-ad44-40acd2c1cfdc.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In my <a href="http://devhawk.net/2009/10/09/Hybrid+App+Debugging+Ndash+Threading.aspx">last
installment</a>, I added support for a separate debug window on a separate thread
from the main window thread. That way, I can pause the execution of the main window
while the debug window stays responsive to user input. Now, let’s add some functionality
to the debug window. I’m going to start by showing the source code of the python file
being executed.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:dcfea840-226c-4ee4-b08d-2fc450756d73" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>private</b>
            </span> <span style="color:#008000"><b>void</b></span> <span style="color:#0000FF">OnTraceback</span>(TraceBackFrame frame, <span style="color:#B00040">string</span> result, <span style="color:#B00040">object</span> payload)<br>
{<br>
    FunctionCode code = (FunctionCode)frame.f_code;<br>
    <span style="color:#008000"><b>if</b></span> (_curCode == <span style="color:#008000"><b>null</b></span> || _curCode.co_filename != code.co_filename)<br>
    {<br>
        _source.Inlines.Clear();<br>
        <span style="color:#008000"><b>foreach</b></span> (var line <span style="color:#008000"><b>in</b></span> System.IO.File.ReadAllLines(code.co_filename))<br>
        {<br>
            _source.Inlines.Add(<span style="color:#008000"><b>new</b></span> Run(line + <span style="color:#BA2121">"\r\n"</span>));<br>
        }<br>
    }<br></div>
        </div>
        <p>
The TraceBackFrame instance has a property f_code that represents the FunctionCode
object being executed in this frame. We have to explicitly cast to FunctionCode type
because currently we’re exposing all properties that hang off TraceBackFrame as object
type. Since Python is a dynamic language, we’re going to use reflection against the
instance itself anyway so it doesn’t really matter what the return type is. However,
I’ve asked Dino to change the TraceBackFrame type to use explicit types in order to
make it easier to use SetTrace from statically typed languages like C#. Look for that
in RC2.
</p>
        <p>
After we cast the code object so it can be used from C#, we check to see if the currently
loaded file matches the file currently loaded into the UI. I’ve <a href="http://devhawk.net/2009/07/09/Syntax+Highlighting+TextBoxes+In+WPF+Ndash+A+Sad+Story.aspx">ranted
recently</a> about the limitations of WPF’s TextBox but I didn’t want to get hung
up syntax highlighting for this sample so I just went ahead and used the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx">RichTextBox</a>.
In the DebugWindow Loaded event handler, I create _source as a WPF <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.paragraph.aspx">Paragraph</a> and
then wrap it in a FlowDocument and use it as the RichTextBox’s Document. I set the
FlowDocument to be extremely wide, so as to avoid word wrapping. Then when I need
to load a new source file, I clear _source of it’s current contents and add a single
line run for every line of code in the file. This convention becomes useful later
when I go to highlight the current line of code. 
</p>
        <p>
Once I load the current file, I save the current frame, code, result and payload in
instance fields and then switch on result to determine what to do next. Currently,
I’m just highlighting the relevant line of code and setting a TextBlock control in
the menu bar.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:03ae047a-7cf1-445b-b5ab-78bcbf912b7d" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>private</b>
            </span> <span style="color:#008000"><b>void</b></span> <span style="color:#0000FF">TracebackCall</span>()<br>
{<br>
    dbgStatus.Text = <span style="color:#B00040">string</span>.Format(<span style="color:#BA2121">"Call {0}"</span>, _curCode.co_name);<br>
    HighlightLine((<span style="color:#B00040">int</span>)_curFrame.f_lineno, <br>
        Brushes.LightGreen, Brushes.Black);<br>
}<br><br><span style="color:#008000"><b>private</b></span> <span style="color:#008000"><b>void</b></span> <span style="color:#0000FF">TracebackReturn</span>()<br>
{<br>
    dbgStatus.Text = <span style="color:#B00040">string</span>.Format(<span style="color:#BA2121">"Return {0}"</span>, _curCode.co_name);<br>
    HighlightLine(_curCode.co_firstlineno, <br>
        Brushes.LightPink, Brushes.Black);<br>
}<br><br><span style="color:#008000"><b>private</b></span> <span style="color:#008000"><b>void</b></span> <span style="color:#0000FF">TracebackLine</span>()<br>
{<br>
    dbgStatus.Text = <span style="color:#B00040">string</span>.Format(<span style="color:#BA2121">"Line {0}"</span>, _curFrame.f_lineno);<br>
    HighlightLine((<span style="color:#B00040">int</span>)_curFrame.f_lineno, <br>
        Brushes.Yellow, Brushes.Black);<br>
}<br></div>
        </div>
        <p>
        </p>
        <p>
In Visual Studio, we typically highlight the current line of code in yellow. However,
that doesn’t work as great in a language like Python that delineates code blocks with
whitespace. In ipydbg, I <a href="http://devhawk.net/2009/03/19/Writing+An+IronPython+Debugger+Colorful+Console.aspx">indicated
function return</a> with three carets. But I didn’t want to be modifying the text
in the RichTextBox here so instead I used different colors for the different traceback
event types: light green for call, light pink for return and yellow for line. The
frame object contains the current line number, which I use for call and line, while
the code object has the first line of the current code object, which I use for return.
HighlightLine highlights the line in question with the colors provided and also scrolls
that line into view if it isn’t already visible.
</p>
        <p>
So now when a traceback is handled, it shows the text for the file being executed
and highlights the appropriate line, based on the type of traceback event that happened.
Now all we need is to have some way be able to continue execution. In the code, you’ll
see I’ve <a href="http://github.com/devhawk/LightweightDebuggerDemo/blob/deac85aaf14b37352ce4248917fd857c173d8997/LightweightDebuggerDemo/DebugWindow.xaml.cs#L21">defined
a series</a> of RoutedUICommands for common debugger commands. I’ve got the StepIn
command wired up in the <a href="http://github.com/devhawk/LightweightDebuggerDemo/blob/deac85aaf14b37352ce4248917fd857c173d8997/LightweightDebuggerDemo/DebugWindow.xaml">DebugWindow
XAML</a> to a menu item and the “S” keystroke. All that remains is to define StepInExecuted.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:58f8f796-27f2-414a-9bf3-e4001a05861b" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>private</b>
            </span> <span style="color:#008000"><b>void</b></span> <span style="color:#0000FF">StepInExecuted</span>(<span style="color:#B00040">object</span> sender, ExecutedRoutedEventArgs e)<br>
{<br>
    dbgStatus.Text = <span style="color:#BA2121">"Running"</span>;<br><br>
    <span style="color:#008000"><b>foreach</b></span> (var i <span style="color:#008000"><b>in</b></span> _source.Inlines)<br>
    {<br>
        i.Background = rtbSource.Background;<br>
        i.Foreground = rtbSource.Foreground;<br>
    }<br><br>
    _dbgContinue.Set();<br>
}<br></div>
        </div>
        <p>
This function does three basic things: changes the dbgStatus text, resets all the
text in the RichTextBox back to the default coloring, and sets the _dbgContinue AutoResetEvent
which signals the main window thread that’s been blocked in OnTracebackReceived to
continue.
</p>
        <p>
With this post, I’m about even with the code that’s <a href="http://github.com/devhawk/LightweightDebuggerDemo">up
on GitHub</a>. That code has a few other capabilities – notably it will stop tracing
if you close the debug window and it supports StepOut command which disables traceback
for the current scope by returning null in OnTracebackReceived. But I haven’t implemented
things like:
</p>
        <ul>
          <li>
Set Next Statement</li>
          <li>
Viewing and changing variables</li>
          <li>
Debugger REPL</li>
          <li>
Breakpoint Management</li>
        </ul>
        <p>
Any suggestions on which of those would you like to see next? 
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=fe530c58-39d6-46d5-ad44-40acd2c1cfdc"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=zHp7UN5CGtc:2lUM1bFXrVs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=zHp7UN5CGtc:2lUM1bFXrVs:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=zHp7UN5CGtc:2lUM1bFXrVs:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=zHp7UN5CGtc:2lUM1bFXrVs:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=zHp7UN5CGtc:2lUM1bFXrVs:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=zHp7UN5CGtc:2lUM1bFXrVs:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/zHp7UN5CGtc" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
In my &lt;a href="http://devhawk.net/2009/10/09/Hybrid+App+Debugging+Ndash+Threading.aspx"&gt;last
installment&lt;/a&gt;, I added support for a separate debug window on a separate thread
from the main window thread. That way, I can pause the execution of the main window
while the debug window stays responsive to user input. Now, let’s add some functionality
to the debug window. I’m going to start by showing the source code of the python file
being executed.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:dcfea840-226c-4ee4-b08d-2fc450756d73" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;OnTraceback&lt;/span&gt;(TraceBackFrame&amp;#160;frame,&amp;#160;&lt;span style="color:#B00040"&gt;string&lt;/span&gt;&amp;#160;result,&amp;#160;&lt;span style="color:#B00040"&gt;object&lt;/span&gt;&amp;#160;payload)&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;FunctionCode&amp;#160;code&amp;#160;=&amp;#160;(FunctionCode)frame.f_code;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;&amp;#160;(_curCode&amp;#160;==&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;null&lt;/b&gt;&lt;/span&gt;&amp;#160;||&amp;#160;_curCode.co_filename&amp;#160;!=&amp;#160;code.co_filename)&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;_source.Inlines.Clear();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;foreach&lt;/b&gt;&lt;/span&gt;&amp;#160;(var&amp;#160;line&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;in&lt;/b&gt;&lt;/span&gt;&amp;#160;System.IO.File.ReadAllLines(code.co_filename))&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;_source.Inlines.Add(&lt;span style="color:#008000"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&amp;#160;Run(line&amp;#160;+&amp;#160;&lt;span style="color:#BA2121"&gt;"\r\n"&lt;/span&gt;));&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
The TraceBackFrame instance has a property f_code that represents the FunctionCode
object being executed in this frame. We have to explicitly cast to FunctionCode type
because currently we’re exposing all properties that hang off TraceBackFrame as object
type. Since Python is a dynamic language, we’re going to use reflection against the
instance itself anyway so it doesn’t really matter what the return type is. However,
I’ve asked Dino to change the TraceBackFrame type to use explicit types in order to
make it easier to use SetTrace from statically typed languages like C#. Look for that
in RC2.
&lt;/p&gt;
&lt;p&gt;
After we cast the code object so it can be used from C#, we check to see if the currently
loaded file matches the file currently loaded into the UI. I’ve &lt;a href="http://devhawk.net/2009/07/09/Syntax+Highlighting+TextBoxes+In+WPF+Ndash+A+Sad+Story.aspx"&gt;ranted
recently&lt;/a&gt; about the limitations of WPF’s TextBox but I didn’t want to get hung
up syntax highlighting for this sample so I just went ahead and used the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx"&gt;RichTextBox&lt;/a&gt;.
In the DebugWindow Loaded event handler, I create _source as a WPF &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.paragraph.aspx"&gt;Paragraph&lt;/a&gt; and
then wrap it in a FlowDocument and use it as the RichTextBox’s Document. I set the
FlowDocument to be extremely wide, so as to avoid word wrapping. Then when I need
to load a new source file, I clear _source of it’s current contents and add a single
line run for every line of code in the file. This convention becomes useful later
when I go to highlight the current line of code. 
&lt;/p&gt;
&lt;p&gt;
Once I load the current file, I save the current frame, code, result and payload in
instance fields and then switch on result to determine what to do next. Currently,
I’m just highlighting the relevant line of code and setting a TextBlock control in
the menu bar.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:03ae047a-7cf1-445b-b5ab-78bcbf912b7d" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;TracebackCall&lt;/span&gt;()&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;dbgStatus.Text&amp;#160;=&amp;#160;&lt;span style="color:#B00040"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#BA2121"&gt;"Call&amp;#160;{0}"&lt;/span&gt;,&amp;#160;_curCode.co_name);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;HighlightLine((&lt;span style="color:#B00040"&gt;int&lt;/span&gt;)_curFrame.f_lineno,&amp;#160;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Brushes.LightGreen,&amp;#160;Brushes.Black);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;TracebackReturn&lt;/span&gt;()&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;dbgStatus.Text&amp;#160;=&amp;#160;&lt;span style="color:#B00040"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#BA2121"&gt;"Return&amp;#160;{0}"&lt;/span&gt;,&amp;#160;_curCode.co_name);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;HighlightLine(_curCode.co_firstlineno,&amp;#160;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Brushes.LightPink,&amp;#160;Brushes.Black);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;TracebackLine&lt;/span&gt;()&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;dbgStatus.Text&amp;#160;=&amp;#160;&lt;span style="color:#B00040"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#BA2121"&gt;"Line&amp;#160;{0}"&lt;/span&gt;,&amp;#160;_curFrame.f_lineno);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;HighlightLine((&lt;span style="color:#B00040"&gt;int&lt;/span&gt;)_curFrame.f_lineno,&amp;#160;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Brushes.Yellow,&amp;#160;Brushes.Black);&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
In Visual Studio, we typically highlight the current line of code in yellow. However,
that doesn’t work as great in a language like Python that delineates code blocks with
whitespace. In ipydbg, I &lt;a href="http://devhawk.net/2009/03/19/Writing+An+IronPython+Debugger+Colorful+Console.aspx"&gt;indicated
function return&lt;/a&gt; with three carets. But I didn’t want to be modifying the text
in the RichTextBox here so instead I used different colors for the different traceback
event types: light green for call, light pink for return and yellow for line. The
frame object contains the current line number, which I use for call and line, while
the code object has the first line of the current code object, which I use for return.
HighlightLine highlights the line in question with the colors provided and also scrolls
that line into view if it isn’t already visible.
&lt;/p&gt;
&lt;p&gt;
So now when a traceback is handled, it shows the text for the file being executed
and highlights the appropriate line, based on the type of traceback event that happened.
Now all we need is to have some way be able to continue execution. In the code, you’ll
see I’ve &lt;a href="http://github.com/devhawk/LightweightDebuggerDemo/blob/deac85aaf14b37352ce4248917fd857c173d8997/LightweightDebuggerDemo/DebugWindow.xaml.cs#L21"&gt;defined
a series&lt;/a&gt; of RoutedUICommands for common debugger commands. I’ve got the StepIn
command wired up in the &lt;a href="http://github.com/devhawk/LightweightDebuggerDemo/blob/deac85aaf14b37352ce4248917fd857c173d8997/LightweightDebuggerDemo/DebugWindow.xaml"&gt;DebugWindow
XAML&lt;/a&gt; to a menu item and the “S” keystroke. All that remains is to define StepInExecuted.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:58f8f796-27f2-414a-9bf3-e4001a05861b" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;StepInExecuted&lt;/span&gt;(&lt;span style="color:#B00040"&gt;object&lt;/span&gt;&amp;#160;sender,&amp;#160;ExecutedRoutedEventArgs&amp;#160;e)&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;dbgStatus.Text&amp;#160;=&amp;#160;&lt;span style="color:#BA2121"&gt;"Running"&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;foreach&lt;/b&gt;&lt;/span&gt;&amp;#160;(var&amp;#160;i&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;in&lt;/b&gt;&lt;/span&gt;&amp;#160;_source.Inlines)&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;i.Background&amp;#160;=&amp;#160;rtbSource.Background;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;i.Foreground&amp;#160;=&amp;#160;rtbSource.Foreground;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;_dbgContinue.Set();&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
This function does three basic things: changes the dbgStatus text, resets all the
text in the RichTextBox back to the default coloring, and sets the _dbgContinue AutoResetEvent
which signals the main window thread that’s been blocked in OnTracebackReceived to
continue.
&lt;/p&gt;
&lt;p&gt;
With this post, I’m about even with the code that’s &lt;a href="http://github.com/devhawk/LightweightDebuggerDemo"&gt;up
on GitHub&lt;/a&gt;. That code has a few other capabilities – notably it will stop tracing
if you close the debug window and it supports StepOut command which disables traceback
for the current scope by returning null in OnTracebackReceived. But I haven’t implemented
things like:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Set Next Statement&lt;/li&gt;
&lt;li&gt;
Viewing and changing variables&lt;/li&gt;
&lt;li&gt;
Debugger REPL&lt;/li&gt;
&lt;li&gt;
Breakpoint Management&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Any suggestions on which of those would you like to see next? 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=fe530c58-39d6-46d5-ad44-40acd2c1cfdc" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=fe530c58-39d6-46d5-ad44-40acd2c1cfdc</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,fe530c58-39d6-46d5-ad44-40acd2c1cfdc.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,fe530c58-39d6-46d5-ad44-40acd2c1cfdc.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=fe530c58-39d6-46d5-ad44-40acd2c1cfdc</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">5</slash:comments></item><item><title>Hybrid App Debugging &amp;ndash; Threading</title><link>http://devhawk.net/2009/10/09/Hybrid+App+Debugging+Ndash+Threading.aspx</link><category>Debugger</category><category>IronPython</category><category>Lightweight Debugger</category><category>Polyglot</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Thu, 08 Oct 2009 18:42:38 PDT</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,d69568b9-9021-46d6-aeb4-0e1bb554fbf1.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I <a href="http://devhawk.net/2009/10/07/Hybrid+App+Debugging+Ndash+TracebackDelegate+And+SetTrace.aspx">added
traceback</a> to my GetThings app in just two lines of code, but so far it doesn’t
actually do anything that you would expect a debugger to do. But before we get to
that, we need understand a little about how threading works for traceback debugging.
</p>
        <p>
As I mentioned last time, the traceback debugger works by calling into the registered
traceback handler at various times (entering/exiting a function, before executing
a line of code and on exceptions). Execution of the Python code continues when the
traceback function exits. That means that you have to block the execution thread while
you let the user poke around with the debugger UI. For a console based app, that’s
easy. For a GUI app, not so much.
</p>
        <p>
At a minimum, you need to run your debugger UI on a separate thread from your main
app window. If you want your main app window to be responsive while you debug, you’ll
need to pump messages at a minimum (<a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx">DoEvents</a> in
Windows Forms, <a href="http://social.msdn.microsoft.com/forums/en-US/wpf/thread/a2988ae8-e7b8-4a62-a34f-b851aaf13886">similar
approaches are available</a> for WPF) or preferably run your python scripts on a background
thread separate from either the main window UI thread or the debugger UI thread. To
keep things simple, I’m going to simply block the main window thread while the debugger
is active.
</p>
        <p>
Since I’m going to have to setup a new thread for the debugger window, I decided to
use a static constructor to centralize creating the thread, creating the window and
registering the traceback handler all in one place.
</p>
        <p>
        </p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:5f7cd0e0-2bf2-4bd7-9a08-f107b029bee1" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>static</b>
            </span> Thread _debugThread;<br><span style="color:#008000"><b>static</b></span> DebugWindow _debugWindow;<br><span style="color:#008000"><b>static</b></span> ManualResetEvent _debugWindowReady = <span style="color:#008000"><b>new</b></span> ManualResetEvent(<span style="color:#008000"><b>false</b></span>);<br><br><span style="color:#008000"><b>public</b></span> <span style="color:#008000"><b>static</b></span> <span style="color:#008000"><b>void</b></span> <span style="color:#0000FF">InitDebugWindow</span>(ScriptEngine engine)<br><span style="color:#008000"><b>{</b></span><br>
    _debugThread = <span style="color:#008000"><b>new</b></span> Thread(() =&gt;<br>
    <span style="color:#008000"><b>{</b></span><br>
        _debugWindow = <span style="color:#008000"><b>new</b></span> DebugWindow(engine);<br>
        _debugWindow.Show();<br>
        Dispatcher.Run();<br>
    <span style="color:#008000"><b>}</b></span>);<br>
    _debugThread.SetApartmentState(ApartmentState.STA);<br>
    _debugThread.Start();<br><br>
    _debugWindowReady.WaitOne();<br>
    engine.SetTrace(_debugWindow.OnTracebackReceived);<br><span style="color:#008000"><b>}</b></span><br></div>
        </div>
        <p>
        </p>
        <p>
As you can see, InitDebugWindow spins up a new thread and creates the debug window
on that thread. Since it’s not the main WPF application thread, you have to explicitly
call <a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.run.aspx">Dispatcher.Run</a> to
get the event queue pumping. You also have to explicitly <a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.setapartmentstate.aspx">set
the apartment state</a> to be single threaded for any threads creating WPF objects.
Finally, I wait for the window to signal that it’s ready (it set’s the _debugWindowReady
AutoResetEvent in the Window Loaded event) and then call SetTrace, passing in the
debug window’s OnTracebackReceived event, on the thread that called InitDebugWindow.
</p>
        <p>
It’s critical that you call SetTrace – and thus InitDebugWindow – on the thread that’s
going to execute the Python code. Debugging in Python is <em>per thread</em>. Even
if you execute the same code in the same ScriptScope with the same ScriptEngine but
on a different thread, the traceback handler calls won’t fire. The way DebugWindow
is written, it will only support debugging a single thread, but it would be pretty
straightforward to support multiple threads by changing the way OnTracebackReceived
gets signaled to continue.
</p>
        <p>
Speaking of OnTracebackReceived, this was my initial basic implementation of it:
</p>
        <p>
        </p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:5d65e913-c52d-4aa8-b658-b3a8440c2f9d" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>private</b>
            </span> TracebackDelegate <span style="color:#0000FF">OnTracebackReceived</span><br>
    (TraceBackFrame frame, <span style="color:#B00040">string</span> result, <span style="color:#B00040">object</span> payload)<br><span style="color:#008000"><b>{</b></span><br>
    Action&lt;TraceBackFrame, <span style="color:#B00040">string</span>, <span style="color:#B00040">object</span>&gt; tbAction = <span style="color:#008000"><b>this</b></span>.OnTraceback;<br>
    <span style="color:#008000"><b>this</b></span>.Dispatcher.BeginInvoke(tbAction, frame, result, payload);<br>
    _dbgContinue.WaitOne();<br>
    <span style="color:#008000"><b>return</b></span> <span style="color:#008000"><b>this</b></span>.OnTracebackReceived;<br><span style="color:#008000"><b>}</b></span><br></div>
        </div>
        <p>
        </p>
        <p>
As we saw, the DebugWindow is running on a different thread than the traceback handler
call will come in on. So OnTracebackReceived needs to invoke a new call on the correct
thread by using <a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.begininvoke.aspx">Dispatcher.BeginInvoke</a>.
Even though OnTracebackReceived is always called on the main window thread, it still
has access to the properties of the debug window thread like its Dispatcher. I used
BeginInvoke to invoke OnTraceback asynchronously – OnTraceback isn’t going to return
anything interesting and we’re going to wait on an AutoResetEvent before continuing
anyway so I didn’t see any reason to use a synchronous call. 
</p>
        <p>
We’ll discuss OnTraceback more next post, but basically it will configure the UI for
the traceback event that happened. Then DebugWindow will wait for user input. When
the user indicates they want to resume execution, the command handler in question
will set _dbgContinue and the original traceback will return so execution can continue. 
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=d69568b9-9021-46d6-aeb4-0e1bb554fbf1"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=nQURz_4Y9JA:leL1WorzP6c:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=nQURz_4Y9JA:leL1WorzP6c:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=nQURz_4Y9JA:leL1WorzP6c:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=nQURz_4Y9JA:leL1WorzP6c:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=nQURz_4Y9JA:leL1WorzP6c:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=nQURz_4Y9JA:leL1WorzP6c:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/nQURz_4Y9JA" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
I &lt;a href="http://devhawk.net/2009/10/07/Hybrid+App+Debugging+Ndash+TracebackDelegate+And+SetTrace.aspx"&gt;added
traceback&lt;/a&gt; to my GetThings app in just two lines of code, but so far it doesn’t
actually do anything that you would expect a debugger to do. But before we get to
that, we need understand a little about how threading works for traceback debugging.
&lt;/p&gt;
&lt;p&gt;
As I mentioned last time, the traceback debugger works by calling into the registered
traceback handler at various times (entering/exiting a function, before executing
a line of code and on exceptions). Execution of the Python code continues when the
traceback function exits. That means that you have to block the execution thread while
you let the user poke around with the debugger UI. For a console based app, that’s
easy. For a GUI app, not so much.
&lt;/p&gt;
&lt;p&gt;
At a minimum, you need to run your debugger UI on a separate thread from your main
app window. If you want your main app window to be responsive while you debug, you’ll
need to pump messages at a minimum (&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx"&gt;DoEvents&lt;/a&gt; in
Windows Forms, &lt;a href="http://social.msdn.microsoft.com/forums/en-US/wpf/thread/a2988ae8-e7b8-4a62-a34f-b851aaf13886"&gt;similar
approaches are available&lt;/a&gt; for WPF) or preferably run your python scripts on a background
thread separate from either the main window UI thread or the debugger UI thread. To
keep things simple, I’m going to simply block the main window thread while the debugger
is active.
&lt;/p&gt;
&lt;p&gt;
Since I’m going to have to setup a new thread for the debugger window, I decided to
use a static constructor to centralize creating the thread, creating the window and
registering the traceback handler all in one place.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:5f7cd0e0-2bf2-4bd7-9a08-f107b029bee1" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&amp;#160;Thread&amp;#160;_debugThread;&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&amp;#160;DebugWindow&amp;#160;_debugWindow;&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&amp;#160;ManualResetEvent&amp;#160;_debugWindowReady&amp;#160;=&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&amp;#160;ManualResetEvent(&lt;span style="color:#008000"&gt;&lt;b&gt;false&lt;/b&gt;&lt;/span&gt;);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;InitDebugWindow&lt;/span&gt;(ScriptEngine&amp;#160;engine)&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;_debugThread&amp;#160;=&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&amp;#160;Thread(()&amp;#160;=&amp;gt;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;_debugWindow&amp;#160;=&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&amp;#160;DebugWindow(engine);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;_debugWindow.Show();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Dispatcher.Run();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;_debugThread.SetApartmentState(ApartmentState.STA);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;_debugThread.Start();&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;_debugWindowReady.WaitOne();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;engine.SetTrace(_debugWindow.OnTracebackReceived);&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
As you can see, InitDebugWindow spins up a new thread and creates the debug window
on that thread. Since it’s not the main WPF application thread, you have to explicitly
call &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.run.aspx"&gt;Dispatcher.Run&lt;/a&gt; to
get the event queue pumping. You also have to explicitly &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.setapartmentstate.aspx"&gt;set
the apartment state&lt;/a&gt; to be single threaded for any threads creating WPF objects.
Finally, I wait for the window to signal that it’s ready (it set’s the _debugWindowReady
AutoResetEvent in the Window Loaded event) and then call SetTrace, passing in the
debug window’s OnTracebackReceived event, on the thread that called InitDebugWindow.
&lt;/p&gt;
&lt;p&gt;
It’s critical that you call SetTrace – and thus InitDebugWindow – on the thread that’s
going to execute the Python code. Debugging in Python is &lt;em&gt;per thread&lt;/em&gt;. Even
if you execute the same code in the same ScriptScope with the same ScriptEngine but
on a different thread, the traceback handler calls won’t fire. The way DebugWindow
is written, it will only support debugging a single thread, but it would be pretty
straightforward to support multiple threads by changing the way OnTracebackReceived
gets signaled to continue.
&lt;/p&gt;
&lt;p&gt;
Speaking of OnTracebackReceived, this was my initial basic implementation of it:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:5d65e913-c52d-4aa8-b658-b3a8440c2f9d" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;TracebackDelegate&amp;#160;&lt;span style="color:#0000FF"&gt;OnTracebackReceived&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;(TraceBackFrame&amp;#160;frame,&amp;#160;&lt;span style="color:#B00040"&gt;string&lt;/span&gt;&amp;#160;result,&amp;#160;&lt;span style="color:#B00040"&gt;object&lt;/span&gt;&amp;#160;payload)&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;Action&amp;lt;TraceBackFrame,&amp;#160;&lt;span style="color:#B00040"&gt;string&lt;/span&gt;,&amp;#160;&lt;span style="color:#B00040"&gt;object&lt;/span&gt;&amp;gt;&amp;#160;tbAction&amp;#160;=&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;.OnTraceback;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;.Dispatcher.BeginInvoke(tbAction,&amp;#160;frame,&amp;#160;result,&amp;#160;payload);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;_dbgContinue.WaitOne();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;.OnTracebackReceived;&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
As we saw, the DebugWindow is running on a different thread than the traceback handler
call will come in on. So OnTracebackReceived needs to invoke a new call on the correct
thread by using &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.begininvoke.aspx"&gt;Dispatcher.BeginInvoke&lt;/a&gt;.
Even though OnTracebackReceived is always called on the main window thread, it still
has access to the properties of the debug window thread like its Dispatcher. I used
BeginInvoke to invoke OnTraceback asynchronously – OnTraceback isn’t going to return
anything interesting and we’re going to wait on an AutoResetEvent before continuing
anyway so I didn’t see any reason to use a synchronous call. 
&lt;/p&gt;
&lt;p&gt;
We’ll discuss OnTraceback more next post, but basically it will configure the UI for
the traceback event that happened. Then DebugWindow will wait for user input. When
the user indicates they want to resume execution, the command handler in question
will set _dbgContinue and the original traceback will return so execution can continue. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=d69568b9-9021-46d6-aeb4-0e1bb554fbf1" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=d69568b9-9021-46d6-aeb4-0e1bb554fbf1</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,d69568b9-9021-46d6-aeb4-0e1bb554fbf1.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,d69568b9-9021-46d6-aeb4-0e1bb554fbf1.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=d69568b9-9021-46d6-aeb4-0e1bb554fbf1</wfw:commentRss></item><item><title>Hybrid App Debugging Aside - The DLR Hosting API</title><link>http://devhawk.net/2009/10/07/Hybrid+App+Debugging+Aside+The+DLR+Hosting+API.aspx</link><category>DLR</category><category>Hosting API</category><category>IronPython</category><category>Lightweight Debugger</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Wed, 07 Oct 2009 15:58:15 PDT</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,96e3d1b3-5adc-4e69-b414-e69a6e5a05d0.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In my series on <a href="http://devhawk.net/2009/10/06/Lightweight+Debugging+For+Hybrid+CIronPython+Apps.aspx">Hybrid
App Debugging</a>, I showed the following code for executing a Python file in a hybrid
C#/IronPython app.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:08436bdc-960e-4b10-a9f6-5784d3fdaad4" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>private</b>
            </span> <span style="color:#008000"><b>void</b></span> <span style="color:#0000FF">Window_Loaded</span>(<span style="color:#B00040">object</span> sender, RoutedEventArgs e)<br>
{<br>
    ScriptEngine engine = Python.CreateEngine();<br>
    ScriptScope  scope = engine.CreateScope();<br>
    scope.SetVariable(<span style="color:#BA2121">"items"</span>, lbThings.Items);<br>
    engine.ExecuteFile(<span style="color:#BA2121">"getthings.py"</span>, scope);<br>
}<br></div>
        </div>
        <p>
The <a href="javascript:window.location.href='http://dlr.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=84001';">DLR
Hosting API</a> has three distinct levels of functionality. As simple as this is,
technically it’s level 2 since it’s using a ScriptEngine directly. If you wanted to
use the simplest level 1 hosting API, you could use runtimes instead of engines and
save a line of code.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:69036e31-2f47-461b-a06e-6f9784a7caeb" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>private</b>
            </span> <span style="color:#008000"><b>void</b></span> <span style="color:#0000FF">Window_Loaded</span>(<span style="color:#B00040">object</span> sender, RoutedEventArgs e)<br>
{<br>
    ScriptRuntime runtime = Python.CreateRuntime();<br>
    runtime.Globals.SetVariable(<span style="color:#BA2121">"items"</span>, lbThings.Items);<br>
    runtime.ExecuteFile(<span style="color:#BA2121">"getthings.py"</span>);<br>
}<br></div>
        </div>
        <p>
The ScriptRuntime version of ExecuteFile doesn’t include an overload that takes a
ScriptScope like ScriptEngine does, so instead you add the items variable to the globals
scope. However, this doesn’t automatically add the items object to every child scope
– you have to explicitly import items into the local scope if you want to use it.
So for Python, that means you need to add “import items” to the top of the GetThings.py
script. Nothing else changes.
</p>
        <p>
Personally, I find DLR Hosting API Level 2 to be straightforward and easy enough to
understand, so I tend to code to that level by default. I actually had to go read
the doc to discover the ScriptRuntime.Globals property and talk to Dino about importing
those variables into a local scope. However, I wanted to point out that nothing in
my Hybrid App Debugging sample so far is really dependent on the level 2 API. If you
just want to execute some Python files in the context of your C# application, you
can stick with the simpler level 1 API if you want. You can even use lightweight debugging
with the level 1 API – there’s an overload of the SetTrace extension method for ScriptRuntimes
just as there is for ScriptEngines. Just something to keep in mind.
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=96e3d1b3-5adc-4e69-b414-e69a6e5a05d0"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=B88byMgjtpo:xKv25WVxCZQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=B88byMgjtpo:xKv25WVxCZQ:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=B88byMgjtpo:xKv25WVxCZQ:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=B88byMgjtpo:xKv25WVxCZQ:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=B88byMgjtpo:xKv25WVxCZQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=B88byMgjtpo:xKv25WVxCZQ:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/B88byMgjtpo" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
In my series on &lt;a href="http://devhawk.net/2009/10/06/Lightweight+Debugging+For+Hybrid+CIronPython+Apps.aspx"&gt;Hybrid
App Debugging&lt;/a&gt;, I showed the following code for executing a Python file in a hybrid
C#/IronPython app.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:08436bdc-960e-4b10-a9f6-5784d3fdaad4" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;Window_Loaded&lt;/span&gt;(&lt;span style="color:#B00040"&gt;object&lt;/span&gt;&amp;#160;sender,&amp;#160;RoutedEventArgs&amp;#160;e)&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;ScriptEngine&amp;#160;engine&amp;#160;=&amp;#160;Python.CreateEngine();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;ScriptScope&amp;#160;&amp;#160;scope&amp;#160;=&amp;#160;engine.CreateScope();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;scope.SetVariable(&lt;span style="color:#BA2121"&gt;"items"&lt;/span&gt;,&amp;#160;lbThings.Items);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;engine.ExecuteFile(&lt;span style="color:#BA2121"&gt;"getthings.py"&lt;/span&gt;,&amp;#160;scope);&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
The &lt;a href="javascript:window.location.href='http://dlr.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=84001';"&gt;DLR
Hosting API&lt;/a&gt; has three distinct levels of functionality. As simple as this is,
technically it’s level 2 since it’s using a ScriptEngine directly. If you wanted to
use the simplest level 1 hosting API, you could use runtimes instead of engines and
save a line of code.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:69036e31-2f47-461b-a06e-6f9784a7caeb" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;Window_Loaded&lt;/span&gt;(&lt;span style="color:#B00040"&gt;object&lt;/span&gt;&amp;#160;sender,&amp;#160;RoutedEventArgs&amp;#160;e)&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;ScriptRuntime&amp;#160;runtime&amp;#160;=&amp;#160;Python.CreateRuntime();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;runtime.Globals.SetVariable(&lt;span style="color:#BA2121"&gt;"items"&lt;/span&gt;,&amp;#160;lbThings.Items);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;runtime.ExecuteFile(&lt;span style="color:#BA2121"&gt;"getthings.py"&lt;/span&gt;);&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
The ScriptRuntime version of ExecuteFile doesn’t include an overload that takes a
ScriptScope like ScriptEngine does, so instead you add the items variable to the globals
scope. However, this doesn’t automatically add the items object to every child scope
– you have to explicitly import items into the local scope if you want to use it.
So for Python, that means you need to add “import items” to the top of the GetThings.py
script. Nothing else changes.
&lt;/p&gt;
&lt;p&gt;
Personally, I find DLR Hosting API Level 2 to be straightforward and easy enough to
understand, so I tend to code to that level by default. I actually had to go read
the doc to discover the ScriptRuntime.Globals property and talk to Dino about importing
those variables into a local scope. However, I wanted to point out that nothing in
my Hybrid App Debugging sample so far is really dependent on the level 2 API. If you
just want to execute some Python files in the context of your C# application, you
can stick with the simpler level 1 API if you want. You can even use lightweight debugging
with the level 1 API – there’s an overload of the SetTrace extension method for ScriptRuntimes
just as there is for ScriptEngines. Just something to keep in mind.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=96e3d1b3-5adc-4e69-b414-e69a6e5a05d0" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=96e3d1b3-5adc-4e69-b414-e69a6e5a05d0</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,96e3d1b3-5adc-4e69-b414-e69a6e5a05d0.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,96e3d1b3-5adc-4e69-b414-e69a6e5a05d0.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=96e3d1b3-5adc-4e69-b414-e69a6e5a05d0</wfw:commentRss></item><item><title>Hybrid App Debugging &amp;ndash; TracebackDelegate and SetTrace</title><link>http://devhawk.net/2009/10/07/Hybrid+App+Debugging+Ndash+TracebackDelegate+And+SetTrace.aspx</link><category>Debugger</category><category>IronPython</category><category>Lightweight Debugger</category><category>Polyglot</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Wed, 07 Oct 2009 13:43:27 PDT</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,0cbc8971-2ce0-4098-b3b4-23a7f852cc86.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Now that I’ve introduced my <a href="http://devhawk.net/2009/10/06/Lightweight+Debugging+For+Hybrid+CIronPython+Apps.aspx">simple
hybrid GetThings app</a>, we need to set about adding support for debugging just the
IronPython part of the app via the new lightweight debugging functionality we’re introducing
in 2.6. Note, the code is <a href="http://github.com/devhawk/LightweightDebuggerDemo">up
on github</a>, but isn’t going to exactly match what I show on the blog. Also, I have
a post RC1 daily build of IronPython in the <a href="http://github.com/devhawk/LightweightDebuggerDemo/tree/deac85aaf14b37352ce4248917fd857c173d8997/External">Externals
folder</a> since I discovered a few issues while building this sample that Dino had
to fix after RC1. Those assemblies will be updated as needed as the sample progresses.
</p>
        <p>
We saw last time how how easy it is to execute a Python script to configure a C# app
– only four lines of code. If we want to support debugging, we need to add a fifth:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:8307bd4c-8d81-422a-9938-c547f25696e0" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>private</b>
            </span> <span style="color:#008000"><b>void</b></span> <span style="color:#0000FF">Window_Loaded</span>(<span style="color:#B00040">object</span> sender, RoutedEventArgs e)<br>
{<br>
    ScriptEngine engine = Python.CreateEngine();<br>
    engine.SetTrace(<span style="color:#008000"><b>this</b></span>.OnTraceback);<br><br>
    ScriptScope s = engine.CreateScope();<br>
    s.SetVariable(<span style="color:#BA2121">"items"</span>, lbThings.Items);<br>
    engine.ExecuteFile(<span style="color:#BA2121">"getthings.py"</span>, s);<br>
}<br></div>
        </div>
        <p>
You’ll notice the one new line – the call to engine.SetTrace. This is actually an
extension method – ScriptEngine is a DLR hosting API class and but SetTrace is IronPython
specific functionality [1]. If you look at the source of Python.SetTrace, you’ll see
that it’s just a wrapper around SysModule.settrace, but it avoids needing to get the
engine’s shared PythonContext yourself.
</p>
        <p>
SetTrace takes a TracebackDelegate as a parameter. That delegate gets registered as
the global traceback handler for the Python engine (on that thread, but we’ll ignore
threading for now). Whenever that engine enters a new scope (i.e. a new function),
the IronPython runtime calls into the global traceback handler. While the traceback
handler runs, execution of the python code in that engine is paused. When the traceback
handler returns, the engine resumes executing python code.
</p>
        <p>
In addition to the global traceback handler, each scope has a local traceback handler
as well. The TracebackDelegate type returns a TracebackDelegate which is used as the
local traceback handler for the next traceback event within that scope. Traceback
handlers can return themselves, some other TracebackDelegate, or null if they don’t
want any more traceback events for the current scope. It’s kinda confusing, so here’s
a picture:
</p>
        <p>
          <a href="http://devhawk.net/content/binary/WindowsLiveWriter/HybridAppDebuggingTracebackDelegateandSe_F502/image_10.png">
            <img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://devhawk.net/content/binary/WindowsLiveWriter/HybridAppDebuggingTracebackDelegateandSe_F502/image_thumb_4.png" width="514" height="206"></img>
          </a>
        </p>
        <p>
You’ll notice three different traceback event types in the picture above: call, line
and return. Call indicates the start of a scope, and is always invoked on the global
traceback handler (i.e. the traceback passed to SetTrace). Line indicates the Python
engine is about to execute a line of code and return indicates the end of a scopes
execution. As you can see, the runtime uses the return value of the traceback for
the next tracing call until the end of the scope. The return value from the “return”
event handler is ignored. 
</p>
        <p>
So now that we know the basics of traceback handlers, here’s a simple TracebackDelegate
that simply returns itself. The “Hello, world!” of traceback debugging if you will.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:bd6a1c57-94d2-4d29-9e6d-e8894c3097e3" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>private</b>
            </span> TracebackDelegate <span style="color:#0000FF">OnTraceback</span><br>
    (TraceBackFrame frame, <span style="color:#B00040">string</span> result, <span style="color:#B00040">object</span> payload)<br>
{<br>
    <span style="color:#008000"><b>return</b></span> <span style="color:#008000"><b>this</b></span>.OnTraceback;<br>
}<br></div>
        </div>
        <p>
If you run this code, there will be no functional difference from the code before
you added the SetTrace call. That’s because we’re not doing anything in the traceback
handler. But if you run this in the debugger with a breakpoint on this function, you’ll
see that it gets called a bunch of times. In the python code <a href="http://devhawk.net/2009/10/06/Lightweight+Debugging+For+Hybrid+CIronPython+Apps.aspx">from
the last post</a>, there are three scopes – module scope, download_stuff function
scope and the get_nodes function scope. Each of those function scopes will have a
call and return event, plus a bunch of line events in between. 
</p>
        <p>
The parameters for TracebackDelegate are described <a href="http://docs.python.org/library/sys.html#sys.settrace">in
the Python docs</a>. The frame parameter is the current stack frame – it has information
about the local and global variables, the code object currently executing, the line
number being executed and a pointer to the previous stack frame if there is one. More
information on code and frame objects is available in the <a href="http://docs.python.org/reference/datamodel.html#the-standard-type-hierarchy">python
data model</a> (look for “internal types”). Result is the reason why the traceback
function is being called (in Python docs, it’s called “event” but that’s a keyword
in C#). IronPython supports four traceback results: “call”, “line” and “return” as
described above plus “exception” when an exception is thrown. Finally, the payload
value’s meaning depends on the traceback result. For call and line, payload is null.
For return, payload is the value being returned from the function. For exception,
the payload is information about the exception and where it was thrown. 
</p>
        <p>
As I mentioned above, python code execution is paused while the traceback handler
executes and then continues when the traceback handler returns. That means you need
to block in that function if you want to let the user interact with the debugger.
For a console app like PDB, you can do that with a single thread of execution easily
enough. For a GUI app like GetThings, that means running the debugger and debugee
windows on separate threads. And as I alluded to, tracing for Python script engines
is per thread. So next time, we’ll look deeper into how to use multiple threads for
lightweight debugging a hybrid app.
</p>
        <hr></hr>
        <p>
[1] Eventually, I’d like to see IronRuby support lightweight debugging as well. However,
there’s no built in mechanism for Ruby debugging the way there is for Python, so it’s
less clear how we should expose debugging to the Ruby developer. We’d also want to
build a language neutral DLR Hosting API mechanism for lightweight debugging as well
at that point. But honestly, we have higher priorities at this point.
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=0cbc8971-2ce0-4098-b3b4-23a7f852cc86"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=0W0kYj5M25A:P42ofQqDp2E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=0W0kYj5M25A:P42ofQqDp2E:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=0W0kYj5M25A:P42ofQqDp2E:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=0W0kYj5M25A:P42ofQqDp2E:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=0W0kYj5M25A:P42ofQqDp2E:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=0W0kYj5M25A:P42ofQqDp2E:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/0W0kYj5M25A" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
Now that I’ve introduced my &lt;a href="http://devhawk.net/2009/10/06/Lightweight+Debugging+For+Hybrid+CIronPython+Apps.aspx"&gt;simple
hybrid GetThings app&lt;/a&gt;, we need to set about adding support for debugging just the
IronPython part of the app via the new lightweight debugging functionality we’re introducing
in 2.6. Note, the code is &lt;a href="http://github.com/devhawk/LightweightDebuggerDemo"&gt;up
on github&lt;/a&gt;, but isn’t going to exactly match what I show on the blog. Also, I have
a post RC1 daily build of IronPython in the &lt;a href="http://github.com/devhawk/LightweightDebuggerDemo/tree/deac85aaf14b37352ce4248917fd857c173d8997/External"&gt;Externals
folder&lt;/a&gt; since I discovered a few issues while building this sample that Dino had
to fix after RC1. Those assemblies will be updated as needed as the sample progresses.
&lt;/p&gt;
&lt;p&gt;
We saw last time how how easy it is to execute a Python script to configure a C# app
– only four lines of code. If we want to support debugging, we need to add a fifth:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:8307bd4c-8d81-422a-9938-c547f25696e0" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;Window_Loaded&lt;/span&gt;(&lt;span style="color:#B00040"&gt;object&lt;/span&gt;&amp;#160;sender,&amp;#160;RoutedEventArgs&amp;#160;e)&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;ScriptEngine&amp;#160;engine&amp;#160;=&amp;#160;Python.CreateEngine();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;engine.SetTrace(&lt;span style="color:#008000"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;.OnTraceback);&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;ScriptScope&amp;#160;s&amp;#160;=&amp;#160;engine.CreateScope();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;s.SetVariable(&lt;span style="color:#BA2121"&gt;"items"&lt;/span&gt;,&amp;#160;lbThings.Items);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;engine.ExecuteFile(&lt;span style="color:#BA2121"&gt;"getthings.py"&lt;/span&gt;,&amp;#160;s);&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
You’ll notice the one new line – the call to engine.SetTrace. This is actually an
extension method – ScriptEngine is a DLR hosting API class and but SetTrace is IronPython
specific functionality [1]. If you look at the source of Python.SetTrace, you’ll see
that it’s just a wrapper around SysModule.settrace, but it avoids needing to get the
engine’s shared PythonContext yourself.
&lt;/p&gt;
&lt;p&gt;
SetTrace takes a TracebackDelegate as a parameter. That delegate gets registered as
the global traceback handler for the Python engine (on that thread, but we’ll ignore
threading for now). Whenever that engine enters a new scope (i.e. a new function),
the IronPython runtime calls into the global traceback handler. While the traceback
handler runs, execution of the python code in that engine is paused. When the traceback
handler returns, the engine resumes executing python code.
&lt;/p&gt;
&lt;p&gt;
In addition to the global traceback handler, each scope has a local traceback handler
as well. The TracebackDelegate type returns a TracebackDelegate which is used as the
local traceback handler for the next traceback event within that scope. Traceback
handlers can return themselves, some other TracebackDelegate, or null if they don’t
want any more traceback events for the current scope. It’s kinda confusing, so here’s
a picture:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://devhawk.net/content/binary/WindowsLiveWriter/HybridAppDebuggingTracebackDelegateandSe_F502/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://devhawk.net/content/binary/WindowsLiveWriter/HybridAppDebuggingTracebackDelegateandSe_F502/image_thumb_4.png" width="514" height="206" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
You’ll notice three different traceback event types in the picture above: call, line
and return. Call indicates the start of a scope, and is always invoked on the global
traceback handler (i.e. the traceback passed to SetTrace). Line indicates the Python
engine is about to execute a line of code and return indicates the end of a scopes
execution. As you can see, the runtime uses the return value of the traceback for
the next tracing call until the end of the scope. The return value from the “return”
event handler is ignored. 
&lt;/p&gt;
&lt;p&gt;
So now that we know the basics of traceback handlers, here’s a simple TracebackDelegate
that simply returns itself. The “Hello, world!” of traceback debugging if you will.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:bd6a1c57-94d2-4d29-9e6d-e8894c3097e3" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;TracebackDelegate&amp;#160;&lt;span style="color:#0000FF"&gt;OnTraceback&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;(TraceBackFrame&amp;#160;frame,&amp;#160;&lt;span style="color:#B00040"&gt;string&lt;/span&gt;&amp;#160;result,&amp;#160;&lt;span style="color:#B00040"&gt;object&lt;/span&gt;&amp;#160;payload)&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;.OnTraceback;&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
If you run this code, there will be no functional difference from the code before
you added the SetTrace call. That’s because we’re not doing anything in the traceback
handler. But if you run this in the debugger with a breakpoint on this function, you’ll
see that it gets called a bunch of times. In the python code &lt;a href="http://devhawk.net/2009/10/06/Lightweight+Debugging+For+Hybrid+CIronPython+Apps.aspx"&gt;from
the last post&lt;/a&gt;, there are three scopes – module scope, download_stuff function
scope and the get_nodes function scope. Each of those function scopes will have a
call and return event, plus a bunch of line events in between. 
&lt;/p&gt;
&lt;p&gt;
The parameters for TracebackDelegate are described &lt;a href="http://docs.python.org/library/sys.html#sys.settrace"&gt;in
the Python docs&lt;/a&gt;. The frame parameter is the current stack frame – it has information
about the local and global variables, the code object currently executing, the line
number being executed and a pointer to the previous stack frame if there is one. More
information on code and frame objects is available in the &lt;a href="http://docs.python.org/reference/datamodel.html#the-standard-type-hierarchy"&gt;python
data model&lt;/a&gt; (look for “internal types”). Result is the reason why the traceback
function is being called (in Python docs, it’s called “event” but that’s a keyword
in C#). IronPython supports four traceback results: “call”, “line” and “return” as
described above plus “exception” when an exception is thrown. Finally, the payload
value’s meaning depends on the traceback result. For call and line, payload is null.
For return, payload is the value being returned from the function. For exception,
the payload is information about the exception and where it was thrown. 
&lt;/p&gt;
&lt;p&gt;
As I mentioned above, python code execution is paused while the traceback handler
executes and then continues when the traceback handler returns. That means you need
to block in that function if you want to let the user interact with the debugger.
For a console app like PDB, you can do that with a single thread of execution easily
enough. For a GUI app like GetThings, that means running the debugger and debugee
windows on separate threads. And as I alluded to, tracing for Python script engines
is per thread. So next time, we’ll look deeper into how to use multiple threads for
lightweight debugging a hybrid app.
&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;
[1] Eventually, I’d like to see IronRuby support lightweight debugging as well. However,
there’s no built in mechanism for Ruby debugging the way there is for Python, so it’s
less clear how we should expose debugging to the Ruby developer. We’d also want to
build a language neutral DLR Hosting API mechanism for lightweight debugging as well
at that point. But honestly, we have higher priorities at this point.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=0cbc8971-2ce0-4098-b3b4-23a7f852cc86" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=0cbc8971-2ce0-4098-b3b4-23a7f852cc86</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,0cbc8971-2ce0-4098-b3b4-23a7f852cc86.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,0cbc8971-2ce0-4098-b3b4-23a7f852cc86.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=0cbc8971-2ce0-4098-b3b4-23a7f852cc86</wfw:commentRss></item><item><title>Lightweight Debugging for Hybrid C#/IronPython Apps</title><link>http://devhawk.net/2009/10/06/Lightweight+Debugging+For+Hybrid+CIronPython+Apps.aspx</link><category>Debugger</category><category>IronPython</category><category>Lightweight Debugger</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Harry Pierson</dc:creator><pubDate>Tue, 06 Oct 2009 14:11:38 PDT</pubDate><guid isPermaLink="false">http://devhawk.net/PermaLink,guid,3cf0678c-d21a-4569-8d9c-2a3ae2996605.aspx</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.zazzle.com/you_had_me_at_dynamic_shirt-235421109922997983">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="designallCAZM93SM" border="0" alt="designallCAZM93SM" align="right" src="http://devhawk.net/content/binary/WindowsLiveWriter/EmbeddedDebuggingIntroduction_AD18/designallCAZM93SM_3.jpg" width="240" height="221"></img>
          </a>
        </p>
        <p>
One of the IronPython scenarios that I’m hearing more and more about recently is for <a href="http://en.wikipedia.org/wiki/Polyglot_%28computing%29">polyglot</a> programs.
In these scenarios, part of the application is built in IronPython other parts are
build in compiled, statically typed languages like C# or Visual Basic. Sometimes,
programs are written this way to allow the C# app to access a Python library, like
my <a href="http://devhawk.net/2009/04/05/Pygments+For+Windows+Live+Writer.aspx">Pygments
for WL Writer</a> plugin. Other programs want to be customizable by the end user,
like <a href="http://blogs.msdn.com/intellipad/archive/2008/11/11/newbie-experience-writing-a-custom-command.aspx">Intellipad</a>.
Whatever the reason, I think that the number of these hybrid polyglot programs is
going up, which partially explains why the C# team added the <a href="http://msdn.microsoft.com/en-us/library/dd264741(VS.100).aspx">new
dynamic type</a> to C# 4.0.
</p>
        <p>
(FYI: the <a href="http://www.zazzle.com/you_had_me_at_dynamic_shirt-235421109922997983">You
had me at “dynamic”</a> shirt above is available for sale in my Zazzle store along
with my <a href="http://www.zazzle.com/architecture_help_dark_t_shirt-235848130425737882">Architecture
Help 5¢</a> shirt)
</p>
        <p>
The thing is that if you’re going to build polyglot apps, you’re probably going to
want the ability to debug polyglot apps as well. I’ve <a href="http://devhawk.net/2009/02/27/Writing+An+IronPython+Debugger+Introduction.aspx">written
extensively</a> about building a debugger for IronPython. However, <a href="http://github.com/devhawk/ipydbg/">ipydbg</a> uses
the CLR debugger under the hood which means you have to have the debugger and the
code it’s debugging in separate processes. That’s a huge design burden for building
a debuggable polyglot application. Luckily, as of IronPython 2.6, we support Python’s
built-in trace debugging capability (aka <a href="http://docs.python.org/library/sys.html#sys.settrace">sys.settrace</a>).
While you can use this in pure Python apps (like <a href="http://docs.python.org/library/pdb.html">PDB</a>),
you can also use it polyglot C# (or VB)/IronPython apps as well. If only someone were
to take the time to build a sample and document what he did along the way…
</p>
        <p>
Hey, that sounds like PM work!
</p>
        <p>
Seriously, let me introduce you to the worlds simplest Twitter application: GetThings.
The app downloads a list of my tweets via the Twitter API and displays them in a list
box. The UI is written in C# while the tweet download code is written in Python. Clearly,
this is a pretty brain dead app – but the point isn’t to build a great Twitter app
but rather to show how to use the settrace API from C#.
</p>
        <p>
I’ve stuck the <a href="http://github.com/devhawk/LightweightDebuggerDemo">code up
on GitHub</a>. If you want to see the basic app in action sans debugging, start with
the <a href="http://github.com/devhawk/LightweightDebuggerDemo/commit/92bd5fc330e2a48ae84fc185f3e397aefb4be1eb">initial
checkin</a>. As you can see here, basic C# / IronPython integration is pretty trivial.
I’m simply creating an engine and a scope, adding the list boxes’ Items property to
the scope, and executing the getthings.py file from the disk.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:73f1a3b9-a8dc-4c38-880a-c9ef836bf0c3" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>private</b>
            </span> <span style="color:#008000"><b>void</b></span> <span style="color:#0000FF">Window_Loaded</span>(<span style="color:#B00040">object</span> sender, RoutedEventArgs e)<br>
{<br>
    ScriptEngine engine = Python.CreateEngine();<br>
    ScriptScope  scope = engine.CreateScope();<br>
    scope.SetVariable(<span style="color:#BA2121">"items"</span>, lbThings.Items);<br>
    engine.ExecuteFile(<span style="color:#BA2121">"getthings.py"</span>, scope);<br>
}<br></div>
        </div>
        <p>
Since GetThings.py is just a text file, the user can modify it to get a list of anything
they want – some other user’s timeline, the public timeline, or even – gasp! – something
not from Twitter! In fact, as you see below, I’ve actually modified it to pull the
tweets from a file on disk so I can avoid hitting the network on every run.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:c699ee34-4a59-40a5-a49c-eb135389af0a" class="wlWriterEditableSmartContent">
          <div style="font-family:consolas,lucida console,courier,monospace">
            <span style="color:#008000">
              <b>import</b>
            </span> <span style="color:#0000FF"><b>clr</b></span><br>
clr<span style="color:#666666">.</span>AddReference(<span style="color:#BA2121">"System.Xml"</span>)<br><span style="color:#008000"><b>from</b></span> <span style="color:#0000FF"><b>System.Xml</b></span> <span style="color:#008000"><b>import</b></span> XmlDocument<br><br><span style="color:#008000"><b>def</b></span> <span style="color:#0000FF">get_nodes</span>(xml):<br>
    <span style="color:#008000"><b>return</b></span> xml<span style="color:#666666">.</span>SelectNodes(<span style="color:#BA2121">"statuses/status/text"</span>)<br><br><span style="color:#008000"><b>def</b></span> <span style="color:#0000FF">download_stuff</span>():<br>
    x <span style="color:#666666">=</span> XmlDocument()<br><br>
    <span style="color:#408080"><i>#load from disk to save time in development</i></span><br>
    <span style="color:#408080"><i>#x.Load("http://twitter.com/statuses/user_timeline/devhawk.xml")</i></span><br>
    x<span style="color:#666666">.</span>Load(<span style="color:#BA2121">"devhawk.xml"</span>)<br><br>
    <span style="color:#008000"><b>for</b></span> n <span style="color:#AA22FF"><b>in</b></span> get_nodes(x):<br>
        txt <span style="color:#666666">=</span> n<span style="color:#666666">.</span>InnerText<br>
        items<span style="color:#666666">.</span>Add(txt)<br><br>
download_stuff()<br></div>
        </div>
        <p>
OK, so that’s the basics of the world’s simplest hybrid C#/IronPython Twitter application.
Next up, I’ll add the settrace basics.
</p>
        <img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=3cf0678c-d21a-4569-8d9c-2a3ae2996605"></img>
      </body><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Devhawk?a=gOGI9U1cXkY:2RulaMM8AmQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=gOGI9U1cXkY:2RulaMM8AmQ:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=gOGI9U1cXkY:2RulaMM8AmQ:XQ266DUsA9M"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=XQ266DUsA9M" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=gOGI9U1cXkY:2RulaMM8AmQ:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/Devhawk?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Devhawk?a=gOGI9U1cXkY:2RulaMM8AmQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Devhawk?i=gOGI9U1cXkY:2RulaMM8AmQ:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Devhawk/~4/gOGI9U1cXkY" height="1" width="1"/>]]></content:encoded><description>&lt;p&gt;
&lt;a href="http://www.zazzle.com/you_had_me_at_dynamic_shirt-235421109922997983"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="designallCAZM93SM" border="0" alt="designallCAZM93SM" align="right" src="http://devhawk.net/content/binary/WindowsLiveWriter/EmbeddedDebuggingIntroduction_AD18/designallCAZM93SM_3.jpg" width="240" height="221" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
One of the IronPython scenarios that I’m hearing more and more about recently is for &lt;a href="http://en.wikipedia.org/wiki/Polyglot_%28computing%29"&gt;polyglot&lt;/a&gt; programs.
In these scenarios, part of the application is built in IronPython other parts are
build in compiled, statically typed languages like C# or Visual Basic. Sometimes,
programs are written this way to allow the C# app to access a Python library, like
my &lt;a href="http://devhawk.net/2009/04/05/Pygments+For+Windows+Live+Writer.aspx"&gt;Pygments
for WL Writer&lt;/a&gt; plugin. Other programs want to be customizable by the end user,
like &lt;a href="http://blogs.msdn.com/intellipad/archive/2008/11/11/newbie-experience-writing-a-custom-command.aspx"&gt;Intellipad&lt;/a&gt;.
Whatever the reason, I think that the number of these hybrid polyglot programs is
going up, which partially explains why the C# team added the &lt;a href="http://msdn.microsoft.com/en-us/library/dd264741(VS.100).aspx"&gt;new
dynamic type&lt;/a&gt; to C# 4.0.
&lt;/p&gt;
&lt;p&gt;
(FYI: the &lt;a href="http://www.zazzle.com/you_had_me_at_dynamic_shirt-235421109922997983"&gt;You
had me at “dynamic”&lt;/a&gt; shirt above is available for sale in my Zazzle store along
with my &lt;a href="http://www.zazzle.com/architecture_help_dark_t_shirt-235848130425737882"&gt;Architecture
Help 5¢&lt;/a&gt; shirt)
&lt;/p&gt;
&lt;p&gt;
The thing is that if you’re going to build polyglot apps, you’re probably going to
want the ability to debug polyglot apps as well. I’ve &lt;a href="http://devhawk.net/2009/02/27/Writing+An+IronPython+Debugger+Introduction.aspx"&gt;written
extensively&lt;/a&gt; about building a debugger for IronPython. However, &lt;a href="http://github.com/devhawk/ipydbg/"&gt;ipydbg&lt;/a&gt; uses
the CLR debugger under the hood which means you have to have the debugger and the
code it’s debugging in separate processes. That’s a huge design burden for building
a debuggable polyglot application. Luckily, as of IronPython 2.6, we support Python’s
built-in trace debugging capability (aka &lt;a href="http://docs.python.org/library/sys.html#sys.settrace"&gt;sys.settrace&lt;/a&gt;).
While you can use this in pure Python apps (like &lt;a href="http://docs.python.org/library/pdb.html"&gt;PDB&lt;/a&gt;),
you can also use it polyglot C# (or VB)/IronPython apps as well. If only someone were
to take the time to build a sample and document what he did along the way…
&lt;/p&gt;
&lt;p&gt;
Hey, that sounds like PM work!
&lt;/p&gt;
&lt;p&gt;
Seriously, let me introduce you to the worlds simplest Twitter application: GetThings.
The app downloads a list of my tweets via the Twitter API and displays them in a list
box. The UI is written in C# while the tweet download code is written in Python. Clearly,
this is a pretty brain dead app – but the point isn’t to build a great Twitter app
but rather to show how to use the settrace API from C#.
&lt;/p&gt;
&lt;p&gt;
I’ve stuck the &lt;a href="http://github.com/devhawk/LightweightDebuggerDemo"&gt;code up
on GitHub&lt;/a&gt;. If you want to see the basic app in action sans debugging, start with
the &lt;a href="http://github.com/devhawk/LightweightDebuggerDemo/commit/92bd5fc330e2a48ae84fc185f3e397aefb4be1eb"&gt;initial
checkin&lt;/a&gt;. As you can see here, basic C# / IronPython integration is pretty trivial.
I’m simply creating an engine and a scope, adding the list boxes’ Items property to
the scope, and executing the getthings.py file from the disk.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:73f1a3b9-a8dc-4c38-880a-c9ef836bf0c3" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;Window_Loaded&lt;/span&gt;(&lt;span style="color:#B00040"&gt;object&lt;/span&gt;&amp;#160;sender,&amp;#160;RoutedEventArgs&amp;#160;e)&lt;br /&gt;
{&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;ScriptEngine&amp;#160;engine&amp;#160;=&amp;#160;Python.CreateEngine();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;ScriptScope&amp;#160;&amp;#160;scope&amp;#160;=&amp;#160;engine.CreateScope();&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;scope.SetVariable(&lt;span style="color:#BA2121"&gt;"items"&lt;/span&gt;,&amp;#160;lbThings.Items);&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;engine.ExecuteFile(&lt;span style="color:#BA2121"&gt;"getthings.py"&lt;/span&gt;,&amp;#160;scope);&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
Since GetThings.py is just a text file, the user can modify it to get a list of anything
they want – some other user’s timeline, the public timeline, or even – gasp! – something
not from Twitter! In fact, as you see below, I’ve actually modified it to pull the
tweets from a file on disk so I can avoid hitting the network on every run.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8647342E-C6F6-4230-979C-77E8BB3FA682:c699ee34-4a59-40a5-a49c-eb135389af0a" class="wlWriterEditableSmartContent"&gt;
&lt;div style="font-family:consolas,lucida console,courier,monospace"&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;&lt;b&gt;clr&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
clr&lt;span style="color:#666666"&gt;.&lt;/span&gt;AddReference(&lt;span style="color:#BA2121"&gt;"System.Xml"&lt;/span&gt;)&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;from&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;&lt;b&gt;System.Xml&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt;&amp;#160;XmlDocument&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;get_nodes&lt;/span&gt;(xml):&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&amp;#160;xml&lt;span style="color:#666666"&gt;.&lt;/span&gt;SelectNodes(&lt;span style="color:#BA2121"&gt;"statuses/status/text"&lt;/span&gt;)&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color:#008000"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt;&amp;#160;&lt;span style="color:#0000FF"&gt;download_stuff&lt;/span&gt;():&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;x&amp;#160;&lt;span style="color:#666666"&gt;=&lt;/span&gt;&amp;#160;XmlDocument()&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#408080"&gt;&lt;i&gt;#load&amp;#160;from&amp;#160;disk&amp;#160;to&amp;#160;save&amp;#160;time&amp;#160;in&amp;#160;development&lt;/i&gt;&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#408080"&gt;&lt;i&gt;#x.Load("http://twitter.com/statuses/user_timeline/devhawk.xml")&lt;/i&gt;&lt;/span&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;x&lt;span style="color:#666666"&gt;.&lt;/span&gt;Load(&lt;span style="color:#BA2121"&gt;"devhawk.xml"&lt;/span&gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;span style="color:#008000"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/span&gt;&amp;#160;n&amp;#160;&lt;span style="color:#AA22FF"&gt;&lt;b&gt;in&lt;/b&gt;&lt;/span&gt;&amp;#160;get_nodes(x):&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;txt&amp;#160;&lt;span style="color:#666666"&gt;=&lt;/span&gt;&amp;#160;n&lt;span style="color:#666666"&gt;.&lt;/span&gt;InnerText&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;items&lt;span style="color:#666666"&gt;.&lt;/span&gt;Add(txt)&lt;br /&gt;
&lt;br /&gt;
download_stuff()&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
OK, so that’s the basics of the world’s simplest hybrid C#/IronPython Twitter application.
Next up, I’ll add the settrace basics.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://devhawk.net/aggbug.ashx?id=3cf0678c-d21a-4569-8d9c-2a3ae2996605" /&gt;</description><trackback:ping xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">http://devhawk.net/Trackback.aspx?guid=3cf0678c-d21a-4569-8d9c-2a3ae2996605</trackback:ping><pingback:server xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/pingback.aspx</pingback:server><pingback:target xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/">http://devhawk.net/PermaLink,guid,3cf0678c-d21a-4569-8d9c-2a3ae2996605.aspx</pingback:target><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/CommentView,guid,3cf0678c-d21a-4569-8d9c-2a3ae2996605.aspx</wfw:comment><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devhawk.net/SyndicationService.asmx/GetEntryCommentsRss?guid=3cf0678c-d21a-4569-8d9c-2a3ae2996605</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">2</slash:comments></item></channel></rss>
