Thursday, July 31, 2008

IronPython in Action: All 15 Chapters Available in Early Access Program

All fifteen chapters (427 pages) of IronPython in Action are now available in the Manning Early Access Program. The last few chapters (12 -15) are now being perused by our reviewers, so there may be minor changes, but this is an important milestone. You can read more about the last chapter (Embedding IronPython in .NET Applications) on my blog, and see the whole table of contents on the IronPython in Action website:
The new chapters available in the "MEAP" include Christian Muirhead's chapter (12) on Databases and Webservices, plus chapters on extending & embedding IronPython and Silverlight.

Still to do are the index and appendices plus updates to the earlier chapters (particularly the first chapter) in the light of changes to IronPython over the eighteen months or so that we have been writing it.

IronPython and Active Directory

Two new recipes have been posted to the IronPython Cookbook. They are both about interacting with Active Directory from IronPython.
The first article shows how to use 'System.DirectoryServices' and 'RefreshCache' to load attributes not exposed by ADSI. The second is a helper object that turns 'DirectoryService' objects into Python dictionaries, which are easier to work with.

Inside IronPython AST - Parts 1 & 2 (Chinese)

These articles on the Chinese "Aim and Action" blog look really interesting, if only I could understand them. It is a two part look at IronPython 2 from the inside - exploring how IronPython (and the DLR) parses Python code and the resulting AST. Although there are some diagrams I'm afraid you won't get much out of them if you can't read Chinese. Still, they look good.
In fact this chap has done a series of articles on IronPython, although the other entries more cover Python features like decorators, higher order functions and generators. It's nice to see that the Python and IronPython community is truly international.

Wednesday, July 30, 2008

.NET 4, C# 4 and the DLR

The recent C# 4 Meet the Design Team Video discussed the future of C# 4, and in particular how it might have more features inspired by dynamic languages and offer better interoperation with the DLR languages like IronPython and IronRuby. (Currently dynamic objects created using these languages can be used from statically typed .NET languages - the DLR provides an API to do this - but it could certainly be made more convenient).

In this blog entry, Jb looks at potential DLR integration into C# 4 and particularly examines the similarities between LINQ Expression Trees and DLR ASTs (in fact these will be merged completely at some point to use the same representation for LINQ expressions and parsed dynamic languages - this will not only be simpler for developers working with both but make it a lot easier to bring LINQ into DLR languages):
UPDATE: He's followed up with a new post, confirming that in IronPython 2 Beta 4 (not yet released but the sourcecode is regularly synced from the teams internal repositories to Codeplex's TFS and available for download) the "Microsoft.Scripting.Core namespace has been renamed to System.Scripting, and that the DLR AST has been merged into System.Linq.Expressions".

4 different ways to execute IronPython code using the DLR Hosting API

The DLR hosting blog has posted another article on using the IronPython embedding API. This entry explores different ways you can execute Python code (four of them). It introduces the ScriptScope, ScriptSource and CompiledCode classes:

IronPython Projects, IronPython IDEs and Python in the Browser with Silverlight

IronPython in Action is nearly complete, and once it really is finished I will have more time to work on projects that have been waiting in the wings.

This includes several IronPython related projects (including a documentation tool that runs under IronPython, user controls specified in XAML for dynamic languages for WPF and Silverlight, and an IronPython IDE):The IronPython IDE of course is IronEditor, a project by Ben Hall to create an IDE for Dynamic Language Runtime languages and to run on Mono and .NET.

The Industrialization of Software blog has a great roundup of (.NET) dynamic language IDEs and interactive environments. He is particularly focussed on web based environments:
His blog entry mentions Silvershell, a Python interpreter that runs inside Silverlight 2. It is written by Dan Eloff and has nice features like auto-indentation and completion. Currently it only works on IE, but Dan will work on this when Silverlight 2 is out of beta.


Try Python is one of the projects I'd like to work on once the book is complete. I intend to make it a tutorial series for teaching Python that only needs a browser and Silverlight. Currently it uses Python in the Browser, which is an interactive Python interpreter that runs in an HTML textarea. I have various options for improving "Try Python" and one of them is to build it on top of Silvershell:

Tuesday, July 29, 2008

PyCon UK: IronPython Tutorial and Talk Lists Up

September 12-14th at the Birmingham Conservatoire is the 2nd UK Python Conference, organised by the UK Python community.

This year the conference starts with a tutorial day, and Christian
Muirhead, Menno Smits and I will be running a half day IronPython
tutorial. The tutorial day is only £30, so if you're interested in learning about IronPython it is an ideal opportunity.
Other topics include Python & WMI, testing, lots of Django, PyPy, Google AppEngine, Pyglet and Python on OpenMoko. On my blog is a summary of the accepted talks and tutorials.

Saturday, July 26, 2008

Twining, TwyDL (IronPython DSL)

David Seruyange has been working on his IronPython database DSL Twining.
He's been using Twining to export tables to SQL and also working on the ability to generate schema objects:
database(cn).create.table("Employees",
[
col.ident("EmployeeID"),
col.string("FirstName"),
col.string("LastName"),
col.numeric("Salary")
]
)

IronPython and Silverlight - Part 2

There is a new post on "Kim's Blog" about Silverlight. This is a follow-up to IronPython and Silverlight Part 1.
The blog entry is in French, but with clear example code using WebClient to make network requests and fetch a page (or data) from a specified Url.

WebClient is asynchronous, so to fetch resources with it you must call DownloadStringAsync and provide a handler for the DownloadStringCompleted event. (Although I'm pretty sure that you don't need to wrap the handler method with an explicit DownloadStringCompletedEventHandler delegate as IronPython will do this for you.)

Friday, July 25, 2008

CLS Compilation of IronPython

In IronPython (and other Dynamic Language Runtime languages) Python classes are not static .NET types.

There are various reasons for this. .NET classes can't be garbage collected (assemblies can't be unloaded - unless you load them in another AppDomain and unload the whole AppDomain). Additionally dynamic languages typically allow you to add and remove members at runtime and in Python you can even change the base classes at runtime. For instances of Python classes we can also change the class at runtime, not usually recommended but possible...

This means that normally a Python class can't be a static .NET type, instead Python classes are .NET objects (instances of their metaclass - for new style classes without a custom metaclass that means 'PythonType').

This isn't without problems - in order to apply .NET attributes you basically need a sttic type. This leaves a hole in the interoperation between Common Language Runtime features and dynamic languages, and means their are various there are various things you can't do from IronPython and have to resort to C#. There is more to it than this summary, and different ways for this to be resolved - by both the DLR and the CLR teams at Microsoft.

Shri Borde has a blog entry explaining some of the issues and possibilities:

How to create IronPython objects of types defined in C#

A new article from the "DLR Hosting blog" on creating Python types that inherit from .NET types when hosting IronPython.

Inheriting from .NET types is straightforward in IronPython. The builtin Python types are all .NET types implemented in C# and you can inherit from these, just as in CPython.

The interesting part of the blog entry is that it shows you to how to setup the hosting environment - to make your custom .NET types available to Python code running in the hosted Python engine.

Wednesday, July 23, 2008

Python (and IronPython) for Executives

ophirk has published a great essay on getting Python / IronPython accepted as a development language within the company he works for:
IronPython has worked well for them because of easy integration with C# and the .NET infrastructure.

He lists the four main fears that their managers had to face in adopting Python:
  • Recruiting - It turns out that smart and innovative people are attracted by Python .Innovative smart people can also learn Python very quickly.
  • Risk - in one year we had only five cases where a Python specific bug occurred. We had many more ASP. NET, JavaScript, HTML and even Java specific problems.
  • Maturity - not only is Python very solid, so is IronPython. The code is stable, the smart features work, the community is responsive and the libraries are rich. The only downside is the IDE and Visual studio integration, but this is progressing as well.
  • Performance - Python flexibility allowed extremely fast optimizations at the system and algorithmic levels, without requiring premature optimization. The system and algorithm changes are the ones critical in a real world environment. Some issues are showing up, but it seems they can be solved with a reasonable cost.

IronEditor: An Editor for Dynamic Languages on .NET

Ben Hall, a .NET developer from the UK, has announced a new project to create an IDE specifically targeting IronPython and IronRuby. In the future the project will also be extended to cover all languages that use the Dynamic Language Runtime.
Ben's goal is to create an IDE for Dynamic Languages that is lighter-weight than Visual Studio.

Out of the box the project already supports IronPython and IronRuby, including the creation of new projects or source files and executing code. IronEditor is based on Windows Forms and has a syntax highlighting code editor.

Currently to build IronEditor you will need Visual Studio 2008 (Express is fine), but there is a binary available for download. The blog entry shows screenshots of IronEditor running on Mono. Mono compatibility is an important goal for IronEditor. Currently the only feature missing on Mono is syntax highlighting.

Monday, July 21, 2008

Review of IronPython in Action

It isn't even published yet, but there is already a review of IronPython in Action! Noel, who works in 'cheminformatics' and is an avid Python user, has been reading the Early Access version (currently the first eleven chapters) and has posted his thoughts:
The obligatory introduction to Python is quickly and efficiently dealt with before moving on to the main subject - accessing .NET classes and creating a GUI application. For those coming from C# to IronPython, there is a whole chapter on unit testing with Python, as well as another that covers everything from Python magic methods to metaprogramming.

In short, for any serious users of IronPython, this book is a must have. It may also convince those using C# to make the switch to a better and more productive life with Python..

Turning Internet Feeds into TV Feeds with WPF and IronPython

Jon Udell has been writing a series of blog entries on a project to display RSS feeds in a publicly accessible way. He settled on WPF (Windows Presentation Foundation - part of .NET 3) as the user interface, but couldn't wire up the timer callback to refresh the display periodically from IronPython. After prototyping in C#, and with a bit of help, he got an IronPython version working:
Jon's project is to make information more accessible by displaying it on his local public access cable TV. Although the IronPython and C# versions of this client are virtually identical, he is leaning towards the IronPython one as it would be easier for the folks at the TV station to customize / modify it.

Embedded IronPython 1 - The Simple (and Chinese) Way

This blog entry by Terence Chao is very short, and barring about two words all in Chinese. However it links to a PDF document (by the author of the blog) with examples of embedding IronPython 1 in C# and using IronPython to automate Excel. More Chinese text, but straighforward code examples:
His Excel automation example takes command line arguments to convert Excel files into CSV files.

If you are (or can read) Chinese, then you might also be interested in these entries:
A simple example of the IronPython 2 hosting API, executing code from a string. This entry is mostly code, with screenshots and diagram.
This one is mainly text, but appears to be a pretty impressive IronPython tutorial. It looks like it is the start of a translation of the tutorial (by Microsoft) that comes with IronPython. You can find it on the web here.
Another blog entry with screenshots and code (XAML plus IronPython). This one on using IronPython inside Silverlight.

Sunday, July 20, 2008

Easier Python Evaluation from C#

Ronnie Maor uses IronPython with C# at work. He has written an extension method, to the IronPython 1.1 PythonEngine, to make evaluating Python expressions simpler.

Saturday, July 19, 2008

DLR Hosting Sample : QikScript - Handle Visual Studio 2008 extensibility events in IronPython

Sesh Pillailokam has written another blog entry on using the Dynamic Language Runtime Hosting API. This blog entry shows how to extend Visual Studio 2008, using IronPython to handle Visual Studio events:
The entry includes a downloadable example called 'QikScript', which is a Visual Studio AddIn written in Python. It handles the 'WindowCreated' and 'DocumentSaved' events.

Friday, July 18, 2008

C# 4.0: Meet the Design Team

A channel 9 video interview with Anders Hejilsberg and the C# design team on the future of C#, specifically C# 4.0. The team (and video) includes Jim Hugunin (creator of Jython and IronPython) and the discussion rambles around language design issues, the importance of concurrency, and how dynamic languages are influencing C# and the Common Language Runtime. The video is an hour long (and the high quality version around 950mb to download), but very entertaining - although Anders doesn't seem to realise that there are plenty of IDEs for dynamic languages with capable intellisense features.
From the introduction to the video:

C# 4.0 will contain many new features that will help developers be, yeah, you've heard it before, more productive. There's also some very interesting work going on with adding dynamic constructs to the language, which is of course very interesting given the static nature of the C# language.

In this video you will not get any specific details since the C# team wants to reveal exactly what they've done at PDC 2008. That said, you'll still get a very clear sense of what they've been up to and where they're taking the language.

Thursday, July 17, 2008

The Differences Between IronPython and CPython

IronPython is an implementation of the Python programming language written in C#, running on the Microsoft .NET framework and Mono.

This naturally means that there are some differences between IronPython and CPython. The most significant differences being:
  • IronPython uses the underlying .NET basic types. Strings are therefore Unicode by default, as they will be in Python 3.
  • IronPython compiles Python code to .NET assemblies, and uses neither Python stack frames nor bytecode.
  • CPython extensions written in C, using the CPython C API, don't work with IronPython (at least not until Ironclad is completed).
There are several lesser differences as well. For example, did you know that CPython catches string exceptions by reference whereas IronPython catches them by value?

The IronPython team have written up the differences between the two implementations and have now put them up on wiki pages:

IronPython the Road Ahead: a Post 2.0 Roadmap

In recent days both Todd Ogasawara and Steve Holden have wondered what the future holds for IronPython, particularly with regard to how and whether it will support Python 3.0 which edges ever closer.

Harry Pierson has been goaded into mapping out the road ahead for IronPython, at least partly due to utterly unfair comments from me over Twitter.
In this blog Harry Pierson's sets out the IronPython teams plans, which include:
  • Pushing out a new 1.1.2 release in the coming weeks, the last planned released of the 1.X (pre-Dynamic Language Runtime) branch of IronPython
  • Getting IronPython 2 (currently still in beta) completed by the end of the year. IronPython 2 targets compatibility with CPython 2.5.
  • Python 2.6 support (both language and library compatibility) will come sometime in the IronPython 2.1 lifecycle. Along with this will be Visual Studio integration.
  • An IronPython 3 that will target Python 3.
Harry also talks about the hoops he is jumping through to get the Microsoft lawyers to sign off on IronPython accepting contributions back from the community (and being able to do things like ship the Python standard library with IronPython distributions).

Much good news, although I wonder if the IronPython team will be willing to continue active development of IronPython 2.X and 3.X as the CPython development team intend to. It will probably be several years before the majority of the Python community has switched over to Python 3.

Visual Studio IronPython Integration Deep Dive

The Visual Studio SDK demonstrates how to customize Visual Studio, providing IronPython integration as an example of how to use many of the advanced features. code.msdn.microsoft.com nows has a 'deep dive' document that explores the SDK through the IronPython integration.
The IronPython Visual Studio SDK example provides, among other things, a full implementation of the Python programming language. The IronPython integration into Visual Studio, included as part of the SDK, provides not only a full IDE experience for Python developers interested in exploring this Python implementation, but also a useful framework from which to dissect a non-trivial Visual Studio language service and development environment. While the VS SDK provides some documentation on the subject, along with the source code of the IronPython Visual Studio Integration itself, it can be overwhelming to attack such a large source base without some kind of guide to point out purpose, direction, and salient roadmarks within the code.

This Deep Dive will explore a variety of topics dealing with the IronPython Visual Studio integration, such as:
  • MSBuild integration with the Visual Studio environment
  • A custom tool window to display the IronPython console
  • Code snippets
  • Project template support

And so on.

Tuesday, July 15, 2008

GUI Automated Testing: Simulating User Input

The next post on the "GUI Automated Testing" blog continues the theme of testing .NET applications with IronPython. This entry supplies a useful library of routines to simulate user input using (key strokes, mouse events etc) the Win32 API.

Lukas Cenovsky illustrates using this library to interact with an application under test.

Debugging in IronPython Studio with PythonEngine

Another post on Michael's Random Technology Posts blog. This one on how to use the .NET debugger with IronPython code and the IronPython Studio IDE (which can run standalone or integrated with Visual Studio). The setup Michael uses some C# (embedding the PythonEngine), but shows nice screenshots for the whole process:

ASP.NET and Dynamic Languages

ASP.NET has been overshadowed recently, both by Silverlight and the ongoing development of the ASP.NET MVC framework which is heavily influenced by Rails and Django.

The IronPython support in ASP.NET was released in July last year, but not much has apparently happened since then. Jimmy Schementi blogs about hope for the future of dynamic languages in ASP.NET:

How to Redirect Output from Python Using the DLR Hosting API

seshadripv has a long blog entry showing how to using the core classes in the Dynamic Language Runtime hosting API to divert the standard output and error streams (using the ScriptIO class) on a hosted Python Engine.

Snippets from Devhawk

Harry Pierson (Devhawk and Microsoft IronPython PM) regularly blogs interesting snippets of news. His "Morning Coffee 166" edition has several IronPython and Dynamic Languages related pieces of news.

There is a new Dynamic Language Runtime Hosting spec available (doc, pdf). If you're embedding IronPython into languages  like C#, VB.NET or even F# or Powershell, this is an invaluable and surprisingly readable document (well - if you like reading heavily technical documents).

As IronPython PM Harry has a new boss - Dave Remy. Dave doesn't blog, but Jim Deville, a new member of the Dynamic Languages team working mainly on IronRuby does.

There is also yet another new member of the Dynamic Languages team. Oleg Tkachenko, who also blogs.

IronRuby has a new wiki and homepage. The front page has a bright and shiny picture of Matz (Ruby BDFL) wearing a Python T-Shirt!

IronPython Parser AST Walker

A post by Michael (not me - another one...) on how to use the IronPython 1.1. parser from C#. By creating new expression walkers that inherit from the AstWalker class you can do interesting things with Python code parsed into an IronPython Abstract Syntax Tree:

IronPython 1.1.2 RC1 Released

IronPython 1.1.2 RC1 has just been released. This is the first release on the stable branch of IronPython for quite some time, and if all is well a 1.1.2 final should follow soon.
As might be expected, this is mainly a bugfix release.

However, there is at least one major new feature with the addition of the _winreg builtin module.

This release also fixes the following codeplex work items:
  • 16368 1.1.2: nt.access is missing
  • 16402 1.1.2: implement _winreg module
  • 15105 1.1.2: endpos is zero in IronPython 1.1.1
  • 16335 1.1.2: Event handlers can cause circular references and leak memory
  • 16337 1.1.2: Trivial: Implement float._lt_(float)
  • 16338 1.1.2: Using lambda in class definition will add into the
  • 16342 1.1.2: calling base class _call_ invokes constructor instead
  • 16343 1.1.2: problem with _slots_ and _init_ in new-style classes
  • 16347 1.1.2: Trivial: popen shouldn't open new window
  • 16348 1.1.2: Removes the inexistent file did not throw OSError in IP
  • 16350 1.1.2: int() doesn't convert representable longs to int
  • 16351 1.1.2: dict.update doesn't take keyword arguments - differs from CPython
  • 16353 1.1.2: Trivial: int('0x20', 16) fails to parse, long too
  • 16355 1.1.2: unpacking single element tuples in for-statement, listcomp and generator
  • 16356 1.1.2: socket.getnameinfo(...) broken under Vista
  • 16360 1.1.2: Class with slots and getattr not compatible
  • 16363 1.1.2: Can't call method w/ nullable as 1st argument w/ greater than 5 arguments
  • 16364 1.1.2: Backport fix for compiled regular expressions
  • 16365 1.1.2: Tuple hashing improvements
  • 16366 1.1.2: PyCFDONTIMPLY_DEDENT support in compile
  • 16749 1.1.2 (Trivial): Modifier of PythonEngine.DefaultCompilerContext(..)

Tuesday, July 01, 2008

Python Generation using the Code Dom

IronPython 1 has a CodeDom provider. This means that IronPython Studio can use it to generate Python code from the Windows Forms and WPF designers, and even generate executable files from Python projects.

This is one feature that hasn't yet made it into IronPython 2, but there are strange rumblings from the IronPython team that it may just make it.

In the meantime, 'tech-michael' has a blog entry showing how to use IronPython CodeDom to generate Python code from metadata.

How to Invoke Python Functions from C#

seshadripv has posted a blog entry, the second in a series, on using the DLR hosting API from C#. This entry shows how to execute Python code in a ScriptEngine to create a Python function, and then invoke that function (returning results) from C#. The entry includes a description of all the major components used, and full sample code.

Programming Languages @ PDC 08

Harry Pierson (IronPython PM for Microsoft) has posted some of the programming language sessions that will be part of the PDC 08 conference.

Naturally this includes a session on dynamic languages.

Deep Dive: Dynamic Languages in .NET
The CLR has great support for dynamic languages like IronPython. Learn how the new Dynamic Language Runtime (DLR) adds a shared dynamic type system, a standard hosting model, and support for generating fast dynamic code. Hear how these features enable languages that use the DLR to share code with other dynamic and static languages like VB.NET and C#.
For programming language geeks it looks like there is a lot to looks forward to at PDC, with sessions on F#, the future directions of both C# and VB.NET (both of which will include support for better working with dynamic languages), and C++.