Why is python not written in C++ ?

C

candide

Python is an object oriented langage (OOL). The Python main
implementation is written in pure and "old" C90. Is it for historical
reasons?

C is not an OOL and C++ strongly is. I wonder if it wouldn't be more
suitable to implement an OOL with another one.

Has it ever been planned to rewrite in C++ the historical implementation
(of course in an object oriented design) ?
 
T

Terry Reedy

Python is an object oriented langage (OOL). The Python main
implementation is written in pure and "old" C90. Is it for historical
reasons?

Python was first released before C++. C is available on, and hence
Python runs on, systems that do not have C++ available.
C is not an OOL and C++ strongly is. I wonder if it wouldn't be more
suitable to implement an OOL with another one.

Python's object system is sufficiently different from that of C++ that I
doubt the latter could used with much profit.
Has it ever been planned to rewrite in C++ the historical implementation
(of course in an object oriented design) ?

Proposed and rejected. Not every C programmer knows or wants to learn C++.
 
R

Roy Smith

candide said:
Python is an object oriented langage (OOL). The Python main
implementation is written in pure and "old" C90. Is it for historical
reasons?

C is not an OOL and C++ strongly is. I wonder if it wouldn't be more
suitable to implement an OOL with another one.

One thing that comes to mind is that it's much easier to distribute C
libraries than C++ libraries.

If I compile a main program with one C compiler and you compile a
dynamically loaded library with another C compiler on the same box, the
odds are pretty good they'll interoperate without any problems.

Not at all so with C++ compilers. The linkage is *way* more
complicated. Not just how the two compilers do name mangling, but how
they handle exceptions, RVO, and a zillion other details. Pretty much
the only way to make it work is to compile everything with exactly the
same compiler. That would make it pretty close to impossible for people
to take a Python core distribution and add their own extension modules
to it.
 
J

John Bokma

Terry Reedy said:
Python was first released before C++.

C++ was named C++ in 1983 (development on it started in 1979) and the
first commercial implementation was released in 1985 [1]. Implementation
of Python started in December 1989 [2].

So: no. (I was quite sure on this, since I started to program in C++ in
the late 80's/early 90's IIRC).

[1]
http://en.wikipedia.org/wiki/C_plus_plus#History

[2]
http://en.wikipedia.org/wiki/Python_(programming_language)#History
http://python-history.blogspot.com/2009/01/brief-timeline-of-python.html
 
J

John Bokma

Roy Smith said:
One thing that comes to mind is that it's much easier to distribute C
libraries than C++ libraries.

In the beginning of C++ there were programs that just converted C++ to C
(frontends). At least that is how the C++ compiler Acorn sold worked.
So I don't think your argument was much true back then.
 
T

Tomasz Rola

In the beginning of C++ there were programs that just converted C++ to C
(frontends). At least that is how the C++ compiler Acorn sold worked.
So I don't think your argument was much true back then.

Those that I (tried to) used on Amiga were based around the same concept.

It seems, that Comeau C++ compiler (which I never tried) still requires C
compiler as a backend (and is highly regarded by some).

Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature. **
** As the answer, master did "rm -rif" on the programmer's home **
** directory. And then the C programmer became enlightened... **
** **
** Tomasz Rola mailto:[email protected] **
 
C

Carl Banks

Roy Smith said:
In the beginning of C++ there were programs that just converted C++ to C
(frontends). At least that is how the C++ compiler Acorn sold worked.
So I don't think your argument was much true back then.

No, it was that way back then too. They might all generate C code but
different C code by different backends wouldn't be able to call each
other natively.

For instnace the function

int foo(int);

might be name-mangled this way in one cfront:

foo$d

and this way in another:

____int_foo__int_i


The virtual table of this class:

class Bar {
virtual int foo(int);
virtual int bar(int);
};

might be generated like this in one cfront:

struct Bar$$Vtable$ {
int (*Bar$$bar$d)(int);
int (*Bar$$foo$d)(int);
};

and like this in another:

struct ____class_Foo___vtable_ {
int (*foo)(int);
int (*bar)(int);
};


So, just because they both generated C code, it doesn't mean they can
call one another.


Carl Banks
 
A

Albert Hopkins

Python is an object oriented langage (OOL). The Python main
implementation is written in pure and "old" C90. Is it for historical
reasons?

C is not an OOL and C++ strongly is. I wonder if it wouldn't be more
suitable to implement an OOL with another one.

Has it ever been planned to rewrite in C++ the historical implementation
(of course in an object oriented design) ?

Disclaimer: I am neither a C nor C++ programmer. In fact I can barely
even program in Python ;-)

I would propose that in fact most programming languages are implemented
in C. Sun's (Oracle's) Java compiler and runtime are written in ANSI C.
The core of the Gnu Compiler Collection (which includes C++ and
Objective-C compilers) is written in C. The official Ruby is
implemented in C. The Squeak Smalltalk implementation uses C instead of
C++. I can't even think of a programming language that is implemented
in C++ (maybe C++ is).

C seems to be a good, portable language for writing interpreters and
compilers.

But I wonder if someone has/has tried to write a programming language in
C++ and what were their experiences.
 
T

Tomasz Rola

C seems to be a good, portable language for writing interpreters and
compilers.

And one should not forget about performance. C++ was for a long time
behind C, and even now some parts (like iostreams) should be avoided in
fast code.

BTW, C++ can be IMHO a bit tricky in situations when one would like to
call back from JIT-generated code into parts written in C++... I mean
things like virtual functions, overloading, code generated from templates,
accessing private members etc. All those issues are non essential from the
point of interpreting or JIT, yet they stand in a way. While this could be
solved (with some headache, I suspect), C is far simpler and function
calls or manipulating structs are actually trivial...

Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature. **
** As the answer, master did "rm -rif" on the programmer's home **
** directory. And then the C programmer became enlightened... **
** **
** Tomasz Rola mailto:[email protected] **
 
M

Michael Torrie

In the beginning of C++ there were programs that just converted C++ to C
(frontends). At least that is how the C++ compiler Acorn sold worked.
So I don't think your argument was much true back then.

No, he is still right. Each C++ implementation did name mangling
differently leading to "C" libraries that had incompatible names and
signatures. Also each frontend could have generated incompatible
vtables and other C++ structures. So C code generated by one C++
frontend could not easily call C code generated by another C++ frontend.
So the same arguments that are made about C++ now were just as valid
back then when C++ was merely a fancy preprocessor.
 
T

Tim Wintle

Not every C programmer knows or wants to learn C++.

I think Terry is the only person that's mentioned this - but I'd like to
give extra support to it - I for one prefer C to C++ (as someone that
writes quite a lot of C extension modules).

And as Stephen mentioned - just because C is not an OO language, doesn't
mean you can't write OO code in it - you just have to pass an instance
of the class method is defined on in as the first parameter (like you do
in Python).


Tim
 
G

Grant Edwards

In your opinion what would Python gain from a C++ implementation?

Greater buzzword-compliance -- an important characteristic highly
prized by Human-Resources poeple and mid-level managers here in the
US.

;)
 
M

Mithrandir

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Disclaimer: I am neither a C nor C++ programmer. In fact I can barely
even program in Python ;-)

I would propose that in fact most programming languages are implemented
in C. Sun's (Oracle's) Java compiler and runtime are written in ANSI C.
The core of the Gnu Compiler Collection (which includes C++ and
Objective-C compilers) is written in C. The official Ruby is
implemented in C. The Squeak Smalltalk implementation uses C instead of
C++. I can't even think of a programming language that is implemented
in C++ (maybe C++ is).

C seems to be a good, portable language for writing interpreters and
compilers.

But I wonder if someone has/has tried to write a programming language in
C++ and what were their experiences.

(Sorry if this is a double post, but apparently my last one didn't go
through.)

I know that LOLCode has a .NET implementation (1), although it's "very
much alpha." And someone was apparently working on a C++ only
implementation of LOLCode (2), although that was 3 years ago.

LOLCode itself is very much alpha anyway and development seems to be
very slow (or dead.)

Python has a way of extending it's modules with C or C++ (3).

1: http://lolcode.com/implementations/lolcode.net
2: http://forum.lolcode.com/viewtopic.php?id=14
3: http://docs.python.org/release/2.5.2/ext/intro.html

- --
People should read more.
https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain
"All that is gold does not glitter,
not all those who wander are lost;
the old that is strong does not wither,
deep roots are not reached by the frost.
- From the ashes a fire shall be woken,
a light from the shadows shall spring;
renewed shall be blade that was broken,
the crownless again shall be king."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJMVyNqAAoJEKo37V1xH7gTeOUH/2/KYc4busZbATSB09ZUgW+v
BmydxDTZaPQd0B56JWSeUiz0/kZrufdDrVc3XUTNNF2oa8ExW51IgsaZOxn2UJGv
ydplycT1axs5hrzDG72v2Oo7/poPDxSsvpF58dBsb0XSI25I+orHKrTQpwvKz9cf
x6nzahUoygTbaVqZUyxCW2Tc7Rv4T2gpskssD8sIYqaRNofNnPbf3h3NA+q4LMkR
+F2UF3r1RE1jwJhs6RNAvUJBdLrHkA3isRsjQE38l6AioLdeTs2yrRtc+6xUkAig
RxR11qLZl5OOer/Jrmg1My0+ZTYGnIcAfChxPh1YnHuYbp+H7doqLjlKIkoXZms=
=F9Ou
-----END PGP SIGNATURE-----
 
M

Mark Lawrence

Python is an object oriented langage (OOL). The Python main
implementation is written in pure and "old" C90. Is it for historical
reasons?

C is not an OOL and C++ strongly is. I wonder if it wouldn't be more
suitable to implement an OOL with another one.

Has it ever been planned to rewrite in C++ the historical implementation
(of course in an object oriented design) ?

I can't understand why any serious programmer mentions C++. As soon as I
read it, I have to rush either to the kitchen to find a bowl to throw up
in, or head for the toilet so I can talk to the great white telephone.

Kindest regards.

Mark Lawrence.
 
P

Peter

On 02/08/2010 00:08, candide wrote:
I can't understand why any serious programmer mentions C++. As soon as I
read it, I have to rush either to the kitchen to find a bowl to throw up
in, or head for the toilet so I can talk to the great white telephone.

Kindest regards.

Mark Lawrence.

With you there Mark - IMO C++ is an abortion that should never have
seen the light of day. The idea of experimenting with creating an OO
language by extending C wasn't such a bad idea for a "play thing" (by
Stroustrop) but the fact that it somehow escaped from the Lab and
people picked it up and ran with it on a commercial basis is just
plain wrong!

Personally I liken it to one of those genetically engineered diseases
they play around with in biological warfare labs - and unfortunately
this one escaped! It has probably set the computing industry back
untold years in terms of advancement...

Unfortunately I am forced to use it in my day to day life, but at the
end of every day I go home and use a purgative to get it out of my
system. But there are many deluded youngsters out there who just don't
seem to know any better, but then the signs of the breakdown of
society surround us on a daily basis and I guess C++ is just another
signpost on the way...

Peter
 
M

Michael Torrie

I can't understand why any serious programmer mentions C++. As soon as I
read it, I have to rush either to the kitchen to find a bowl to throw up
in, or head for the toilet so I can talk to the great white telephone.

Sometimes, C++ is just the right tool for the job, despite all its
warts. For example, programming GTK apps with GTKmm in C++ is way more
pleasant than using C (but nowhere as pleasant as Python). C++'s object
semantics (guaranteed destruction, scoping, etc) can sometimes work very
well when you need the speed of a compiled language, but don't want to
be quite as low-level as C.

In this case, C++ is certainly not a better tool for the job than C.
But plenty of serious programmers know how to leverage C++ and do so
quite successfully. Just because C++ makes you ill in no way proves
that C++ is unfit for certain purposes.
 
S

sturlamolden

Has it ever been planned to rewrite in C++ the historical implementation
(of course in an object oriented design) ?

OO programming is possible in C. Just take a look at GNOME and GTK.

Perl is written in C++. That is not enough to make me want to use
it ;)

To be honest, C++ can be a great tool. But very few know how to use it
correctly. C++ textbooks are also written by people who don't
understand the language, and teach bad habits. The typical examples
revealing incompetence are use of new[] instead of std::vector, and
dynamic resourse allocation outside contructors.

C++ compilers used to be bloatware generators; C++ compilers of 2010
are not comparable to those of 1990. C++ is also a PITA for
portability. It is not sufficient for Python to only build with
Microsoft Visual Studio.
 
P

Paul Rubin

Michael Torrie said:
Sometimes, C++ is just the right tool for the job, despite all its
warts.... C++'s object semantics (guaranteed destruction, scoping,
etc) can sometimes work very well when you need the speed of a
compiled language, but don't want to be quite as low-level as C.

In this case, C++ is certainly not a better tool for the job than C.

The stuff C++ adds to C is a mix of good and bad, and it's reasonably
possible to use just the good stuff and ignore the bad. At that point
you've got a pure improvement over C, although a lot of C's shortcomings
can't be papered over and still remain.

Certain folks in the functional-programming community consider OO to be
a 1980's or 1990's approach that didn't work out, and that what it was
really trying to supply was polymorphism. C++ programs these days
apparently tend to use template-based generics rather than objects and
inheritance for that purpose.

I've never programmed in Ada but I'm intrigued by these articles:

http://adahome.com/Ammo/cpp2ada.html
http://www.adaic.org/whyada/ada-vs-c/cada_art.html

I have the impression that Ada has an undeservedly bad rap because of
its early implementations and its origins in military bureaucracy. I'd
certainly consider it as an alternative to C or C++ if I had to write a
big program in a traditional procedural language.
 
S

sturlamolden

And one should not forget about performance. C++ was for a long time
behind C, and even now some parts (like iostreams) should be avoided in
fast code.

For fast I/O one must use platform specific APIs, such as Windows' i/o
completion ports and memory mapping.

iostreams in C++ and stdio in C are ok for less demanding tasks.
 
S

sturlamolden

Certain folks in the functional-programming community consider OO to be
a 1980's or 1990's approach that didn't work out, and that what it was
really trying to supply was polymorphism.  C++ programs these days
apparently tend to use template-based generics rather than objects and
inheritance for that purpose.  

It avoids virtual function calls at the expense of unreable code and
errors that are nearly impossible to trace. It seems many thinks this
is a good idea because Microsoft did this with ATL and WTL. There are
also those who thinks template metaprogramming is a good idea. But who
uses a C++ compiler to dumb to unroll a for loop? In my experience,
trying to outsmart a modern compiler is almost always a bad idea.
I have the impression that Ada has an undeservedly bad rap because of
its early implementations and its origins in military bureaucracy.  

It is annyingly verbose, reminds me of Pascal (I hate the looks of
it), and is rumoured to produce slow bloatware. And don't forget
Ariane 5 ;)

I'd
certainly consider it as an alternative to C or C++ if I had to write a
big program in a traditional procedural language.

I still prefer Fortran 95 :)
 

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
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top