How are you using IronPython?

Will Dean picture Will Dean · May 6, 2009 · Viewed 8.6k times · Source

I'm keen to drink some modern dynamic language koolaid, so I've believed all the stuff on Michael Foord's blog and podcasts, I've bought his book (and read some of it), and I added an embedded IPy runtime to a large existing app a year or so ago (though that was for someone else and I didn't really use it myself).

Now I need to do some fairly simple code generation stuff, where I'm going to call a few methods on a few .net objects (custom, C#-authored objects), create a few strings, write some files, etc.

The experience of trying this leaves me feeling like the little boy who thinks he's the only one who can see that The Emperor has no clothes on. If you're using IronPython, I'd really appreciate knowing how you deal with the following aspects of it:

  • Code editing - do you use the .NET framework without Intellisense?
  • Refactoring - I know a load of 'refactoring' is about working around language-related busywork, so if Python is sufficiently lightweight then we won't need that, But things like renames seem to me to be essential to iteratively developing quality code regardless of language.
  • Crippling startup time - One of the things which is supposed to be good about interpreted languages is the lack of compile time leading to fast interactive development. Unfortunately I can compile a C# application and launch it quicker than IPy can start up.
  • Interactive hacking - the IPy console/repl is supposed to be good for this, but I haven't found a good way to take the code you've interactively arrived at and persist it into a file - cut and paste from the console is fairly miserable. And the console seems to hold references to .NET assemblies you've imported, so you have to quit it and restart it if you're working on the C# stuff as well. Hacking on C# in something like LinqPad seems a much faster and easier way to try things out (and has proper Intellisense). Do you use the console?
  • Debugging - what's the story here? I know someone on the IPy team is working on a command-line hobby-project, but let's just say I'm not immediately attracted to a command line debugger. I don't really need a debugger from little Python scripts, but I would if I were to use IPy for scripting unit tests, for example.
  • Unit testing - I can see that dynamic languages could be great for this, but is there any IDE test-runner integration (like for Resharper, etc). The Foord book has a chapter about this, which I'll admit I have not yet read properly, but it does seem to involve driving a console-mode test-runner from the command prompt, which feels to be an enormous step back from using an integrated test runner like TestDriven.net or Resharper.

I really want to believe in this stuff, so I am still working on the assumption that I've missed something. I would really like to know how other people are dealing with IPy, particularly if they're doing it in a way which doesn't feel like we've just lost 15 years'-worth of tool development.

Update: (July 2010) This question's looking quite dated, now that there are both official IronPython Tools for VS and PyCharm both of which show a lot of promise and neither of which was around when I wrote it. Thanks to everyone who answered. To those of you who are happy without automatic refactoring tools, can I recommend that you never, ever, use an IDE with good automatic refactoring. After you have, you'll wonder why you thought you were ever happy with find-replace, and you'll never want to work without it again. If nothing else, the ability to instantly rename identifiers without worrying about replacing the wrong bit of text changes your whole approach to naming stuff.

Answer

Sake picture Sake · May 10, 2009
do you use the .NET framework without Intellisense?

Yes. I solely use emacs with IronPython. "M-/" is good enough for me. I occasionally switch to Reflector and MSDN when I really need information on the SDK.

Refactoring

You actually mean "Automatic Refactoring" when you said "Refactoring". I do a lot of Refactoring while coding. It could be better with some automation. But I'm fine with manual refactoring. It also force me to include more tests. I've never use any IDE with refactoring feature extensively, perhaps that's why I'm not suffering. Simple search-and-replace is fine for me.

Crippling startup time

Yes, this is my MAJOR pain, eventhough I'm working on 3GHz Quad-core with 4G Ram, it does takes 50s to run 359 test-cases. Half of that time (25s) is the startup time !! It seems IronPython perform some very heavy processing task when importing large module. I'm now planning to spit my tests into parts to mitigate this pain.

Interactive hacking - Do you use the console?

I use console occasionally, when I want to try some adhoc idea. Don't have problem with it. Most of the time I wrote my thought into unit-test, however.

Debugging - what's the story here?

If debugging means break-point and variable-inspection. I solely use print statement for that stuff. The kind of application I'm working on is about to live and keep being maintained for at least a decade. To handle defective code, I only bet on 3 things: comprehensible-code, unit-test and extensive-logging.

Unit testing

I never come close to any tool you mention. Just use unittest.TextTestRunner. Beside the horrible startup time, I do not have any other complains.

** UPDATED **

I just finish upgrading to IPy 2.6B1 with phenomenal result. The startup time reduce from 25s to 6s and my overall testing time reduce from 50s to 16s !!!

AMAZING !