Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

C++ or Python: You Pick!

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
30 posts
  • 1
  • 2
  • Next
Author
Message
daveman
n00b
n00b
User avatar
Posts: 6
Joined: Wed Mar 08, 2006 1:02 am

C++ or Python: You Pick!

  • Quote

Post by daveman » Wed Apr 12, 2006 4:52 pm

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?
There's no place like 127.0.0.1
Top
Zepp
Veteran
Veteran
User avatar
Posts: 1246
Joined: Mon Mar 15, 2004 9:43 pm
Location: Ontario, Canada

Re: C++ or Python: You Pick!

  • Quote

Post by Zepp » Wed Apr 12, 2006 5:00 pm

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?
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.
Top
xglad
n00b
n00b
User avatar
Posts: 53
Joined: Tue Aug 13, 2002 10:25 pm
Location: Ft. Lauderdale, FL, USA.

  • Quote

Post by xglad » Wed Apr 12, 2006 5:23 pm

You're both right. All things being equal, C++ runs faster. And Gentoo is better. :)
Top
incabolocabus
Apprentice
Apprentice
User avatar
Posts: 232
Joined: Mon Nov 24, 2003 10:09 pm
Location: Fort Collins, CO

  • Quote

Post by incabolocabus » Wed Apr 12, 2006 6:51 pm

I know that gentoo is written mainly in python
Huh? Portage is (mainly) written in python, but then again, so is yum.
Who's right?
Neither of you, but mostly your friend.
Regarding fedora vs. gentoo - like anything, one must weigh the pros and cons based upon ones needs.
Regarding C++ vs. python - C++ faster, but see above.
1970s Sears Hawthorne, green, 3 gears, front and rear fenders, rear dual basket rack, overclocked to 1.3 hz.
Top
Tyir
Apprentice
Apprentice
User avatar
Posts: 172
Joined: Mon Mar 08, 2004 5:45 am
Location: Montreal

  • Quote

Post by Tyir » Thu Apr 13, 2006 12:30 am

Different tools. C++ is good at some things, python is good at other things. And tools like portage and yum aren't exactly CPU intensive tasks, they tend to be much more disk-intensive.

And as the above posters mentioned, gentoo is not portage, both gentoo and fedora are very similar in language amounts.
There are two things I have learnt in life:
1. Don't reveal everything you know.
Top
Frodg
l33t
l33t
User avatar
Posts: 761
Joined: Wed Feb 11, 2004 11:44 pm

  • Quote

Post by Frodg » Thu Apr 13, 2006 1:06 am

Either way, are you going to notice the difference at the normal resource levels used in either Fedora or Gentoo? With a relatively fast machine, differences will more likely be noticeable due to configurations....
(IMHO)
Aerosolo ergo sum - I spray therefore I am

Gentoo - Registered Linux User # 361400
Top
hegga
Apprentice
Apprentice
Posts: 210
Joined: Wed Jun 04, 2003 10:30 am
Location: Norway
Contact:
Contact hegga
Website

  • Quote

Post by hegga » Thu Apr 13, 2006 11:33 am

python allows one to write software more rapid, for me this is more important
than the speed difference between the software. i would not exchange portage
for anything.
hegga
Top
dmitchell
Veteran
Veteran
User avatar
Posts: 1159
Joined: Sat May 17, 2003 4:51 pm
Location: Austin, Texas

  • Quote

Post by dmitchell » Thu Apr 13, 2006 7:49 pm

hegga wrote:python allows one to write software more rapid
I hear this all the time, but I've never seen any evidence. Do you have any?

For what it's worth, C++ is more than satisfactory for my needs.
Your argument is invalid.
Top
Gergan Penkov
Veteran
Veteran
User avatar
Posts: 1464
Joined: Sat Jul 17, 2004 9:42 pm
Location: das kleinste Kuhdorf Deutschlands :)

  • Quote

Post by Gergan Penkov » Thu Apr 13, 2006 8:06 pm

dmitchell wrote:
hegga wrote:python allows one to write software more rapid
I hear this all the time, but I've never seen any evidence. Do you have any?

For what it's worth, C++ is more than satisfactory for my needs.
Probably you should try it out :)
"I knew when an angel whispered into my ear,
You gotta get him away, yeah
Hey little bitch!
Be glad you finally walked away or you may have not lived another day."
Godsmack
Top
killomatic
n00b
n00b
Posts: 38
Joined: Fri Mar 17, 2006 8:15 pm

  • Quote

Post by killomatic » Thu Apr 13, 2006 8:18 pm

Perl is alot faster to code in than either Python or C++.

Python is more weakly typed than C++, which makes it more unpredictable and bug prone. A skilled C or C++ programmer will have no issue with memory leaks, and will write more stable code in C than python, but given two less skilled programmers, the one writing in python will likely write better code than the one writing in C++.

It has a one way to do any particular thing philosophy, which is great for readability, but you'd better hope that the "one way" is the way that best suits your solution, or coding in python might even take longer than C/C++.

The only advantage python has over other languages is readability and forced constency, so it's well suited to scripts that are part of a group project, where you don't trust your peers to write clean code without being forced to, or be good about memory management.
Top
Gergan Penkov
Veteran
Veteran
User avatar
Posts: 1464
Joined: Sat Jul 17, 2004 9:42 pm
Location: das kleinste Kuhdorf Deutschlands :)

  • Quote

Post by Gergan Penkov » Thu Apr 13, 2006 8:30 pm

what does this mean that python is weakly typed as c++?
python is strong typed, c++ is more a static typed.
I don't want to start a flame war but perl is really sth, which should be avoided :twisted:
I'll allow myself to cite Bruce Eckel here:
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).
And you could read the rest here http://www.mindview.net/WebLog/log-0025.
If you have read Thinking in C++ and Thinking in Java you'll understand that he is not some random guy commenting bullshit.
"I knew when an angel whispered into my ear,
You gotta get him away, yeah
Hey little bitch!
Be glad you finally walked away or you may have not lived another day."
Godsmack
Top
killomatic
n00b
n00b
Posts: 38
Joined: Fri Mar 17, 2006 8:15 pm

  • Quote

Post by killomatic » Thu Apr 13, 2006 10:30 pm

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.

I dunno what sth means, but perl is very useful for a programmer who wants to keep his job. It's a very fast language to write in, and if you're fond of clever one-liners, your code will be completely unreadable, making you impossible to fire :wink:
Top
Gergan Penkov
Veteran
Veteran
User avatar
Posts: 1464
Joined: Sat Jul 17, 2004 9:42 pm
Location: das kleinste Kuhdorf Deutschlands :)

  • Quote

Post by Gergan Penkov » Thu Apr 13, 2006 10:32 pm

In fact you should try what you are talking about this might be true for perl but not for python:

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'
"I knew when an angel whispered into my ear,
You gotta get him away, yeah
Hey little bitch!
Be glad you finally walked away or you may have not lived another day."
Godsmack
Top
Gergan Penkov
Veteran
Veteran
User avatar
Posts: 1464
Joined: Sat Jul 17, 2004 9:42 pm
Location: das kleinste Kuhdorf Deutschlands :)

  • Quote

Post by Gergan Penkov » Thu Apr 13, 2006 10:42 pm

And in fact this will not throw anything in c it will give you "0" probably :D
"I knew when an angel whispered into my ear,
You gotta get him away, yeah
Hey little bitch!
Be glad you finally walked away or you may have not lived another day."
Godsmack
Top
hegga
Apprentice
Apprentice
Posts: 210
Joined: Wed Jun 04, 2003 10:30 am
Location: Norway
Contact:
Contact hegga
Website

  • Quote

Post by hegga » Thu Apr 13, 2006 10:50 pm

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
in python i would be able to catch this as an exception, somthing (correct me if i'm wrong) perl don't have.
The fact that python is the third most used programming language at Google speaks for itself, and is it Guido van Rossum or
Larry Wall that has been hired by Google?

I'm not trying to start an argue, but i feel that you are talking negative about python without having ever tried it.
we can agree upon that Gentoo is the best distro out there... :)
hegga
Top
killomatic
n00b
n00b
Posts: 38
Joined: Fri Mar 17, 2006 8:15 pm

  • Quote

Post by killomatic » Thu Apr 13, 2006 11:13 pm

Oh hey I was wrong :oops: , could have sword that kinda stuff worked in python. My experience with python is limited to modifying other people's python code, so I guess I really don't know enough to criticize it. If anything I've tried to avoid it despite working with numerous people who use it almost exclusively... I'm not sure why I hate the look of it so much.

And yup, agreed about gentoo.
Top
kmj0377
Guru
Guru
User avatar
Posts: 397
Joined: Fri Sep 26, 2003 6:53 am

  • Quote

Post by kmj0377 » Thu Apr 13, 2006 11:16 pm

Gergan Penkov wrote:And in fact this will not throw anything in c it will give you "0" probably :D
C will treat the string as a pointer and do pointer arithmetic. C++ won't compile it with the error "error: invalid conversion from ‘const char*’ to ‘int’"
Top
Gergan Penkov
Veteran
Veteran
User avatar
Posts: 1464
Joined: Sat Jul 17, 2004 9:42 pm
Location: das kleinste Kuhdorf Deutschlands :)

  • Quote

Post by Gergan Penkov » Fri Apr 14, 2006 12:09 am

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.
"I knew when an angel whispered into my ear,
You gotta get him away, yeah
Hey little bitch!
Be glad you finally walked away or you may have not lived another day."
Godsmack
Top
kmj0377
Guru
Guru
User avatar
Posts: 397
Joined: Fri Sep 26, 2003 6:53 am

  • Quote

Post by kmj0377 » Fri Apr 14, 2006 1:41 am

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

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);
}
Results in (with the second value depending on the address of the string):

Code: Select all

58 134513817
So I don't know where you're getting "0" from.
Top
nmcsween
Guru
Guru
User avatar
Posts: 381
Joined: Wed Nov 12, 2003 11:13 pm

  • Quote

Post by nmcsween » Fri Apr 14, 2006 7:37 am

I choose Ada
Great Resources
  • Fluid Portage
Top
Gergan Penkov
Veteran
Veteran
User avatar
Posts: 1464
Joined: Sat Jul 17, 2004 9:42 pm
Location: das kleinste Kuhdorf Deutschlands :)

  • Quote

Post by Gergan Penkov » Fri Apr 14, 2006 9:08 am

kmj0377 wrote:
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.
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).

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);
}
Results in (with the second value depending on the address of the string):

Code: Select all

58 134513817
So I don't know where you're getting "0" from.
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 noise :)
"I knew when an angel whispered into my ear,
You gotta get him away, yeah
Hey little bitch!
Be glad you finally walked away or you may have not lived another day."
Godsmack
Top
teknomage1
Veteran
Veteran
User avatar
Posts: 1239
Joined: Tue Aug 05, 2003 10:05 pm
Location: Los Angeles, CA

  • Quote

Post by teknomage1 » Fri Apr 14, 2006 10:05 am

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.
Top
rukh
Apprentice
Apprentice
User avatar
Posts: 177
Joined: Wed Aug 17, 2005 7:06 am
Location: Sol 3
Contact:
Contact rukh
Website

  • Quote

Post by rukh » Fri Apr 14, 2006 10:24 am

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.
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... :D ).
Prepare to meet your maker! -- Bereiten Sie vor sich, Ihren Hersteller zu treffen!

-- rukh.de, Noir (german)
Top
ruben
Guru
Guru
Posts: 462
Joined: Fri Jul 04, 2003 9:00 am

  • Quote

Post by ruben » Fri Apr 14, 2006 1:14 pm

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.
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.
See the bottom of this page, which describes it clearly.
People seem to be scared about not having type declarations, but in practice it works very well. And you can really program something a lot faster in for example Ruby (or Python) than in C++. It is true that sometimes in a dynamically typed language, you'll find a bug which would have been caught in a statically typed language, but personally i see a lot more advantages than disadvantages. In the context of Ruby, I see a lot of people push the use of unit tests as a way to catch bugs in your software. So, the aforementioned type of bugs, would likely have been caught in a unit test.
Top
ruben
Guru
Guru
Posts: 462
Joined: Fri Jul 04, 2003 9:00 am

  • Quote

Post by ruben » Fri Apr 14, 2006 1:29 pm

rukh wrote:
teknomage1 wrote:But the python program would run somewhat slower than the C one.
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... :D ).
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.
Oh.. and I do think Lisp is a nice and very powerful language... and when you think about how old that language is... and how a lot of the concepts used in that language seem to become popular again in languages like Python and Ruby, then you need to show Lisp some respect.
Top
Post Reply

30 posts
  • 1
  • 2
  • Next

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic