Python or C++?

For system help, all hardware / software topics NOTE: use Coders Corner for all coders topics.

Moderators: Krom, Grendel

Post Reply

Which is a better language to learn?

C++
1
25%
Python
3
75%
 
Total votes: 4
User avatar
Isaac
DBB Artist
DBB Artist
Posts: 7737
Joined: Mon Aug 01, 2005 8:47 am
Location: 🍕

Python or C++?

Post by Isaac »

For someone who's pretty new to computer programming, what would you recommend they learn? Not that you shouldn't learn the other, but someone who knows Python might not need C++ or visa-versa.

I asked a few reliable sources already.
My friend,(edit:fixed) who graduated from UT with Honors with a Bachelors of Science in Computer Science, and is working on Andorid apps and participated in the recent Netflix competition, wrote this :
Out of the two...
Python is easiest to learn.
Which, I can say, is true. Five minutes in and I was already writing small 3 line scripts that worked.
Lots of experienced programmers prefer to use Python over C++ for certain projects.
I'm not sure about this. My friend above only worked with those who knew it; he doesen't know the language himself. Lo, from ODF-online.org, does know Python and worte:
I personally, do not like python. The advantages seem to be that you can do many things much faster than with e.g. C++, you can debug it easier etc... However, pythons runtime is a mess. Also, I think C++ has far more librarys (3D engines, physics engines, netcode libraries, whatever other libraries) to use than python. You might find a workaround to access them via a C++ workaround, but why not using C++ for the whole project than?
My conclusion is, that if you just want to have a bit of fun ;) - use Python. But for everything more, I suggest only C or C++. (My 2 Cents :D
However, my UT friend did show some jelousy of Python users.
You can do serious work with Python, it's not just for fun. Often times, it's better to use Python because it'll take you 20 minutes to do something that will take you 2 hours with C++.
So far, I've been reading the Python documents tutorial introduction section to better understand Python and its uses. It opens with...
If you do much work on computers, eventually you find that there’s some task you’d like to automate.
...
Or maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application.
...
You could write a Unix shell script or Windows batch files for some of these tasks, but shell scripts are best at moving around files and changing text data, not well-suited for GUI applications or games. You could write a C/C++/Java program, but it can take a lot of development time to get even a first-draft program. Python is simpler to use, available on Windows, Mac OS X, and Unix operating systems, and will help you get the job done more quickly.
Thank you.
User avatar
Foil
DBB Material Defender
DBB Material Defender
Posts: 4900
Joined: Tue Nov 23, 2004 3:31 pm
Location: Denver, Colorado, USA
Contact:

Post by Foil »

I think you've answered your own question - it depends on what you want to do.

Small job, need quick solutions, easy interface, moderate performance... go Python.

Large job, need detailed control, high-performance... go C++.

Don't limit yourself to one or the other - use what works best for the project.

-------

P.S. Although I wouldn't recommend it for learning to code, I personally enjoy working in C++ (my job involves mostly Visual C++ for a monstrous CAD application). It's a powerful language, and allows for some really fine control over exactly what the application does.
User avatar
Krom
DBB Database Master
DBB Database Master
Posts: 16138
Joined: Sun Nov 29, 1998 3:01 am
Location: Camping the energy center. BTW, did you know you can have up to 100 characters in this location box?
Contact:

Post by Krom »

What language is better to learn is entirely dependent on what you want to do with it. Not all languages are equal so there are tasks that are better done with one than with another.
User avatar
BUBBALOU
DBB Benefactor
DBB Benefactor
Posts: 4198
Joined: Tue Aug 24, 1999 2:01 am
Location: Dallas Texas USA
Contact:

Post by BUBBALOU »

Actually if you're into 3D animation, shaders and output pipelines then you should know both. Python for the Modeling and export/import features (where you need simple & precise scripts) to achive your results. Then C++ to import and convey the desired results with added weight and in some instances on the fly results with additional variables in your finsished project(especially gaming)

When someone mentions python Blender, 3dsm, Maya and trueSpace instantly comes to mind.

I seem to have a better workout dodging your stupidity than attempting to grasp the weight of your intelligence.
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6539
Joined: Sun Sep 05, 1999 2:01 am
Location: ❄️❄️❄️

Post by Jeff250 »

At the risk of being controversial, I think that C++ is almost always the wrong choice. I'd recommend learning Python, then C, in that order. Python has a great C API, so there's a lot of overlap. Both Python and C are beautiful, elegant languages that will be around for a very long time. Conversely, C++ is an ugly language that adds more warts and pitfalls to C than actual expressive power and is waning in popularity. If you're going to add the overhead, then you might as well use a programming language like Python with all the modern bells and whistles, like garbage collection, first-class functions, closures, dictionaries, and list comprehensions. In fact, describing these as \"bells and whistles\" is a grave understatement.

Since most applications are IO-bound, using C++ is usually a premature optimization, and even that's being generous. I'd recommend using Python, and then, if you've actually *profiled* your application and you've empirically determined that your Python bit twiddling code running in a tight loop somewhere is consuming too much processor time, then consider factoring that code into a C function or small library. I honestly can't think of anyone who would start a new project in C++.

Also, if it's personally relevant, Python will put you much more quickly onto the path of becoming a hacker.

Here is some literature relevant to your question:
Great Hackers
I Did It All For You
User avatar
Sirius
DBB Master
DBB Master
Posts: 5616
Joined: Fri May 28, 1999 2:01 am
Location: Bellevue, WA
Contact:

Post by Sirius »

C++ adds additional features to C to allow it to do somewhat more modern things. It's the best, and the worst, of both worlds. Best because you get a lot of stuff to improve productivity without substantially increasing overhead, and you don't pay for what you don't use; worst because that results in an unusually difficult to learn/understand/use effectively language.

But there are some times when you have to use it. I've been working with COM/ActiveX recently, and I would very much hate to do that in raw C (i.e. without ATL or a decent object-oriented windowing framework). Wouldn't surprise me if C++ does lose most of what importance it still has though; the only thing it is really well-suited to is games. Most applications are better suited to managed languages now, and many performance-oriented ones, e.g. OS kernels, are often written in pure C.

To really use C++ to its fullest potential, it seems you need an experienced programmer who wants to develop applications relatively quickly while sacrificing only a bare minimum of performance. If any of those conditions aren't met, you're better off looking elsewhere...
User avatar
Thenior
DBB Captain
DBB Captain
Posts: 667
Joined: Wed Oct 06, 2004 9:40 am

Post by Thenior »

Question:

I'm no coder, so my opinion may or may not be worth anything, but isn't C# a pretty good option? I know alot of it is .NET dependant, but with the Mono project, I thought alot of that is supposed to be gone.

And although Python seems like a quick and easy script language, it's not really something you would want to code a OS or a 3D physics engine out of, right?
User avatar
Sirius
DBB Master
DBB Master
Posts: 5616
Joined: Fri May 28, 1999 2:01 am
Location: Bellevue, WA
Contact:

Post by Sirius »

Yeah, I'm a pretty big fan of C#. You can use it for many, many things (small applications, large applications, websites, rich internet applications, even games with the XNA thing), and its syntax is quite flexible but also much easier to get to work than C++. Cross-platform support isn't perfect yet, and it's not going to be completely native speed (though like Java, it's getting pretty close, theoretically), but other than that.

Actually, there is one area it isn't such a good choice; scripts, e.g. for admin stuff, importers/exporters, etc. Incidentally, that's the field Python is probably best suited to (Perl is another popular language for that domain).

Like you say though, I would not ever develop a physics engine in Python (too slow), never mind an operating system (not only too slow, but can't run in isolation because it's interpreted, and is probably not going to be able to support the sorts of low-level operations you'd need to make a decent kernel or driver stack).

Actually, I wouldn't use C# for an operating system either (at least not the core of it). It needs to run quickly and close to the hardware, so that limits you to C/C++ and assembly.
User avatar
Thenior
DBB Captain
DBB Captain
Posts: 667
Joined: Wed Oct 06, 2004 9:40 am

Post by Thenior »

I used a 3D engine a while back that instead of using something like Perl or LUA, it did on-the-fly C# scripting. What a performance nightmare.

Sorry to hijack the thread.
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6539
Joined: Sun Sep 05, 1999 2:01 am
Location: ❄️❄️❄️

Post by Jeff250 »

Yeah, I'd say a game engine is a place where C++ is still relevant, but game engine development is a small niche, and I think you'd be crazy to not use a scripting language for implementing the higher-level game rules. Most OS kernels are written in C and assembly.

I think that Java is slowly becoming the new Cobol. I'm not sure what to think about C#. I've never written it, but Microsoft seems to have jerry rigged some higher level concepts like closures into its otherwise Java-lifted syntax, which may or may not have been a good thing (see my feelings about C++). C# seems to be cross-platform in the same sense that most languages, like C and Python, are cross-platform. The core functionality is cross-platform, but if you want to use GUI's, sound, etc., then you have to use external libraries that may or may not be cross platform. For instance, for GUI's, Windows C# applications tend to end up using WinForms, Linux C# applications tend to end up using GTK, and so on. This is par for the course though compared to most languages, but as a language like C# that tries to imitate Java, this is a significant shortcoming, as Java actually provides cross-platform GUI and sound libraries.
Post Reply