1. Limited time only! Sign up for a free 30min personal 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!

Best programming language for physics

  1. Oct 30, 2013 #1
    Hello,

    I'm not sure if this is the right place for this thread, but I think it is (This forum is for computational physics as well)

    So, my question is quite "soft". What is (in your opinion, obviously) the best programming language for physics? Also, what programming language is most used in physics?

    Nowadays, if you had to learn a new language, as your first programming language, what would you pick?
     
  2. jcsd
  3. Oct 30, 2013 #2

    phinds

    User Avatar
    Gold Member
    2016 Award

    This question is asked about once a week. I suggest a forum search.
     
  4. Oct 30, 2013 #3

    TumblingDice

    User Avatar
    Gold Member

    BASIC is a friendly, easy to learn language with simple variable definitions and statements.

    If this is for intensive calculations like modeling/simulation, "C" would be more appropriate to the task.

    Perhaps I'm showing my age when I say, if there's a lot of math (not meaning reiterative), I'd consider FORTRAN. :)
     
  5. Oct 30, 2013 #4
  6. Oct 30, 2013 #5

    Astronuc

    User Avatar
    Staff Emeritus
    Science Advisor

    The two principal languages would be Fortran (F90 or later) and C++. These days, object-oriented programming is widely used. There is a huge volume of legacy codes written in earlier versions of Fortran, particularly Fortran 77, and more recently C++.

    http://www.dmoz.org/Computers/Programming/Languages/Fortran/Source_Code/Physics/

    Most physics problems involve solving systems of differential equations, both ordinary and partial, and in many cases, non-linear.

    Python is often used to support programs written in Fortran or C++.

    Then there are packages like Matlab, Mathematica, Maple, . . . .

    Linking to other threads is useful.
     
  7. Oct 30, 2013 #6

    jedishrfu

    Staff: Mentor

    There is also Java with the Open Source Physics toolkit (www.compadre.org/osp). It comes with many examples of how to do a variety of different simulations and its open source. Programs are developed using Eclipse or Netbeans.
     
  8. Oct 30, 2013 #7
    Python is probably the most user friendly and intuitive language for beginners IMO.

    It's relatively weak when doing numerical calculations, which is why people use it to implement numerical algorithms in Fortran or C++ (both strong in that area).
     
  9. Oct 30, 2013 #8
    I read from one book that Python also comes with several different implementations, one is PyPy and NumPy. The latter is said to be quite good in numerical computation while the former is faster than the standard Python.
     
  10. Oct 30, 2013 #9

    Student100

    User Avatar
    Education Advisor
    Gold Member

    The first language I'd recommend you learn is C. That makes learning C++ rather simple, and you can focus more on OOP than syntax. I'm not sure how I feel about python, it just doesn't perform all that well unless you invest a lot of time in it, but it is open. I'm not a fan of Java at all.
     
  11. Oct 30, 2013 #10

    jedishrfu

    Staff: Mentor

    In answer to the last question of the OP, I would choose Scala. It seems general purpose languages are moving toward functional programmings in conjunction with OO.

    When you look at legacy systems, the oldest apps are written in FORTRAN, more recent ones are in C++ and the latest ones are in Java. I see this trend moving towards Scala in the coming years. What makes Scala so appealing is its ability to work well with Java libraries while at the same time bringing a new way of thinking about software design...
     
  12. Oct 30, 2013 #11
    Start learning programming with python then move on to another lower level language if you need it. Python will allow you to do the most without needing to write the same code again and again. You can easily use modules to replace other programs like matlab etc.

    The older guys use fortran and c++. The younger people use python,java,and c++. You can do GPGPU in python and java if you need it or move down to lower level c++. There is no point at getting down lower than C++ because compilers are optimized pretty well to the point that your java code wont lose a significant amount of performance relative to a lower language. There is a point of diminishing returns and if there wasnt we would all be writing in Assembly which physicists usually dont.
     
  13. Oct 30, 2013 #12

    jedishrfu

    Staff: Mentor

    And the professionals don't bother to argue about stuff like this, they choose the best language to get the job done and then go home to do other things...
     
  14. Oct 30, 2013 #13

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    Adding my two bits to what you wrote: There is no single language that stands out as the "best programming language for physics". A good programmer knows several languages. The old adage "learn a new language / tool every year" is more applicable now than ever.

    We get these kinds of threads on a very regular basis, and they invariably decay into a religious war over computer languages. From what I've seen, the detractors of language XYZ (pick your language) invariably do not know what they're writing about.
     
  15. Oct 30, 2013 #14
    thats not actionable advice.

    Different languages have their strengths and weakness which means some languages have features which make detractions reasonable. Assembly has trade offs when compared to Python is a simple example of such tradeoffs.

    The simplest answer is to learn the programming language that the people around you know so you could have someone to look for answer to questions.
     
  16. Oct 30, 2013 #15
    I don't know if this is helpful but in my experience the best coding language is often going to be dictated by the group you are in and what language that group writes their codes in. My group wrote theirs in C++ so I needed to learn C/C++. Also in my brief experience it seems it is important to be able to competently code with one language of ones choice (at minimum) but be able to read code in other languages.
     
  17. Oct 31, 2013 #16
    The languages most often used are still FORTRAN and C/C++ so, as a general answer I would tell a physicist wannabe to learn those. If you have a specific group you know you will be working with them ask them what language they use and follow their lead.
     
  18. Oct 31, 2013 #17
    Are people really serious when they advocate FORTRAN of all things as anyones first or primary language? Like really?
     
  19. Oct 31, 2013 #18

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    Really. The question wasn't the best language(s) to learn in general. The question at hand is what are the best language(s) for physics, and Fortran (note the spelling) most certainly is in that category.

    Note well: I am not speaking as a Fortran aficionado. I personally haven't used it for 20 years. There are still times when I regret the switch to C/C++. Fortran is quite widely used for physics and related applications where sheer number crunching power is paramount.
     
  20. Oct 31, 2013 #19

    cgk

    User Avatar
    Science Advisor

    D H,
    even in Fortran[1] is still widely used, most of the applications occur either in legacy codes or in codes directly depending on other Fortran codes. And it is one of the few languages which one can truly classify as "bad" without further qualifying this statement. It is not even only the language, the language implementations are also sub-par: Take five different compilers, and you will find five different subset of the Fortran 95(!!!) standard which work as standardized.

    While being able to read and write Fortran can still be important, I cannot see how it could possibly be a good idea to use this language for starting programming. Many *very* important idoms in programming, including very basic ones (like, compound data structures) simply cannot be expressed in any meaningful way in this language. Starting programming with this is bound to create many problems when later moving to more powerful languages. However, the other way around (say, starting with Python and C++ or Java and then using Fortran if you really have to) does not have this problem at all.

    ([1] and it used to be spelled in upper case)
     
  21. Oct 31, 2013 #20
    Fortran is mostly around as legacy code or code written by some theorist in high energy and it is losing market share among physicists. Programs are being rewritten to other languages like C++, an example of which is Pythia which used to be in FORTRAN in early versions.

    ROOT is in C++. CMSSW is C++ based.

    GPGPU is done using CUDA and OpenCL which the base libraries are done in C++.

    Matplotlib is used by physicists in many fields to generate graphs and can be used to do GPGPU using pyopencl.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Best programming language for physics
Loading...