From what I have seen you can generall get a better performance or speed (runtime wise) out of C++ for pretty much everything, that doesn't mean its better though. But then you could probably get an even better increase if you programmed everything in assembly, but it wouldn't be worth the time or the effort. There's a trade off usually between developing and maintaining and run speed of the final product.daveman wrote:I know that gentoo is written mainly in python, but I just had a little Question. Me and my friend shuai had a little debate over the two languages. It started out with him claiming that fedora is better than gentoo for several reasons, of which I disagreed with. One of the resons was that he said that C++ is way faster than python. And I said that python was was faster cuz even though technicly C++ is faster, when you consider that python is a much lighter language, you might reconsider. So my question to you is, which one is actually faster? Who's right?

Huh? Portage is (mainly) written in python, but then again, so is yum.I know that gentoo is written mainly in python
Neither of you, but mostly your friend.Who's right?

Probably you should try it outdmitchell wrote:I hear this all the time, but I've never seen any evidence. Do you have any?hegga wrote:python allows one to write software more rapid
For what it's worth, C++ is more than satisfactory for my needs.


And you could read the rest here http://www.mindview.net/WebLog/log-0025.Strong testing, not strong typing.
So this, I assert, is an aspect of why Python works. C++ tests happen at compile time (with a few minor special cases). Some Java tests happen at compile time (syntax checking), and some happen at run time (array-bounds checking, for example). Most Python tests happen at runtime rather than at compile time, but they do happen, and that's the important thing (not when). And because I can get a Python program up and running in far less time than it takes you to write the equivalent C++/Java/C# program, I can start running the real tests sooner: unit tests, tests of my hypothesis, tests of alternate approaches, etc. And if a Python program has adequate unit tests, it can be as robust as a C++, Java or C# program with adequate unit tests (although the tests in Python will be faster to write).


Code: Select all
In [1]:5+"5"
---------------------------------------------------------------------------
exceptions.TypeError Traceback (most recent call last)
/root/portage_scripts/<ipython console>
TypeError: unsupported operand type(s) for +: 'int' and 'str'

killomatic wrote:Python is weakly typed in the interaction it allows between different datatypes without casts. It's to guess how certain things might behave, i.e. "5"+5, which would throw an error in C.
Code: Select all
ha@aragorn ~$ perl -e 'print "5"+5'
10
ha@aragorn ~$ python
Python 2.4.2 (#1, Mar 30 2006, 01:43:20)
[GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "5"+5
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: cannot concatenate 'str' and 'int' objects


Err...if you're doing x = '5' + 5; then that is using the ascii value of 5 + the value 5. If you're doing x = "5" + 5; that is using the address of the static string where 5 is held + the value 5 (Note the compiler will protest that you are making an integer from a pointer without a cast).Gergan Penkov wrote:Not always it depends how it is declared if it is a char (static typing) it will be "0" if it is char* it will be some garbage (this results in end effect to weak typing) - in fact c is static, weakly typed language as c++ (although c++ has more type checking it is still weakly typed languge).
python is dynamic, strongly typed language.
And I don't have a clue now if it is simply x = '5'+5 (I haven't program in c/c++ for some time), you are probably right there.
Code: Select all
#include <stdio.h>
int main(int argc, char **argv)
{
int x = '5' + 5;
int y = "5" + 5;
printf ("%d %d\n",x,y);
}
Code: Select all
58 134513817
You are absolutly correct, as I said I haven't programmed in c/c++ for quite a long time - '5' is a char and "5" is a null terminated string. Sorry for the noisekmj0377 wrote:Err...if you're doing x = '5' + 5; then that is using the ascii value of 5 + the value 5. If you're doing x = "5" + 5; that is using the address of the static string where 5 is held + the value 5 (Note the compiler will protest that you are making an integer from a pointer without a cast).Gergan Penkov wrote:Not always it depends how it is declared if it is a char (static typing) it will be "0" if it is char* it will be some garbage (this results in end effect to weak typing) - in fact c is static, weakly typed language as c++ (although c++ has more type checking it is still weakly typed languge).
python is dynamic, strongly typed language.
And I don't have a clue now if it is simply x = '5'+5 (I haven't program in c/c++ for some time), you are probably right there.
Results in (with the second value depending on the address of the string):Code: Select all
#include <stdio.h> int main(int argc, char **argv) { int x = '5' + 5; int y = "5" + 5; printf ("%d %d\n",x,y); }So I don't know where you're getting "0" from.Code: Select all
58 134513817

And today it doesn't matter much, unless you plan to program for embedded systems. So go for Python/Perl/Ruby/Scheme. You can write your applications faster using a high level language (I am not sure about writing code faster in Scheme/Lisp but this would propably start a flame war :running for cover behind some sand bags...teknomage1 wrote:Remember, the argument for higher level languages is always development speed over application speed. That is to say, in general, given a fixed number of developers, they will complete a project in a high level language like python faster than in a lower level language like C (C++ sort of splits the difference if you count STL, I feel) with the same number of features. But the python program would run somewhat slower than the C one.
You don't know very well what "strong typing" and "weak typing" means. Strong typing and weak typing is different from statically typed and dynamically typed. Python is a strongly typed language and a dynamically typed language. It's not becaues a language does not use type declarations that it's weakly typed.killomatic wrote:Python is weakly typed in the interaction it allows between different datatypes without casts. It's to guess how certain things might behave, i.e. "5"+5, which would throw an error in C. Given, an experienced python programmer will learn how these sorts of things behave, but the syntax itself is ambiguous, so the behavior doesn't directly follow from it. The problem isn't errors, or runtime vs compile time checks, it's unpredictable behavior when it comes to the interaction between different data types.
Well... the "somewhat slower" depends on what you are using it for. But for the appropriate use cases, it indeed doesn't matter whether you use Python/Perl/Ruby or C. In the appropriate use cases, the application will simply be developer a lot faster in one of the scripting languages than in C, it will have less code to maintain and probably also less bugs. Also note that a lot of the applications built on Python/Perl/Ruby rely on C libraries in the back to do the heavy lifting stuff. Besides that, I believe Scheme/Lisp implementations to be a lot faster than Python/Perl/Ruby implementations. I believe that with time, more work will be done on those implementations to make them faster. After all, Python/Ruby are quite young, compared to Lisp and Smalltalk, which have fast implementations. I don't know about Python, but a virtual machine for Ruby: YARV (Yet Another Ruby VM) is in the works and already shows improved performance for certain code patterns.rukh wrote:And today it doesn't matter much, unless you plan to program for embedded systems. So go for Python/Perl/Ruby/Scheme. You can write your applications faster using a high level language (I am not sure about writing code faster in Scheme/Lisp but this would propably start a flame war :running for cover behind some sand bags...teknomage1 wrote:But the python program would run somewhat slower than the C one.).