tags:

views:

1708

answers:

11

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.

+1  A: 

My use of IronPython has been limited to making quick prototypes for myself, so I can't say too much about it. But if you're looking for an IDE specific to IronPython, IronPython Studio is passable. It'll give you some Intellisense functionality, although it is a bit flaky at times, so do not close that MSDN documentation window just yet. It will allow you to interactively debug like any other .Net project. Also it supports the Visual Studio 2008 forms designer if you prefer to make your GUI's that way. I haven't tried it, but it may also support running nUnit tests using TestDriven.net.

Sadly, renames and other refactoring features offered by VS 2008 seem to be unsupported.

Jeras
Thanks for this - I was aware of IPyS, though I haven't tried it, but its abandoned status and support only for IP1 doesn't feel very confidence-inspiring.
Will Dean
+1  A: 

I'm using IPy in an embedded environment for running test scripts.

1 & 2. You are right there is not much support for code editing or refactoring -- proper Visual Studio support would be great.

Ignoring your third point -- interpreted vs compiled is an age-old argument.

Haven't done much of interactive hacking yet, so can't comment on 4th point.

I use the Visual Studio debugger to debug my IPy scripts.

Don't know about a unit test IDE integration either.

Rohit
Thanks for the answer, but I think your dismisal of the compiled vs interpreted bit is misplaced. Advocates of (Iron)Python often cite the rapid interactivity of the development as an advantage. The reality is that this is absent with current IPy versions, because the startup time exceeds compile time for small applications.
Will Dean
Hmmm ... you have an example program which illustrates that? Thanks.
Rohit
+1  A: 

I am using Iron Python, not professionally, unfortunately, but as a Rapid Development language for my personal projects.

Python is such a great language for ease of use, brevity but readability of code and simplicity. Some of this is due to it being a dynamic language, but also its basic syntax.

I am, however no cpython guru, and can get so much more out of Iron Python than cpython as I can easily leverage the .NET platform, on which I am far more at home. I am disappointed there is currently no port to the Twisted libraries in cpython, the only extended Python libraries I am comfortable with, as they would be so useful in .NET.

I also use the interactive window just to test .NET structures when I am coding in C#.

johnc
+5  A: 
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 !

Sake
+1 about emacs for python development
pygabriel
As for the "refactoring" subject, I recently start to learn using "ropemacs", the python refactoring for emacs, and it's pretty good. Now I can do automatic refactoring without leaving emacs. :)
Sake
+2  A: 

I am using PyDev to write IronPython code. I am trying to separate .NET specific code as much as possible so that I can run the (Iron)Python scripts from within PyDev. Thanks to PyDev, I can use Pylint which can be found at http://www.logilab.org/857. Recent versions of PyDev are able to configure the interpreter even per file or project basis. So, I can easily switch the interpreters from IronPython to CPython and vice versa. By this way, I can see that my code is portable between Python implementations. (Although I am not using, Jython 2.5 RC can be used in PyDev too.)

Having Python and IronPython 2.5 compatible code, I can use the refactoring in PyDev, see http://pydev.sourceforge.net/refactoring.html.

IronPython Studio would be a good choice if it supported IronPython 2.x, but sadly, it does not.

Caglar Toklu
+2  A: 

IronPython is a great solution, but I keep going back to CPython for Windows. Why ?

In my experience CPython under Windows, Mac OS/X and *NIX are virtually the same. I can use almost all of the "batteries" in each environment. I frequently develop applications on Linux and ship to Windows servers. A couple of issues with threading aside, I've had no issues.

IronPython, on the other hand, is a Python language wrapper around the .Net Framework. I find it much nicer to use than C#, but that's about all. My CPython programs don't work without considerable reworking. The batteries for IronPython are different.

If your goal is to be productive on .Net then IPy is probably Ok. However, if you are seeking portable Python skills, then I would avoid it.

CyberED
A: 

I just bought Foord's book so right now I'm only learning it. I really hope to use it for web development but sadly I have to wait until it is supported with asp.net mvc. I also plan to use it as a scripting tool for windows systems since I can utilize the .net framework

Wayne M
You might interesting in this http://stackoverflow.com/questions/441838/ironpython-on-asp-net-mvc
Sake
I'm looking at that, but it seems that MVC with IronPython is still rough around the edges - it seems to only work with Views, and nothing else.
Wayne M
+1  A: 

I'm running a set of blackjack simulations on Python 2.6 vs. IronPython 2.6, and hype notwithstanding, IronPython seems to be just a little bit slower (maybe by about 10%?) The code is very simple, just stuff like:

def highcount(hand):
  total=0
  for c in hand:
    if c[1]==11 and 11+total>21:
      total+=1
    else:
      total+=c[1]
  return total

and

def dmove():
  if ( (dhand[0][1]==11 and dhand[1][1]==10) or 
       (dhand[0][1]==10 and dhand[1][1]==11) ):
    return 21 # should return blackjack

  while 1:
    lc=lowcount(dhand)
    hc=highcount(dhand)
    if lc>21: return lc # dealer busts
    if lc>=17: return hc # stand on soft 17
    if hc>=17: return hc # stand on hard 17
    dhand.append(deck.pop()) # hit otherwise

If the .NET VM optimizations are similar to the JVM's Hotspot is quite possible that over longer runs, IronPython may run the simulation faster.

Another important point to note is the blackjack simulation easily lends itself to spawning on multiple threads which CPython's GIL makes completely worthless in terms of the speed boost. With IronPython I do get the full 400% speedup on a quadcore, which is really really cool.

The code does not make use of any esoteric Python features (that's a good thing) which meant that it ran 100% unmodified on IronPython.

+6  A: 

How about IronPython Tools for Visual Studio 2010?

IronPython tools provide a Python code editor, a file-based project system, and an interactive Python interpreter, all inside Visual Studio 2010, and all for free. http://ironpython.net/tools/

I think this add-in would cover most of your points.

Hope it helps,

Patrick

Patrick
+1  A: 

PyDev, Wing, PyCharm and IronPython Tools for Visual Studio all support intellisense for .NET under IronPython. I have a feeling that SharpDevelop also has intellisense for IronPython.

Startup time improved a lot under IronPython 2.6 and again in 2.7. It is still considerably slower than CPython however.

Bicycle repairman and rope are two popular automated refactoring tools for Python. I've never found a need for either of them.

pdb (the Python standard library debugger) works with IronPython. PyDev, SharpDevelop and IronPython Tools for Visual Studio all support debugging for IronPython.

I've used integrated testing tools (Wing has good unittest support SharpDevelop supports unittest and unittest2 for IronPython, PyDev and PyCharm probably have good unittest integration too). I prefer running my tests from the command line. unittest2 is great for this as it removes the need to write your own test collection / running code.

I use the interactive interpreter for experimentation a great deal and occasionally as a souped up shell.

fuzzyman
You see what I mean about startup time - it's taken you over a year to answer my question ;-) Interested to know how you take code out of the interactive console into a text file once you're done experimenting. Do you just retype it?
Will Dean
I rarely reuse code from the interactive interpreter, it's just experimental code. If you're typing anything non trivial then do it in a python file! Copying and pasting short segments is bearable.
fuzzyman
A: 

boo faster than ironpython 2.6.1.

Kartono Wahid Iqbal