Saturday, 27 May 2006
As I mentioned in a previous post, I am really excited about IronPython on the .NET platform.  The main reason is being able to program dynamically.  What I mean is that I can import .NET classes and start using them interactively with the interpreter.
For example, I can interactively build a simple WPF (formerly Avalon) application in just a half dozen lines of code.  I dont mean running a script either; I mean entering in one line at a time and immediately seeing the results on the screen.
For example, the following code imports the WPF library (and a small script to allow interactivity between the interpreter and application being constructed), creates a new window instance, displays the window, sets the title and some text in the form, sizes the text and finally sizes the form to the text.
from avalon import *
w = Window()
w.Title = Simple WPF App
w.Content = TextBlock()
w.Content.Text = Aloha IronPython!
w.Content.FontSize = 50
w.SizeToContent = SizeToContent.WidthAndHeight
Alright you say, no big deal.  Well, on one hand you are right on the other, I think the point is that it satisfies a major requirement that I have as a programmer which is to interact with building my application in real time.  This goes beyond just the compile, link, deploy cycle of compiled languages.  This allows me to see what I am doing as I am doing it.  Some would say this is hacking with no design documentation and just winging it.  Others would use the analogy of a painter and the canvas where you are seeing tangible results in real-time as you are painting just like in the real world and not in our make belief software world.  Or even if I had a design document and was following Agile methods, this to me gives immediate verifiable results as you are seeing it on the screen, again in real-time.  This whole notion of dynamic programming and the semantic meaning I have for it will be a future topic.
I could take the sample above much further and in fact, if you download IronPython you can follow the tutorial which this snippet is from, plus load up XAML, build event handlers and hook them all up to produce a real working live application with a handful more lines of code.  As tutorial states, IronPython provides a very easy way to develop live application in a dynamic and exploratory way.  That is what has me very excited about this dynamic programming language on the .NET platform.
.NET 2.0 Framework Class Library has roughly 29,000 types in it.  Plus, as I have written elsewhere in this site on software industrialization, there are tens of thousands more COM dlls and other .NET dlls that have been written.  My point is that though IronPython any of these types can be imported and used dynamically in any application you may be building, particularly if you are predisposed to performing programming in a dynamic and exploratory way.
How to so this?  In my post on Software Industrialization using .NET Reflector and IronPython, I suggested building a Smalltalk like System Browser with and IronPython interpreter built into it.  While Lutz Roeders .NET Reflector product is excellent and highly recommended, for me, it is difficult to use from a tree view perspective.  I much prefer Smalltalks System Browser approach plus I can work with types in fewer mouse clicks.  Finally, I can embed the IronPython interpreter in the code window so I can work with the types that I am exploring and later as we will see, add my own types on the fly that are subclasses or extensions or glue code to all of the other types that I have loaded.
First things first.  How do I get type information?  There are several excellent articles on .NET Reflection and the best one summarizes it here.  The first thing is to write a wee bit of IronPython code to find the types in any given assembly.  Here we are going to get the types out of mapack.dll
IronPython 1.0.2280
Copyright (c) Microsoft Corporation. All rights reserved.
>>> from System.Reflection import *
>>> a = Assembly.LoadFrom("mapack.dll")
>>> Types = a.GetTypes()
>>> for Type in Types:
...       print Type
Easy enough.  Next post in this series is to build a Windows App (in IronPython of course) that starts to take on the shape of a Smalltalk System Browser so we can start reflecting types for possible inclusion for the apps we are building.
Saturday, 27 May 2006 20:16:22 (Pacific Standard Time, UTC-08:00)  #    Comments [0]Trackback
© Copyright 2007 Mitch Barnett - Software Industrialization is the computerization of software design and function.

newtelligence dasBlog 1.9.6264.0  Theme design by Bryan Bell
Feed your aggregator (RSS 2.0)   | Page rendered at Wednesday, 11 July 2007 11:54:46 (Pacific Standard Time, UTC-08:00)