views:

424

answers:

6

Hey guys!

I do understand that this topic has been covered in some way at StackOverflow but I'm still not able to figure out the exact answer: can I treat IronPython as a Pythonic replacement to C#?

I use CPython every day, I love the Zen :) but my current task is a Windows-only application with a complex GUI and some other features which I would like to implement using .NET.

+9  A: 

That depends on what it is about C# that you need, and which needs replacing.

If the reason you use C# is that you need a reasonably high performance statically typed language then no, IronPython is likely not going to be a replacement.

If the reason you use it is simply "I need something that runs on .NET and can access .NET libraries", then yes, any language that runs on .NET can be used to replace it.

If you use C# because you're working with a team of programmers who only know C-like languages, C# might also be difficult to replace with IronPython.

It depends on what characteristics about C# it is that you care about, and need to find replacements for.

jalf
Yes, my case is exactly what you've described: I need a language that runs on .NET and uses .NET libraries :) Thanks for the reply.
Ewan Nathaniel
If the reason you use it is simply "I need something that runs on .NET and can access .NET libraries", then check out Boo. It is very Pythonic in syntax, but will generate .NET assemblies and executables just like C#. IronPython doesn't do this.
Paul McGuire
Thanks, Paul. I've checked it out, that's great and I will dive into it soon.
Ewan Nathaniel
+2  A: 

One thing to consider - and I have no idea how IronPython behaves in that respect - is Common Language Subsystem (CLS) compliance for assemblies. CLS compliance guarantees that any .Net language can access a compiled DLL of your code. That means e.g. in C# you cannot have any public or protected method or parameter that is a unsigned integer. I have no idea how easy it is to achieve CLS compliant code in IronPython, an interesting blog entry that I found dates from 2008.

Residuum
Thanks, Residuum. That's a really interesting issue.
Ewan Nathaniel
+1  A: 

The question "Can I treat IronPython as a Pythonic replacement for C#?" has been answered pretty well by jalf. If the question were "Is IronPython a Pythonic .NET Language?" though, then the answer would absolutely be yes. The principles of Zen - esp. least surprise - absolutely apply to IronPython's integration with the CLR as well.

Thanks, John. I spent the whole day trying to decide and now I'm almost certain about not using IronPython. I think that C# or (less likely) Boo will be my choice.
Ewan Nathaniel
I do think that being fluent in C# is a very important skill to acquire, even if you eventually use Boo or IronPython to prototype. Not too familiar with Boo yet, but I'm sure it will be closer to C# than IronPython being statically typed and all. Boo also claims performance of the same order as C#.
+11  A: 

IronPython is NOT equivalent to "other languages that run on .NET", as the language has support for substantially fewer CLR runtime features.

IronPython classes are not "real" .NET classes, and DLR APIs need to be used when calling IronPython code from traditional CLR-based languages; this means that if you want genuinely easy interoperability, you're stuck writing glue to "hide" the DLR.

Boo is a much more complete Pythonically-inspired language targeting the CLR. Its (dynamically inferrable) static typing (which can be replaced with duck typing on a variable-by-variable basis) also allows libraries written in Boo to be natively used from C# and other CLR-based languages, without needing to make any allowances for the language in use.

Charles Duffy
So if I'm going to start development of a large and complex application under .NET (and that's what I'm actually going to do) IronPython shouldn't be my choice? I mean I do like Python but everything must be on it's own place. Am I right?
Ewan Nathaniel
@Ewan - I expanded and clarified my answer -- but the short form is that yes, you're right; IronPython is great for calling .NET languages, but if you're going to be doing anything where you'll be called from conventional CLR code, things suddenly get ugly and unidiomatic. Jython has the same problem.
Charles Duffy
Thanks a lot, Charles. You've just saved me from a huge time loss :)
Ewan Nathaniel
A: 

I think if you were to do that, it would be easier in .NET 4.0.

I think you can use the newly released IronPython 2.6.1 for .NET 4.0,

It is already easy to use C# in IronPython.

As you can see here, you can easily do it the other way around (using IronPython from C#) with .NET 4.0.

I think its possible, but I agree Boo is a safer way to go.

jcao219
Well I know that I could do it if I'd treat it as a goal. But it's not a goal :) I thought that IronPython is an alternative language that can be used as a complete replacement to C# under .NET.
Ewan Nathaniel
A: 

"Complex" UI usually entails not "writing" it but building it within Visual Studio with point and click. All the callbacks and eventing code is inserted by itself. There is almost nothing like that on python side. I'd say go for C# straight out.

There is one nagging thing though. If you are true Pythonista, the static typing will get to you very very quickly and you will want to start throwing heavy objects at random people.

If that point comes think about building out the UI with C# and embedding IronPython as a scripting engine for implementing your business logic. That could be a tolerable middle ground.

ddotsenko