question about core implementation language
Hi all, while reading all these long mails about this exciting project, one basic question came to my mind: why has the core implementation to be in C? Years ago I did a little programming in Objective C and I just loved this language (I'm taking about gcc objc without the framework by NeXT/Apple). Here are some good things about Objective C: 1. Legal C code is already legal Objective C code 2. Objective C has a runtime engine build in. 3. objects classes don't need to be known at compile time (just their interfaces) Having said that, I could imagine that it's much easier to model python objects in Objective C than in C, thus making the needed core more compact and easier to maintain. Stephan
Hi Stephan,
while reading all these long mails about this exciting project, one basic question came to my mind: why has the core implementation to be in C?
It does not have to.
Years ago I did a little programming in Objective C and I just loved this language (I'm taking about gcc objc without the framework by NeXT/Apple). Here are some good things about Objective C: 1. Legal C code is already legal Objective C code 2. Objective C has a runtime engine build in. 3. objects classes don't need to be known at compile time (just their interfaces)
Having said that, I could imagine that it's much easier to model python objects in Objective C than in C, thus making the needed core more compact and easier to maintain.
But the idea is to remove C alltogether, maybe keep it as a target "assembly" language for intermediate compiler output, and re-write everything in Python, in a way that a specializing compiler can choke upon. I have started some prototyping in Python, and I now remember some words of Guido, that Python isn't specially well suited for such a task. I admit, there is some truth in it. I'm sticking with the approach, but I have to fight the wish for a simpler mapping from C to Python. Some primitive sub-language with direct access to primitive objects by type declarations whould make life easier. But we don't want to change the language now, and I try to express everything by objects, which contain the necessary "hints". No idea if this is the concept that finally survives. My vision is that in a sprint, we do a Python interpreter rather quickly and then start to re-implement the basic objects. The resulting code should look improved, not worse. I have not much practice, yet. I will try a few approaches and post them for discussion. cheers - chris -- Christian Tismer :^) <mailto:tismer@tismer.com> Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/
I have started some prototyping in Python, and I now remember some words of Guido, that Python isn't specially well suited for such a task. I admit, there is some truth in it.
I don't understand Guido's comment. I personally think Python is absolutely superb for any prototyping endeavor. Perhaps I am being dense, but the fact that Python doesn't have feature x of language y seems totally a non-issue. You want a switch statement? Write a psyco_switch function (in Python, of course). Ditto for anything else your heart desires. Eventually _everything_ that generates code is going to become assembly code, but that is no problem at all for any compiler. Perhaps I am confusing levels of discussion or implementation. However, the way I see it, the most important thing is to do experimentation with algorithms. To do that, the essential thing is to compare various ways of doing things, at as high a level as possible. In other words, a psyco_switch routine provides a good enough model for the task at hand. Ditto for any other construct you want. Actually, for experimentation (perhaps leading to inspiration) I wouldn't necessarily confine myself to any particular level of implementation or design or whatever. I would simply blast away using whatever language tools appear to be most useful. Armin has talked about doing high-level work with discovering list optimizations, for example. I don't understand what the lack of a Python switch statement has to do with such matters. In short, I would hardly bother at all with questions of the level at which Python is modeling some implementation. I would use whatever works in Python and worry about mapping that back to a final implementation only after it is clear that Python in Python will be a big win. At that time we will have lots more data, energy and incentive to do the needed grunt work. Until then, I wouldn't let implementation problems get in the way of invention. Just my $0.02. Edward
Edward K. Ream wrote:
I have started some prototyping in Python, and I now remember some words of Guido, that Python isn't specially well suited for such a task. I admit, there is some truth in it.
I don't understand Guido's comment. I personally think Python is absolutely superb for any prototyping endeavor.
It is not superb if you want to directly map stuff from a completely different language, that C is. But as I said, this is only tempting. My conclusions are quite different, tho. ...
Perhaps I am confusing levels of discussion or implementation. However, the way I see it, the most important thing is to do experimentation with algorithms. To do that, the essential thing is to compare various ways of doing things, at as high a level as possible. In other words, a psyco_switch routine provides a good enough model for the task at hand. Ditto for any other construct you want.
Yes, I agree. That's not the problem. The problem is simply this: The algorithms written in C are written very very well. This is highly tested code, evolved for years, and it is as good as thinkable, given the known restrictions, like that it has to be C. My (our) problem is now, that we have to transliterate this quality code into Python, hopefully not destroying anything. Alongside, whe have to invent lots of new objects on-the-fly, as there appear so many structs and things, while you try to write a pythonic Python implementation of a C module. I tried this today with a module which I felt urgent to try to define for this project: frameobject.c . This module is less than 1000 lines, and it is one of the C modules which I know the best, due to my stackless work. I tried to map this module on a 3.5 hour yourney from Kiel to Berlin, and I had one fourth done by an hour. Nevertheless, I got into trouble, just by comparing its implementation differences between 2.2.2 and 2.3a. Then I dropped that and decided that this is the wrong way. It is not a simple task to do a good mapping into Python, although I know exactly how I would map this and that. But only the fact that the python-dev crew is working hard on all the C code makes them into our biggest enemies: The are changing the C code all the time, in all places, getting us into the role to program after them all the time. Between the lines, I recognized that I still would know the mapping that I wanted to apply from C to Python. I just hate to write this by hand, for similar reasons why I abandones Stackless 1.0 long time ago, simply since keeping track of changes is a PITA, unless *your* code is in the core. So what I am thinking to start instead is quite different, with the same target, but one level higher. I will post that after first experiments.
Actually, for experimentation (perhaps leading to inspiration) I wouldn't necessarily confine myself to any particular level of implementation or design or whatever. I would simply blast away using whatever language tools appear to be most useful. Armin has talked about doing high-level work with discovering list optimizations, for example. I don't understand what the lack of a Python switch statement has to do with such matters.
Simply try to implement something. Yes, it is fine. Try to re-implement ceval.c in an afternoon. It is 3900 lines of code, well-written C code, a huge switch statement, and you find yourself writing all those case cases as tiny functions inside a class. Sure it is possible. What the matter is? I have to change something substantial, there is no trivial mapping, but a more complicated one.
In short, I would hardly bother at all with questions of the level at which Python is modeling some implementation. I would use whatever works in Python and worry about mapping that back to a final implementation only after it is clear that Python in Python will be a big win. At that time we will have lots more data, energy and incentive to do the needed grunt work. Until then, I wouldn't let implementation problems get in the way of invention.
I had the same POV before I started to try coding. You are absolutely right, the implementation does not matter so much. In extent, if it doesn't matter too much, then there is no need to do this by hand. Please give me two days to try this, then I will hopefully show a way how to do it *not by hand*. all the best -- chris (too old to do this by hand)
Hello Stephan, On Sun, Jan 19, 2003 at 01:50:25PM +0100, Stephan Diehl wrote:
Here are some good things about Objective C: 1. Legal C code is already legal Objective C code 2. Objective C has a runtime engine build in. 3. objects classes don't need to be known at compile time (just their interfaces)
This makes it a good candidate to experiment with. Remember, the purpose of this project is not to write the interpreter in C but in Python, and use C as an intermediate assembly-level language. I talked about targetting other intermediate languages for their runtime engines, like OCaml which has a very good GC, but that will come later. Objective C and Java are also potential targets (though I must admit I prefer cleaner high-level languages). A bientot, Armin.
participants (5)
-
Armin Rigo -
Boyd Roberts -
Christian Tismer -
Edward K. Ream -
Stephan Diehl