What programming language(s) should an aspiring physicist learn?

In summary: I just started python about one month ago and I learned ALOT;I higly recommend it. I've been learning from "Python Scripting for Computational Science" by Langtangen, Hans Petter. It's been fruitful so far. I recommend getting a book that is geared toward people that are new to programming, such as "Python for Data Science Quick Start" by Brett Slatkin.
  • #1
cordyceps
50
0
I was surfing around the forum, and I noticed that several people recommended learning programming for physicists. What language is most useful for physicist? C? Fortran? Java?
 
Physics news on Phys.org
  • #2
The most common language for the subfield you are interested in.
 
  • #3
If you are going to be working in a lot of fields using simulations or models the existing stuff is going to be written in Fortran or very Fortran-like 'C'.
If you are starting from scratch, python (with numpy and scipy) is good, or if you are in a more theoretical area something like maple or mathematica.
 
  • #4
C plus plus
 
  • #5
Matlab/Simulink seem to be pretty big in physics and engineering. LabView is also extremely useful if you do experimental work.
 
  • #6
I would suggest C/C++. I found that learning this helped me when I was using Visual Basic for Applications, Matlab, PV-Wave etc.
 
  • #7
C/C++, Fortran and Matlab are the main ones.

Java if you're considering working outside academia.

Labview if you're suicidal and wish to learn the worst piece of software ever created by man.
 
  • #8
tmc said:
C/C++, Fortran and Matlab are the main ones.

Java if you're considering working outside academia.

Labview if you're suicidal and wish to learn the worst piece of software ever created by man.

Well, I don't like Labview either; but it is still the de-facto standard for controlling small(ish) measurements setups and there is not like there is much choice if you e.g. want to control DAQs (I have used Labview on a daily basis for almost ten years). Not to mention the fact that it is the only software EVERYONE knows how to use (I would often prefer to e.g. use the Instrument Control Toolbox for Matlab; but most of my colleagues don't know how to use it)
Also, Labview isn't a "normal" programming language and is pretty much useless for anything outside the lab so it is not something one would learn INSTEAD of e.g. Python. That said, if you know how to write simple programs in Python, C, Java etc you will be able to write Labview programs almost immediately.

Hence, learning Labview is a good idea; but wait until you actually need it and learn another language first.
 
  • #9
I'm trying to convert everyone to using Matlab's instrument control toolbox instead of labview

6 lines of code are much neater than 9 boxes and 21 arrows.
 
  • #10
I've been hopping between IDL and PERL for use in astronomy research. I guess I use a bit of C/C++ as well, but PERL is definitely what I use the most for right now.
 
  • #11
Python is a very powerful and easy to learn language.
 
  • #12
Python would be a great place to start.
 
  • #13
I'd recommend C++. You'll learn a very popular, powerful, and modern language and at the same time learn C into the bargain.
 
  • #14
Fortran 77 and 93 are still very popular with many researchers.

Python is becoming the standard though for much of physics and it's much more powerful than MatLab users realize.
 
  • #15
I think this is the wrong question. You should learn to program, not learn a language.

There are a lot of people that can cobble something together that runs. There are many fewer who can actually program.
 
  • #16
I recommend learning Mathematica, since it combines a general programming language with the most powerful symbolic system for doing algebra, calculus, visualizations, etc. It really saves a lot of time!
 
  • #17
I think Fortran is very easy to learn, it seemed the most "naturally English" to me. I also think Mathematica is a good program, it -really- helped me study for my math methods in physics courses.
 
Last edited:
  • #18
Thanks everyone.
I just have another quick question. My school only offers C++ and java as intro computer science classes. In general, do people learn python, fortran, mathematica, etc. on their own, such as by reading books on the subject or by working in a lab?
 
  • #19
cordyceps said:
Thanks everyone.
I just have another quick question. My school only offers C++ and java as intro computer science classes. In general, do people learn python, fortran, mathematica, etc. on their own, such as by reading books on the subject or by working in a lab?

Introductory C++ and Java classes are a waste of time. They stretch a week's worth of material into a quarter/semester.

You will probably pick up most languages as you study and work on projects.
 
  • #20
Haskell since it forces you to think mathematically.
 
  • #21
"Introductory C++ and Java classes are a waste of time. They stretch a week's worth of material into a quarter/semester.

You will probably pick up most languages as you study and work on projects."

Well, in another thread csprof2000 and matlabdude both suggested taking formal courses in programming if you're totally new to the subject.
 
  • #22
I just started python about one month ago and I learned ALOT;I higly recommend it. I've been learning from "Python Scripting for Computational Science" by Langtangen, Hans Petter. It's been fruitful so far. I recommend getting a book that is geared toward applications in engineering/physics; learning this way is more fun.
 
  • #23
"Introductory C++ and Java classes are a waste of time"

Any course is what you make of it.
 
  • #24
confinement said:
I recommend learning Mathematica, since it combines a general programming language with the most powerful symbolic system for doing algebra, calculus, visualizations, etc. It really saves a lot of time!

I really recommend against learning Mathematica as a programming language, especially as a first programming language. Learning basic programming techniques is difficult in Mathematica and it also teaches incredibly poor style - switching to a real or less eccentric language will be very difficult afterwards.

More things I hate about Mathematica:
-it's treatment of abstract datatypes is VERY poor (lists are vectors, not lists!)
-the interface looks awful and is not very helpful (lack of use of indentation is horrible)
-no concept of orders of growth and optimzation becomes basically impossible (also speed comes back to the fact that lists are really vectors)
-also, you need a license


Honestly, for brief uses of symbolic logic I like Mathematica fine. But it should never be anyone first "programming lanauge". EVER.
 
  • #25
At least it's not MATLAB.
 
  • #26
whybother said:
Mathematica-it's treatment of abstract datatypes is VERY poor (lists are vectors, not lists!)

Are you referring to the fact that addition of lists and multiplication of a list by a scalar are defined ? I don't see how this is a drawback, since you can choose not to use this feature.

-the interface looks awful and is not very helpful (lack of use of indentation is horrible)

I like the universality of the interface, it allows me to combine text, equations, code, and graphical output in a single document. It is a very fast tool for students doing homework or for professionals writing papers (it has great LaTeX export).

Also, if you prefer to use a text editor like emacs to creat .m scripts and then load them into mathematica through the shell then you can certainly do that. If you want a 'visual studio' type of environment then look at Wolfram Workbench.

-no concept of orders of growth and optimzation becomes basically impossible (also speed comes back to the fact that lists are really vectors)

Mathematica is slow because it is interpreted rather than compiled. If you are working with rectangular homogenous lists or reals or integers (i.e. matrices with a well-defined dimension and the same data type for each element) then you can have mathematica treat these as machine-arithmetic arrays.

Also, I believe Don Knuth said that premature optimization is the root of all evil --- Mathematica is the ideal programming environment for students or for professionals with assorted mid-size computational tasks or who want to do rapid prototyping of simulations.

-also, you need a license

Yes, more than once I have felt some motivation to start a free clone of Mathematica, but if you look at Octave (free MATLAB clone) it still has a long way to go and Matlab is so primitive compared with Mathematica (from a mathematics / pure CS point of view).

Honestly, for brief uses of symbolic logic I like Mathematica fine. But it should never be anyone first "programming lanauge". EVER.

I think it is a good first language for physics students because it has immediate application in their coursework (e.g. they are more likely to practice iterative programs when it saves them from doing 12 integrals to "compute the first three terms of the Legendre polynomial expansion..." etc).

Physics students just don't have time for all that CS material about data types, delayed evaluation, functions vs procedures, pointers, lists vs arrays, machine instructions, run-time stack, sequence-decision-iteration, etc. The bright ones who go on to graduate school can learn this material in short order if they ever need to, preferably by taking a CS course.
 
  • #27
I think the most important is the speed

Mathematica is easy to learn but slow.
Matlab is a little bit hard to learn but slow.
C and Fortran are hard to learn but are faster
C and Fortran are much FASTER FASTER FASTER than mathematica and Matlab.

If you need to perform millions of operations you need fortran or C. If C speed 1 hour then mathematica will speed days.

If you whant to solve x*x + 1.23*x + 0.99 = 0 use mathematica and do not waste your time in C or Fortran, but if you whant to solve partial differential eq. that apear in General relativity or fluid mechanics use C or Fortran

I preffer Fortran 90 than C, I think Fortran 90 is easier than C but both are great.
 
  • #28
I think that if you know one programming language, it should be object oriented. That's my feeling on the matter.
 

1. What programming languages are most commonly used in physics?

The most commonly used programming languages in physics are Python, C++, and Fortran.

2. Should I learn multiple programming languages or focus on one?

It is recommended to have a strong foundation in at least one programming language, but knowledge of multiple languages can be beneficial as different languages have their own strengths and are used in different areas of physics.

3. Is it necessary to have programming knowledge as a physicist?

While not necessary, having programming knowledge can greatly enhance a physicist's research and data analysis capabilities. It can also open up opportunities for collaboration with computer scientists and engineers.

4. Which programming language is best for data analysis in physics?

Python is a popular choice for data analysis in physics due to its simple syntax, vast libraries for scientific computing, and its ability to handle large amounts of data efficiently.

5. Can I learn programming on my own or do I need formal education?

While having a formal education in programming can be beneficial, it is possible to learn programming on your own through online resources, tutorials, and practice. Many physicists also learn programming through on-the-job training and collaboration with colleagues.

Similar threads

  • STEM Academic Advising
Replies
12
Views
1K
  • STEM Academic Advising
Replies
15
Views
1K
  • STEM Academic Advising
Replies
11
Views
4K
Replies
40
Views
2K
  • STEM Academic Advising
Replies
3
Views
905
  • STEM Academic Advising
Replies
23
Views
923
  • STEM Academic Advising
Replies
15
Views
2K
  • STEM Academic Advising
Replies
5
Views
841
  • STEM Academic Advising
Replies
4
Views
2K
Back
Top