Python or C++ for ChemE Major: Which is Most Useful?

  • Context: C/C++ 
  • Thread starter Thread starter Null_
  • Start date Start date
  • Tags Tags
    C++ Python
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
20 replies · 34K views
Null_
Messages
227
Reaction score
0
I'm a chemE major, entering my sophomore year. I have used python in physics classes, but that was minimal experience.

I want to begin learning a language this summer; I have no other prior experience. My main interest is cryptography, but I don't think this will amount to anything other than a hobby. I'm not interested in games or apps.

I am thinking of learning Python because I have experience with it and because it's a simple language. However, many of my comp sci friends bash on it and tell me to learn C or C++.

Which language would be the most useful? I want to be able to use it to accomplish something (maybe in a future job), but I am not going to be a computer programmer.
 
Physics news on Phys.org
It won't be overwhelming? I dabbled with it for a few hours about a month ago and don't even remember now how to print "hello world." I'll probably try to spend an hour a day working with whatever language I choose.
 
Both are great languages. I started with Python, but C++ will have you at a lower level. It's probably harder to move from Python to C++.

At my uni. most engineering students have to learn C++.

I'd give the C++ tutorial on this site a shot.

Once you learn how to programming, learning a new language is essentially a matter of learning syntax. The choice of language depends on the task at hand.
 
Okay, thanks. I'll give C++ a go for a month and see how far I get.

I find what you say about learning syntax to be inspirational. I suppose it would be better to just jump in the deep end and learn how to swim with C++ than wear those little floaties in the kiddie pool with Python. :)
 
I wouldn’t consign Python to the kiddie end of the pool. Python is a great language, and I use it daily. It's extremely powerful and great for rapid development.

Python and C++ are different beasts. C++ is compiled, Python is interpreted. They are both versatile. C++ is good for when you need to operate at a lower level, but it can be a kludge. Python and plain C are elegant, but if code execution is a factor Python may be too slow, and C requires time spent of memory management and the like.

Whitespace is significant in Python, which puts a lot of programmers off, but it's really not a big issue as you should be indenting your code anyway. Both C++ and Python come with large libraries.
 
Interesting. Thanks for the insight. I hear many jokes about "import [...]" with Python which is why I made the statement. However, I think I'll stick with the original recommendation and learn C++ first, then Python later if I find the need for it.
 
Given the opening poster's motives, I have great difficulty imagining how C++ would have any benefit over Python.


Even for general programming, python is a strong language. As a person who writes high performance code, I would even write most of a finished product in python if it worked on all of my target platforms. Writing an entire program in C++ is premature optimization.
 
Now I'm just confused. I suppose I'll wait just a little longer until I decide. The MIT OCW looks nice as I would have a guide to follow. Hmmm..decisions, decisions...
 
I just started programming a couple months ago and dabbled with C++ and Python. I really don't see how anyone can learn C++ as a first language. Python is going much faster in my learning experience, mainly because I don't have to worry about syntax as much.

I plan on only focusing on Python until I feel proficient enough to explore other languages. With that said, is there any program that converts or translates Python code into C++?
 
DrummingAtom said:
I just started programming a couple months ago and dabbled with C++ and Python. I really don't see how anyone can learn C++ as a first language. Python is going much faster in my learning experience, mainly because I don't have to worry about syntax as much.

I plan on only focusing on Python until I feel proficient enough to explore other languages. With that said, is there any program that converts or translates Python code into C++?
There is Cython.

I haven't used it -- I'm more familiar with the paradigm of rewriting parts of your python program in C/C++ in a fashion that can be invoked from python, e.g. using the ctypes module. But that's mainly because it's the method I'm familiar with, so I can't offer an evaluation of the alternatives.
 
Okay, I'm giving python a go.

I've run into a slight annoyance (error on my part probably):

Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> a,b=0,1
>>> while b<100:
a,b=b,b+a
print (b)


1
2
3
5
8
13
21
34
55
89
144
>>>

As you can see, my small program does print; however, when I try to run the program (after saving), I get an invalid syntax error popup message, and the 2 in Python 3.2 is highlighted in a peachy red color. What is the cause of this?
 
Null_ said:
Okay, I'm giving python a go.

I've run into a slight annoyance (error on my part probably):



As you can see, my small program does print; however, when I try to run the program (after saving), I get an invalid syntax error popup message, and the 2 in Python 3.2 is highlighted in a peachy red color. What is the cause of this?

Does it look something like this in the file?
Code:
a,b=0,1
while b<100:
    a,b=b,b+a
    print b
 
Cython is an option; I'm only vaguely familiar with it, but the Python wrapper for libfreenect uses it.

Null_, can you post the exact code you try to save and get the syntax error on?
 
I did indent as you did, but I found the problem.
In physics class, we had been using VIDLE with VPython, so I was expecting IDLE to work the same way. I just downloaded VIDLE and it works fine now. Is there any disadvantage to vidle? I really like being able to click and edit the code.
 
Vidle is less common, so I'd recommend writing code that works under the standard Python interreter if you want to share code. For personal use, whatever floats your boat.

I personally write my code in gedit and run it from python in bash.
 
You should definitely learn python first. The important part of programming is to learn algorithms and paradigms. The only major thing you'll learn from C++ development that you won't learn from python is RAII and pointers. You do not need the raw performance of C++ for what you are learning, and you will proceed quicker and learn faster with python.
 
Honestly, it would be to your advantage to learn both. Python is such a functional language and c++ is used all over the place. The cool thing is that you can use them both together.