I am an aspiring physicist. Should I learn C++?

  • Physics
  • Thread starter AakashPandita
  • Start date
  • Tags
    Physicist
In summary, the conversation discusses the potential benefits of learning C++ for a physics student, in addition to other subjects such as biology, economics, and fine arts. It is suggested that learning C++ can be directly beneficial for a student's undergraduate studies and for potential research opportunities. However, there is also a discussion about the popularity of other languages, such as MATLAB and Python, in the field of physics. It is noted that while C++ may be important for legacy code, other languages may be more practical for certain tasks in physics research. Ultimately, it is recommended to have a well-rounded understanding of programming languages, with a potential focus on C++ for its parallelism capabilities.
  • #1
AakashPandita
157
0
Besides physics, chemistry and math I was interested in studying psychology but I wanted to know if C++ could be more helpful to a physicist. Also I have a range of other subjects from where I can choose...
Biology, Economics, biotech, history, Political Science, Web Designing, Physical Education, Fine Arts.
 
Physics news on Phys.org
  • #2
Learning c++, or some other programming language, is something that can be of direct benefit to your college physics career and later on in life in almost any technical career. Psychology is not going to help you directly in your physics career.

Those psychology classes might help you indirectly in the sense that it will force you to learn to write clearly and in the sense of becoming a more well-rounded individual. Note that the same applies to subjects such as economics, history, and political science. The latter applies to fine arts.
 
  • #3
What if I want to do research?
 
  • #4
It is probably worth learning as are most programming languages. A few of my friends who are physics majors with graduate degrees in the subject ended up going into programming fields.

The main reason being their is not that many jobs in physics unless your willing to relocate. I suggest you learn at least c++ and maybe even a few others as fallback career options.
 
  • #5
thank you all!
 
  • #6
I am wondering the same thing too. D H, could you give some examples of what c++ can directly benefit to a student's undergrad study or certain areas in REU?
 
  • #7
AakashPandita said:
Besides physics, chemistry and math I was interested in studying psychology but I wanted to know if C++ could be more helpful to a physicist. Also I have a range of other subjects from where I can choose...
Biology, Economics, biotech, history, Political Science, Web Designing, Physical Education, Fine Arts.

You should definitely learn to do some basic numerical programming in at least one language. You don't have to be amazing at it - just capable of writing useful, readable programs. It doesn't have to be C++. Python/NumPy/SciPy are popular at my physics department, and MATLAB is a big deal in my research group.

Friends and colleagues tell me: if you're OK with C++, programmers will often assume that you can learn other languages if you need to. From that point of view, C++ is a good thing to have on a resume/CV. But they also tell me that other languages are more practical for the kind of work physicists do. For example, the code in my thesis was easy to write in MATLAB, not too hard in Python, and I haven't finished the C++ version.

As an undergrad, I took plenty of courses not directly related to physics: art, music, philosophy, etc. (My university required a wide variety of subjects, even for my Mathematics degree.) Those classes were almost completely useless for physics research, but I don't regret taking them.
 
  • #8
absolutely, I use it every day.
 
  • #9
MATLAB and Python have much more momentum in physics. It's very uncommon nowadays that you're asked to write a C++ program in any kind of science, as far as I know. A main reason is that there is a greater emphasis on data visualization and statistical analysis, both of which it's perhaps an order of magnitude faster to develop with MATLAB toolboxes/Python modules as compared to learning a couple of C++ libraries. Physics research is like that, you often want to get something done, for a few uses (perhaps the length of a research project), then throw the code away... not necessarily a good practice but that's how it's done.

Now, the problems are that MATLAB is not really a language and Python is not well-suited for parallelism. If you start with either, you want to hedge against the future with a language that natively supports parallelism, such as Clojure, Scala or Erlang. I think your professors will love you if you know how to build an application with distributed processes.

If it's your first language, I would probably start with Python.

Eventually at some point, having a sound foundation in system architecture will widen your horizons and break some bottlenecks (e.g. learn cache thrashing or stack passing), I guess that's when it's most rewarding to look at a language such as C or C++.

Some argue for the opposite sequence that I've suggested, get over it, then go to learn something like Python. I guess it depends on the type of learning curve that you prefer.
 
  • #10
meanrev said:
MATLAB and Python have much more momentum in physics. It's very uncommon nowadays that you're asked to write a C++ program in any kind of science, as far as I know. A main reason is that there is a greater emphasis on data visualization and statistical analysis, both of which it's perhaps an order of magnitude faster to develop with MATLAB toolboxes/Python modules as compared to learning a couple of C++ libraries. Physics research is like that, you often want to get something done, for a few uses (perhaps the length of a research project), then throw the code away... not necessarily a good practice but that's how it's done.

I don't know about that... the physicists I work with constantly use the ROOT libraries for their data analysis, and they are written in C++. What physicists are using MATLAB these days? I grant you Python is gaining a lot of traction but there is a hell of a lot of C++ legacy code out there that as a grad student you will have to deal with.
 
  • #11
carlgrace said:
I don't know about that... the physicists I work with constantly use the ROOT libraries for their data analysis, and they are written in C++. What physicists are using MATLAB these days? I grant you Python is gaining a lot of traction but there is a hell of a lot of C++ legacy code out there that as a grad student you will have to deal with.

I can wager with you that physicists who use ROOT are more the exception than the norm. And judging from the threadstarter's description, I'm pretty sure he wouldn't be touching it any time soon.

If you want to argue along these lines, a stronger claim to make is that the most physicists probably have to use MKL for their data analysis (I'm sure even you use MKL whether knowingly or unknowingly), and it is probably written in a mix of C/Fortran with handrolled assembly. Right. In fact, you have to use C/Fortran API calls to MKL, while you can use PyROOT as a front-end for ROOT classes. Does this mean that most aspiring physicists should learn C/Fortran as their first language? No.
 
  • #12
meanrev said:
If you want to argue along these lines, a stronger claim to make is that the most physicists probably have to use MKL for their data analysis (I'm sure even you use MKL whether knowingly or unknowingly), and it is probably written in a mix of C/Fortran with handrolled assembly. Right. In fact, you have to use C/Fortran API calls to MKL, while you can use PyROOT as a front-end for ROOT classes. Does this mean that most aspiring physicists should learn C/Fortran as their first language? No.

That's a fair point. Particularly in school you're going to use an interpreted front end. If you need to dig into the C++ I suppose you can pick it up as you go.
 
  • #13
carlgrace said:
That's a fair point. Particularly in school you're going to use an interpreted front end. If you need to dig into the C++ I suppose you can pick it up as you go.

(: That's my advice. The other way is to work in the opposite order. I'm not adding new insights to this thread like that; only difference is that I should re-emphasize that current trends favor parallelism.
 
  • #14
My recent experience is that Python is a utility code and the main computational system is developed in C++. Fortran is another mainstream language, since a lot of legacy code exists in earlier flavors of Fortran.
 
  • #15
meanrev said:
... there is a greater emphasis on data visualization and statistical analysis, both of which it's perhaps an order of magnitude faster to develop with MATLAB toolboxes/Python modules as compared to learning a couple of C++ libraries. Physics research is like that, you often want to get something done, for a few uses (perhaps the length of a research project), then throw the code away... not necessarily a good practice but that's how it's done.
carlgrace said:
I don't know about that... the physicists I work with constantly use the ROOT libraries for their data analysis, and they are written in C++. What physicists are using MATLAB these days?
Astronuc said:
Fortran is another mainstream language, since a lot of legacy code exists in earlier flavors of Fortran.

All of these statements are partially true at my department:

  • Most of the biophysicists and astronomers use Python, often for the reasons meanrev mentioned.
  • The particle physicists primarily use ROOT libraries in C++, as carlgrace said.
  • Two computational quantum physicists in my office use finite-element methods in MATLAB.
  • I use Python and MATLAB for stochastic differential equations and Schrödinger time-evolution.
  • My advisor is 900 years old and still prefers FORTRAN, but we've gotten him to use MATLAB as well. (As Astronuc mentioned, many 'modern' algebra packages are based on legacy FORTRAN routines. For details, look up LAPACK and BLAS.)
  • Some of the computational astro specialists use Python, C, C++, and a bunch of weird stuff I barely understand.
 

FAQ: I am an aspiring physicist. Should I learn C++?

Is C++ a necessary language for aspiring physicists?

C++ is not a necessary language for all aspiring physicists, but it can be a valuable tool to have in your arsenal. It is a high-level programming language that is well-suited for scientific computing, making it a popular choice among physicists for data analysis and simulation.

Can C++ help me in my research as a physicist?

Yes, C++ can be very useful in research as a physicist. It allows for efficient and fast computation, making it ideal for handling large amounts of data and complex simulations. Additionally, many scientific libraries and tools are built using C++, making it easier to integrate into your research projects.

Are there any other programming languages that are better for physicists?

C++ is not the only programming language used by physicists. Other popular languages include Python, MATLAB, and Fortran. Each language has its own strengths and weaknesses, so it ultimately depends on the specific needs of your research project.

Do I need to have prior programming knowledge to learn C++?

Having prior programming knowledge can definitely be helpful when learning C++, but it is not necessary. C++ can be a challenging language to learn, but with dedication and practice, anyone can become proficient in it.

How long does it take to learn C++ as a physicist?

The time it takes to learn C++ as a physicist can vary depending on your prior programming experience and how much time you dedicate to learning. However, with consistent practice and a clear understanding of the fundamentals, you can become proficient in C++ in a matter of months.

Similar threads

Back
Top