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

Programming advice for a physics major?

  1. Jun 23, 2017 #1
    I will be starting my undergraduate career this coming fall and was wondering how I should prepare for the programming that I will need for my studies. My first computational physics course will be in my second year, therefor I have quite a bit of time to practice my coding.

    I have taken two computer science classes in high school, and have done some learning on my free time as well. I know some JavaScript, HTML, and CSS, but I spend most of my practice time writing code in Python (as I've assumed it is the most relevant language to programming for physics among the languages that I know).

    I'm just wondering if it would be best to continue working on and improving my coding through the languages I already know, such as Python, or if I should spend my time learning a new language, such as C++. Any suggestions, practice tips, and/or advice is greatly appreciated!
     
  2. jcsd
  3. Jun 24, 2017 #2

    jedishrfu

    Staff: Mentor

    Well one thing you could do is get more familiar with Python using numpy, sympy and scipy.

    And you could take some time to play with MATLAB. Its big in the engineering community. Many physicists here at work are masters of it.

    There's a free clone called Freemat (look for v4.2) that is a pretty good with the core MATLAB functionality enough to get you started without dropping any money on MATLAB. The MATLAB student version though is $100 (its how they get you addicted to MATLAB) and is worth it if you're serious about computational aspects of physics. It can draw some nice charts with minimal effort.

    Anyway, here's the freemat primer to get you started:

    http://stuffle.website/references/FreematPrimerV4e1-1.pdf

    There's also the Open Source Physics website www.compadre.org where you can find resources and code to build real physical simulations. They also have a book Intro to Computer Simulation by Gould, Tobochnick and Christian that has many great examples of using the software they provide.
     
  4. Jun 24, 2017 #3

    Mark44

    Staff: Mentor

    I don't think it would hurt to learn some C++.
     
  5. Jun 24, 2017 #4
    I'll definitely look into MATLAB and www.compadre.org, thanks!
     
  6. Jun 25, 2017 #5

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    It would help you to be at aware of important languages like C++ and MATLAB and their general characteristics. They are very different from Python. But you should find out what language your school uses in their courses and concentrate on that language.
     
  7. Jun 25, 2017 #6

    ChrisVer

    User Avatar
    Gold Member

    Good luck with your studies. As for computational physics I believe either knowing python or Matlab will be good enough for you... In fact, as a physicist, it doesn't matter which language you're using as long as it allows you to do the job.

    HTML and CSS are not that useful in this aspect (except for if you will need to create your homepage + modify it as you like ).
    Python is amazing, since it's easy to read and write, and if you come across speed issues you can always use cython or something like this.

    I wouldn't suggest C++ except for if you want to work with a very specific field in physics (such as particle physics) or if you want to understand a little better (or get a handle of) how memory is treated by your programs.

    In fact, as a physicist knowing 1 language is good enough to allow you migrate to others, because the logic that you will need (how to turn your problems into program algorithms) is always the same, what changes is the syntax (eg the beautiful Python code, which is read like a book, vs the terrible C++ syntax) and the features of each language (eg Java works only with classes). The important for you is to learn the language that your group (or collaboration) is widely using.
     
    Last edited: Jun 25, 2017
  8. Jun 25, 2017 #7

    jedishrfu

    Staff: Mentor

    Many traditional modeling programs were written in fortran and are still in use today.

    Some of the more popular ones have transitioned to C++ for increased flexibility and extending and improving the programs architecture.

    In our lab, a mix of matlab, fortran, c++, python and java are used along with several scripting languages for glueing things together.
     
  9. Jun 25, 2017 #8

    wle

    User Avatar

    @Josh_Guthrie: you're already doing one thing right, which is to practice solving programming problems and writing code.

    You can learn things that are used by physicists (Matlab, C++, Numpy/Scipy for Python, etc.). I'm not sure how useful this is though in the long term, since they're not really going to teach you anything fundamentally new about programming and they're the sort of thing that you can just look up when you know you need them. So passing familiarity and awareness that they exist is probably enough.

    If you want to broaden your perspectives on programming and you're in it for the long haul then I'd recommend learning C and Lisp. They're both historically important programming languages that have had a huge influence on other languages, and are both still in use today. They're also very different languages from each other (i.e., not just the same thing with different syntax) that you can learn different useful things from (broadly, low-level issues from C and high-level abstractions and metaprogramming from Lisp).
     
  10. Jun 25, 2017 #9

    ChrisVer

    User Avatar
    Gold Member

    I don't know why would someone "waste" work time (their time and also time for the new-comers who will handle the code later- who will have to learn how both languages work) for writing code in Java when they are already using C++ (or the other way around)... Several times I have turned against Fortran use from (new) physicists.
    From a physicist perspective, the only difference I see in C++ and Java is that the last has the garbage collectors (and so you don't have to free memory with "delete"), and what I mentioned above (Java works with classes even for the simplest tasks).

    Of course I am not going to say what is better or worse, a programmer must know several languages and be able to jump from the one to the other (because that's his job) and also learn new languages easily (because several appear in market each year)... My comments aim specifically for a physicist. Lisp is both bad and unnecessary in that case. C can be useful.
     
    Last edited: Jun 25, 2017
  11. Jun 25, 2017 #10

    wle

    User Avatar

    If this is directed at me then, as a physics postdoc who has found some excuses to use Lisp, I disagree. (I could make the case that the physics community as a whole has also disagreed insofar as it is adopting more Lisp-like languages like Python and Julia.)

    I think you're also assuming (in this case possibly correctly and possibly not) that a physics student won't be interested in learning anything more than the bare minimum that they can immediately put to use about programming.
     
  12. Jun 25, 2017 #11

    ChrisVer

    User Avatar
    Gold Member

    I wouldn't put a terrible language as lisp next to python.

    Hmmm, no I don't believe that. I am interested in several languages myself... But it's up to an individual to decide how far they want to go in language learning and CS (another science).
    A physicist though, doesn't have to know a lot of details to make their program work (or develop their code). When you aim for a specific goal though, I recommend to learn the language your group is using (in my case I had to learn python and c++, someone else might have to learn MatLab,Mathematica or Java).
     
  13. Jun 25, 2017 #12

    wle

    User Avatar

    What makes you think Lisp is a terrible language?
     
  14. Jun 25, 2017 #13

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    That is a startling statement. I have never seen a similarity between Lisp and those languages. What similarities are you referring to?
     
    Last edited: Jun 25, 2017
  15. Jun 25, 2017 #14

    ChrisVer

    User Avatar
    Gold Member

    parentheses... even a bash script is easier to read or write.
     
  16. Jun 25, 2017 #15

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    I think that the varieties of recommendations hare has made the point that there are a lot of languages that physicists might use. That is why I would recommend asking some physics professors in your school what language they recommend. Any work you do with them will almost certainly be in their preferred, established language.
     
  17. Jun 25, 2017 #16

    jedishrfu

    Staff: Mentor

    Since this thread discussion has run its course and the OPs question has been answered, its a good time to close this thread and thank everyone for their contribution.

    Take care and thank you
    Jedi
     
    Last edited: Jun 25, 2017
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Programming advice for a physics major?
Loading...