Wednesday, March 03, 2010

Why IronPython for VFP Veterans?

IronPython is a .Net implementation of Python developed and maintained by Microsoft, even though the product itself is open sourced under an OSI-approved license.

Python itself is a dynamically-typed, class-based language that is extremely well-designed and supported (through a large user community and strong administration of the Python open-source project).  It is one of the official languages at places like Google, Yahoo, Facebook and NOAA (think: hurricane center).  In other words, it has Enterprise acceptance.  In terms of “popularity” indexes, it is 3rd behind C# and Java.

It has a command window: everything can be tested from the command window, just as in VFP.

As of .Net 4.0, Python is very easy to call from a .Net program, using the new Dynamic keyword.  It has always been easy to call .Net from within IronPython.

What makes Python in general a friendly language for VFP developers is that it is a dynamic language, and Classes have the same form of inheritance as VFP. In addition, you can create the equivalent of procedure files, by writing functions inside a file, referencing the file (equivalent to SET PROCEDURE TO in VFP) and then simply using the functions. Combined with its ability to work in a friendly manner with .Net, it offers VFP developers a way to develop business logic (which should sit in their own classes anyway) in much the same way we have done it in VFP.

Learning IronPython

To get started in Python, you can get a good introduction to the language in an online tutorial on the IronPython site.  The standard Python bible is Mark Lutz’s Learning Python.  If you’re just getting the physical book, you can get it from Amazon for a lot less than from O’Reilly, although O’Reilly has the e-book, and a physical e-book combination, and a Buy 2 Get 1 Free offer.  Anyway, one way or the other, you will need this book.

There is only 1 book on IronPython, namely IronPython In Action by Michael Foord. Fortunately, it appears to be a good book. He doesn’t appear to be in for the money: he lists a 35% discount on the book on the linked web site, above.

Getting Started In Python

The only really bad news about IronPython is the lack of a first-class IDE in Visual Studio for working with it.  It is not a first-class citizen in the Visual Studio IDE, including the just-released VS2010.  If you come across Visual Studio Tools for IronPython, be aware this was a demo lacking lots of features, and only works with IronPython 1.0.  In other words, it’s useless.

The good news is that SharpDevelop, the same IDE that VFP.Net used in its lamentably brief incarnation, has a pretty decent IDE for IronPython, than even includes Winforms and WPF form designers that spit out IronPython code.  That is a good thing, and no other IronPython IDE does that.  In addition, SharpDevelop is reputedly relatively easy to work with in creating add-ins, so there may be an opportunity to create builders as we had in VFP, to assist in alleviating some of the scut work in initial design, and class changes, with form development.  Matt Ward’s blog entries on IronPython are a big help in working with SharpDevelop using IronPython.

There are other IDE’s available.  The same people who brought us ReSharper (an indispensible tool when working in Visual Studio with the statically-typed languages) are alpha-testing an IDE for IronPython, PyCharm.   Michael Foord, mentioned above from has an article on IronPython IDE’s.  Wing, which he uses, costs $ but he likes it.  Eclipse looks pretty good to me also: note that the PyDev extensions are now free.  Pick your own poison, as it were, but the work I am doing will be in SharpDevelop (3.2 for now, until 4.0 is released). 

Now, if you would like to know when Visual Studio will include IronPython as a first-class language, well, so would a lot of other folks.  If you think this is a good idea (and why would it not be?), you can go to Microsoft Connect, and Vote YES*.  Please?

So How Would This Work?

Let’s isolate the major components of an application in which users add or change data:

  1. Design and create the data, and make it available to the application. (xCase, xCase2PSP.Net, AAPL4PSP)
  2. Create the User Interface that will use the data.
  3. Wire up the data to the interface.
  4. Create the business rules that govern data changes and UI changes.
  5. Wire up the business rules to the interface.

I’ve fuzzed over where these things happen: they can be 1-tier (think: table-based VFP application running on the desktop); 2-tier (think: SQL-based VFP application running on the desktop); 3-tier (think: web or desktop application running against a service, web or windows, that hits against a SQL Server backend); or more tiers if things get really complicated.  These steps still have to be done.

IronPython will play three roles in any of these scenarios: 1) as the programming language of the classes and programs comprising the application framework (Step 3, and the foundation of Step 5); 2) as the programming language for the methods and functions comprising the business rules for data and UI (which you will write for the application); and 3), thanks to SharpDevelop Visual Designer integration with IronPython, as the language behind the form design.

The value of IronPython for creating the classes of the application framework is that we will be able to let you subclass them just as you are used to in VFP (at least if you use our stuff), that is, for as many levels as you want.  That’s something you can’t do in .Net.  If you have worked with us in using the Visual ProMatrix framework as modified by ProSysPlus, you know how handy it is to put your code in the application-level sublcass, while also being able to make more wide-spread changes in the “developer organization” subclass from which the application subclass inherits. 

The value of being able to program your business rule methods and expressions in IronPython is the ability for you to instantiate classes from the IronPython console and test things out dynamically.  There is no substitute for that.

The value of having the visual design expressed in IronPython is that you will be able to use IP to handle custom programming of controls and forms for those special forms that need more than metadata can provide.

How IronPython Will Work With .Net Objects

IronPython just plain works with .Net objects.  We will have some work to do in adjusting the templates to make the calls out from control events to the framework (think: in VFP terms, WHEN, GETFOCUS, VALID, LOSTFOCUS, etc.).  Supposedly <s>, that isn’t too difficult.

So, we will be creating add-ins and adjusting SharpDevelop for PSP.Net, which will be the name of the project.  Like the other parts of PSP.Net, this will be open source, for financial reasons as detailed here (when I get it written). 

 

________

* And anyone who votes yes (I’ll take your word) and comes by Berea, KY is entitled to the drink of their choice at Berea Coffee & Tea, provided of course that you don’t mind chatting with me as I have one too. <s>  Free wireless, soft chairs.

0 comments: