开发者

Can I treat IronPython as a Pythonic replacement to C#?

开发者 https://www.devze.com 2022-12-26 16:36 出处:网络
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 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 applicati开发者_JAVA百科on with a complex GUI and some other features which I would like to implement using .NET.


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.


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.


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.


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.


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.


"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.

0

精彩评论

暂无评论...
验证码 换一张
取 消