1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Feb 21, 2013 #1
    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.
  2. jcsd
  3. Feb 21, 2013 #2

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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.
  4. Feb 21, 2013 #3
    What if I want to do research?
  5. Feb 21, 2013 #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.
  6. Feb 21, 2013 #5
    thank you all!
  7. Feb 26, 2013 #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?
  8. Mar 11, 2013 #7
    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.
  9. Mar 17, 2013 #8
    absolutely, I use it every day.
  10. Mar 18, 2013 #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.
  11. Mar 18, 2013 #10
    I dunno 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.
  12. Mar 18, 2013 #11
    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.
  13. Mar 18, 2013 #12
    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.
  14. Mar 19, 2013 #13
    (: 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.
  15. Mar 19, 2013 #14


    User Avatar

    Staff: Mentor

    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.
  16. Mar 19, 2013 #15
    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.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

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