Why Python won't work on .net

A

Allenabethea

Jython is 100% java coded python.
Python objects work with javacompilers and Virtual machines.

I am a hobby programmer so the technical reasons are probably beyond me...
Why is python incompatible with .net? Why can't python be coded in C#?

I see the the MONO project on linux/unix is advancing. .Net seems to be a
juggernaut especially if programmers will be able to use their favorite(most
productive) language to program in. (every language but python)

I am a new python tinkerer. I love the language. But what is its future but as
a legacy tool?

allen
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

Why is python incompatible with .net? Why can't python be coded in
C#?

Who says that it cannot be coded in C#. It is a matter of fact that it
currently isn't, but it would be possible to reimplement the Python
interpreter in C# (instead of implementing it in C).

As for generating MSIL byte codes: This is also possible, and has been
demonstrated. It also has been demonstrated that an initial
implementation is likely to be *very* slow.

The question is whether a Python implementation for .NET would be CLS
compliant (CLS == Common Language Specification). The existing
implementation has shown that this is not possible without giving up
parts of the Python semantics.

I am a new python tinkerer. I love the language. But what is its
future but as a legacy tool?

No. Instead, most .NET users will find out that .NET is *not* a
juggernaut, but restricted to C#, in practice. So Python might even
survive .NET :)

That said: If you think the Python-.NET story should be a better one,
feel free to contribute. Python is a volunteer effort, and without
volunteers, there will be no progress. Before starting, please have a
look at the excellent Python-for-.NET, which uses the native-code
Python implementation to host .NET, giving Python programs full access
to the framework.

Regards,
Martin
 
G

Gustavo Campanelli

Allenabethea said:
> I am a new python tinkerer. I love the language. But what is its future but as
a legacy tool?

allen

As far as I've learned so far, .net is good for client server but not
that great for standalone because of the need for the .net runtime to
run things, which creates a large overhead. Performance is an issue too,
as everything compiles JIT. I think that's why although .net is a great
idea, a lot of languages will remain language of choice for
standalone/no runtimes/speed critical/cross platform aplications. I
could be wrong, but I don't think I'm far from the truth.

Gustavo Campanelli
 
V

Ville Vainio

I am a new python tinkerer. I love the language. But what is its
future but as a legacy tool?

What, has .NET suddenly turned out to be popular while I wasn't
watching? The whole world is hardly jumping on the .NET platform,
actually mostly people seem to be ignoring it...

Or is this a troll of some kind?

You might also want to take a look at:

http://zope.org/Members/Brian/PythonNet/
 
C

Cameron Laird

.
.
.
As for generating MSIL byte codes: This is also possible, and has been
demonstrated. It also has been demonstrated that an initial
implementation is likely to be *very* slow.

The question is whether a Python implementation for .NET would be CLS
compliant (CLS == Common Language Specification). The existing
implementation has shown that this is not possible without giving up
parts of the Python semantics. .
.
.
No. Instead, most .NET users will find out that .NET is *not* a
juggernaut, but restricted to C#, in practice. So Python might even
survive .NET :)
.
[still other points
elided for space]
.
.
Martin's right. Everything he says here is true, AND
it's not what the .NET Propaganda Ministry teaches, so
I think it's worth repeating.

..NET (and C#, for that matter) is (are) an interesting
technologic story. It's certainly not a purely evil
conspiracy to contaminate our body fluids; on the other
hand, it's not the greatest thing since the domestica-
tion of the camel, as sometimes portrayed. I'm putting
my bet on Python outlasting .NET.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Ville said:
What, has .NET suddenly turned out to be popular while I wasn't
watching?

Where I work, .NET is pretty popular. People are fascinated of
introspection/reflection, (relative) platform-independence,
ubiquitous serialization, powerful development tools, and the
back-up of a large company.

Of course, they all use C#, and consider the other .NET languages
toys.

Regards,
Martin
 
D

Duncan Booth

(e-mail address removed) (Martin v. =?iso-8859-15?q?L=F6wis?=) wrote in
As for generating MSIL byte codes: This is also possible, and has been
demonstrated. It also has been demonstrated that an initial
implementation is likely to be *very* slow.

The question is whether a Python implementation for .NET would be CLS
compliant (CLS == Common Language Specification). The existing
implementation has shown that this is not possible without giving up
parts of the Python semantics.
The main problem is that functions are first class objects in Python, but
not in the CLS. The CLS uses delegates to refer to functions, and a
delegate encapsulates both an object and a pointer to a method.

The CLS does have pointers to methods, but the situations in which they can
be used are limited by the code validator: there are two MSIL code
sequences which may be used to construct delegates, one for static
methods, one for non-static, both involve pushing a function pointer onto
the stack and then calling the delegate constructor, but in neither case
can the function pointer come from a variable.

To model Python within the environment, you can use a delegate to refer to
a static function (the object reference is null in this case), or to refer
to a bound method, but you cannot easily create a delegate to refer to an
unbound method. This makes any Python code using classes extremely hard to
model.

The original attempt at porting Python to this environment used the
reflection classes to get around this. Using reflection you can get objects
which indirectly reference classes and their methods, you can then create a
delegate from a System.Reflection.MethodInfo object at the point where the
unbound method becomes a bound method. Unfortunately, creating a delegate
from a MethodInfo is a couple of hundred times slower than creating a
delegate from a pointer to a method.

It is even possible to get a pointer to a method and then create a delegate
from it entirely within the constraints applied by the code validator, but
again this uses the Reflection classes and is at least as slow as using the
MethodInfo object.

I have been playing around with a variant on the managed Python compiler,
and I think I have figured a way to implement Python which might just get
around this bottleneck. Unfortunately it requires a lot of refactoring from
the original model, and I'm only working on it occasionally in my spare
time. Basically the idea is to compile static wrapper functions for every
method (at runtime). Obviously this is slow, but at least you only take the
hit once per class. Every unbound method, or bound method can keep a
delegate to the static wrapper, and we lose the overhead of the reflection
classes. Wrapper functions can also wrap constructors.

So far most of my refactoring has been concentrating on replacing the
original runtime with one based on a class hierarchy and modelling some of
the more recent Python behaviour. This simplifies and also speeds up the
code somewhat, although I think I have just about reached the limits I can
achieve before I do the function wrappers.
 
M

Michael Hudson

Martin v. Löwis said:
Where I work, .NET is pretty popular. People are fascinated of
introspection/reflection, (relative) platform-independence,
ubiquitous serialization, powerful development tools,
....

and the back-up of a large company.

Oh :)

More sponsorship for the PSF, please!

Cheers,
mwh
 
T

Terry Reedy

Duncan Booth said:
The main problem is that functions are first class objects in Python, but
not in the CLS.

Thank you for this and the persuant explanation. I had been wondering
whether a .NET subset would be sensible. Hah! The design principle of
'everything, including funtions, is a (first-class) object' is part of the
beauty and ease-of-use of Python. Demotion of functions would point toward
'calculator Python'.
The CLS uses delegates to refer to functions, and a
delegate encapsulates both an object and a pointer to a method. ....
I have been playing around with a variant on the managed Python compiler,
and I think I have figured a way to implement Python which might just get
around this bottleneck.

Good luck. Not directly useful to me, but success can only promote the
usage of Python.

Terry J. Reedy
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

Duncan Booth said:
The main problem is that functions are first class objects in Python, but
not in the CLS. The CLS uses delegates to refer to functions, and a
delegate encapsulates both an object and a pointer to a method.

In addition, I think one problem is that in CLS, a class has a
pre-determined set of data attributes, whereas in Python, instances
grow new data attributes as they live.
I have been playing around with a variant on the managed Python compiler,
and I think I have figured a way to implement Python which might just get
around this bottleneck. Unfortunately it requires a lot of refactoring from
the original model, and I'm only working on it occasionally in my spare
time.

Very interesting. Are you willing to share the intermediate results
that you get? Publish early, publish often :)

Regards,
Martin
 
C

Cameron Laird

.
.
.
beauty and ease-of-use of Python. Demotion of functions would point toward
'calculator Python'.
.
.
.
.... still a shockingly useful language. I know of many,
many applications which do nothing which requires func-
tion-first-classness, and quite a number which define no
new classes.
 
Y

Y2KYZFR1

Martin v. Löwis said:
Where I work, .NET is pretty popular. People are fascinated of
introspection/reflection, (relative) platform-independence,
ubiquitous serialization, powerful development tools, and the
back-up of a large company.

Of course, they all use C#, and consider the other .NET languages
toys.

Regards,
Martin


only if you mean Windows 95, 98, ME, 2000, XP as "platform
independant"

..Net is and for all PRACTICAL PURPOSED be a WINDOWS ONLY development /
runtime environment.
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

only if you mean Windows 95, 98, ME, 2000, XP as "platform
independant"

People enjoy running .NET applications on OS X, through Rotor.

Regards,
Martin
 
C

Courageous

Functions are only addresses in C, the (main) language Python is
implemented in.

C//
 
D

Derrick 'dman' Hudson

It's not. The .net virtual machine is Turing Complete.

Sure, you could create and run a python interpreter on the .NET
runtime, but how is that better than running the C implementation?
Presumably people who discuss .NET integration are looking for the
sort of language-agnostic plug-and-play that .NET promises. This is a
different scenario than simply re-implementing python on a new
platform.

-D

--
Contrary to popular belief, Unix is user friendly.
It just happens to be selective about who it makes friends with.
-- Dave Parnas

www: http://dman13.dyndns.org/~dman/ jabber: (e-mail address removed)
 
F

Fredrik Lundh

Courageous said:
Functions are only addresses in C, the (main) language Python is
implemented in.

what parts of "The CLS does have pointers to methods, but the situations
in which they can be used are limited by the code validator" and "in neither
case can the function pointer come from a variable" did you have trouble
understanding?

</F>
 
D

Duncan Booth

(e-mail address removed) (Martin v. =?iso-8859-15?q?L=F6wis?=) wrote in

In addition, I think one problem is that in CLS, a class has a
pre-determined set of data attributes, whereas in Python, instances
grow new data attributes as they live.

I don't believe that is too much of a problem. Even in Python many of the
data types have a fixed set of attributes. Even user defined classes, if
they use __slots__, might not allow you to add attributes.

So, for .Net, some user defined classes might have a __dict__ attribute,
but others don't. Attributes which are accessed through __dict__ won't be
visible to non-Python code, but that shouldn't be a problem.
Very interesting. Are you willing to share the intermediate results
that you get? Publish early, publish often :)
I'm more than willing to share, but so far its been a massive refactoring
job so I was waiting until things settled down a bit before releasing
anything. I expect the main speed gains to come when I get the new model
for functions and methods working and eliminate as far as possible calls
the reflection apis.
 
J

John J. Lee

Who says that it cannot be coded in C#. It is a matter of fact that it
currently isn't, but it would be possible to reimplement the Python
interpreter in C# (instead of implementing it in C).

As for generating MSIL byte codes: This is also possible, and has been
demonstrated. It also has been demonstrated that an initial
implementation is likely to be *very* slow.

http://www.python.org/~jeremy/weblog/

"""Jim Hugunin is at it again""":

http://primates.ximian.com/~miguel/ironpython

"""I've been working off and on for the past couple of months on a new
implementation of Python for the CLR called IronPython. It compiles Python
programs into verifiable IL and then dynamically executes them."""

Interestingly, many of the (micro-) benchmarks show that IronPython is
*faster* than Python 2.3.

The question is whether a Python implementation for .NET would be CLS
compliant (CLS == Common Language Specification). The existing
implementation has shown that this is not possible without giving up
parts of the Python semantics.
[...]

Still true, I guess.


John
 
D

Douglas Crockford

Why is python incompatible with .net? Why can't python be coded in C#?
It's not. The .net virtual machine is Turing Complete.

The subject here is imprecise. The issue is that .net performs very poorly with
dynamic languages. So, for example, Microsoft is adding static features to
JScript in an attempt to improve its performance.

..net is having a homogenizing effect on programming languages. In the end, they
may all become the same. And the ultimate .net language will not be Python.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,477
Latest member
ColumbusMa

Latest Threads

Top