Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Programming Languages for the Physicist

  1. Dec 24, 2016 #1
    Hi all,

    I am a sophomore physics and math major who has realized the importance of being able to code, so I decided to start learning. My question is, what languages should a young physicist learn? I was going to start with C but would like to know where to go from there.

    Thanks for the help!
  2. jcsd
  3. Dec 24, 2016 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Gold Member

    This depends on what exactly you want to do. I would expect a PhD student to know or be able to learn the following rather quickly:
    Matlab or Python

    Of course, the real skill is to be able to give a computer a sequence of logical instructions. The syntax of specific languages is just particulars that you can adapt to.
  4. Dec 24, 2016 #3


    User Avatar
    Gold Member
    2016 Award

    Starting w/ C is fine, as it is the basis for many modern languages (Java, etc). The important things is, as Orodruin said, to learn how to formulate problems as sets of logical instructions that can then be put into the syntax of whatever language you are using.
  5. Dec 24, 2016 #4


    User Avatar
    Gold Member

    I think its better to start with python. Its easier and you can use scipy or sage for scientific computing. Then you can learn C++. After that it'll be really easy to start with any other language.
    As for MatLab, I didn't even learn it. I started using it right away. No big deal. Don't worry about it. if you know a little programming you can do anything with it. Just search the internet for the code you need. I think mathematica is like this too.
  6. Dec 24, 2016 #5
    Okay, good to know I'm on the right track. Thanks guys!
  7. Dec 26, 2016 #6
    If you learn C it might be worth it looking at integrating GNUplots graphing capabilities. It's quite simple but something to keep in mind simply for ease-of-use.

    If you want a graphical interface I'm very impressed with tkinter in Python (although it gives me the heebie jeebies with the significance of tabs/spaces and the lack of semi-colons)
  8. Dec 26, 2016 #7
    +1 for C. I guess it is a must-know for everyone involved in scientific programming and probably the best choice for a beginner; the advantage of C against most other languages is that it is quite a low-level language and it makes you understand how some things are working "behind the scenes". When you will feel confident with it you should have no issues learning other languages(except maybe functional programming languages, which need kind of a different approach, and I think also learning one of those languages can be a nice and interesting exercise).
    Nowadays Python is also getting more and more popular and there are a lot of great scientific libraries, so probably at some point you may want to take a look at it.
    I would also recommend R for data analysis and statistical computing; with MatLab you can probably replace R and have a lot more functionalities, but well, R it's free.

    Another thing I found useful(not really necessary though), if you're working on UNIX systems, is to learn some basics of bash scripting; it can come in quite handy if you need to automate program runs with many different sets of data and stuff like this
  9. Dec 26, 2016 #8
    I think C is the right place to start. Beyond that, I think it depends on your long range plans.

    If you want to get into high performance programming for physics then the two main languages are C/C++ and Fortran. I think Fortran is better for this purpose but others may disagree.

    I am not a fan of C++ but the good thing about it is if you know C you can gradually start using some object-oriented features if you need to. But you are never forced entirely into the OOP paradigm as you are with the other so-called OOP languages.

    Since no one else mentioned Fortran here is a link to why it is still in use.


    If you are looking for free compilers for C, C++ or Fortran then consider MinGW.


    There are good numerical programming books for both C/C++ and Fortran. Perhaps this kind of programming should be your focus as a physics person.

    In case you ever want to get involved in AI programming for physics then Lisp is a good choice. There's a free console-based Lisp interpreter and compiler at


    Lisp is definitely not a mainstream language but I find it very useful for some things.

    Others have mentioned tools like Mathematica which are widely used, so I won't repeat that.

    One caution: if you talk to some physics professors, they will say programming is trivial for we physics types because we are so smart and programming is easy if you can understand QM. I would not take such an opinion as gospel. You will find out if you ever get into advanced programming.
    Last edited: Dec 26, 2016
  10. Jan 23, 2017 #9

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    Octave is a free clone of Matlab with nearly the same functionality and the best part, you can grab Matlab code from online and it usually will run in Octave.

    My [itex]\$ 0.02[/itex], in no particular order, C/C++, Fortran, Python, Java. Matlab is not a language per say, if you know C++, you can learn the Matlab syntax in about a day, the best part about it is that you get all the ease of graphics functionality built in that you don't have with C++ or Fortran. Now, I have Fortran on the list, some would shudder at the thought, but there is a butt-load of legacy code out there and when you get to the real world, you'll find that your going to have to look at old code and work with it, I worked for 15 years with a couple of codes that were a mix of Fortran and C/C++, we were talking about re-writing one of the codes, but management didn't want to set aside about 6-8 man-years of money over the next couple of years to shut down our operation and write codes.
  11. Jan 23, 2017 #10


    Staff: Mentor

    I'm not a physicist, but I'd have to agree with these remarks about Fortran, based on the number of physics-related questions we get here at PF, especially from members who are tasked with maintaining or updating legacy code.
  12. Jan 24, 2017 #11


    User Avatar
    Gold Member

    I find FORTRAN to be outdated (at least for the physics community). Obviously working with objects is way more necessary for a physicist, and its usage is soon to die out, since no new physicist is learning how to work on it for building projects (alas! because it's a very ugly one)...
    it may still be in parts of old-written codes which you won't really have to reach except for if it's your work to do so. I expect one day that someone will invest time to make the transitions... New codes are written in C++ or python... In my work I've never seen FORTRAN but I know it exists.
    From friends doing their PhD is also working with Mathematica, Matlab, (even java!) and rarely I've heard of Fortran.
  13. Jan 24, 2017 #12

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    Ye of little faith, the death of Fortran has been prognosticated for more than 25 years, the academic community may have moved away from it, but until all the computers in this world refuse to run it, the industrial base will continue to utilize it. There have been 3-4 updates and standardization's, it isn't dying anytime soon. I said the same thing over 25 years ago, since then, I wrote the code for my dissertation using it and have continued to write in it on and off and the job I just interviewed for and was given an offer was to extend a major analysis code which is written entirely in it.
  14. Jan 24, 2017 #13
    C will work. You're not really sure what your next requirement might be. Might be Fortran, Java, Python, Matlab, who knows?

    But the more you do and the better you get in C, the easier the next language will be to learn when needed.
  15. Jan 24, 2017 #14


    User Avatar
    Gold Member

    and we've only had C as part of academic courses for the last (maybe) 10-15 years.... I don't know for around how many years we have C++.
  16. Jan 24, 2017 #15

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    Where I went to school they were teaching C in the late '80's and where I went to graduate school they didn't start with C until ~'95. No clue when C++ took over.
  17. Jan 24, 2017 #16


    Staff: Mentor

    I took a class in C programming in 1985 at a local community college.That's 32 years ago.
  18. Jan 25, 2017 #17


    User Avatar
    Gold Member

    that was one amazing physics course program you had at your college!
  19. Jan 25, 2017 #18


    Staff: Mentor

    It wasn't a physics course -- it was just an introductory programming course at the community college (= two-year college) where I was teaching. The language used in the class was C. I was already familiar with Basic, Fortran, Pascal, and Modula-2, but wanted to start learning C.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Discussions: Programming Languages for the Physicist
  1. Programming Languages (Replies: 19)

  2. Programming language (Replies: 10)

  3. Programming Languages (Replies: 1)

  4. Programming Language (Replies: 2)