Learning Programming for Physics Research in Grad School

In summary, it is important to learn the basics of programming and how to solve problems, as this will help you in your research in physics involving computations and simulations. However, it is also important to take into account the area of physics you are interested in and the programming language that is most appropriate for that area.
  • #36
physiker_192 said:
Looking at others people's codes and trying to analyze and understand how it works is a waste of time in my opinion.

Not if you're working in a research group that has already developed code that you're asked to modify, e.g. by adding new features.
 
Physics news on Phys.org
  • #37
jtbell said:
Not if you're working in a research group that has already developed code that you're asked to modify, e.g. by adding new features.

This is true, but for beginning, I find it more useful to start from scratch and learn the things (e.g. objects) as one would need them, by doing so, one might have to look at other codes just to see how certain parts work.

Immediately jumping to large codes is not encouraging in my opinion, especially if the code has a GUI and a large number of classes.
hadsed said:
Completely disagree. This is exactly how I learned how to program 8 years ago, and how I learned each programming language I know. Maybe I'm different, but I've never actually read a programming book and only half paid attention in the two classes I took for Java and MATLAB.

I think it's more helpful to tell how you learn instead of telling people how they should learn.

I too didn't pay much attention during the compulsory programming classes either, which I found that they get more annoying as they progress (linked lists etc...). I started the other way around, writing small non-computational codes, till I decided to write a computational MATLAB code to calculate the bandstructure of Silicon. Being the first real code, I took me sometime to finish due to various issues, I had to learn how to write MATLAB functions (was annoying because I didn't recognize the syntax properly) and so on.
 
  • #38
physiker_192 said:
Looking at others people's codes and trying to analyze and understand how it works is a waste of time in my opinion.

It's not for any non-trivial project. Computational astrophysics codes often have 100,000 lines and *decades* of effort put into them. Reading those codes is seriously important, and writing clean code so that people ten years from now can figure out what you are doing is even more so.

And it will seriously help you get a job. Microsoft Windows has about 10 million lines of code and 10,000 programmers, and being able to read and write clean code is seriously important.

It will also help you develop gut feelings. For example, my stomach turns every time I see bad code, because it reminded of the times in which I had to spend *months* fixing something that could be fixed in five minutes had someone properly designed things.

What you can do which should benefit you much more is to pick some field and write a code/program in connection.

This won't work for computational astrophysics. The thing about astrophysics codes is that they often will contain parts that are coded by hyper-experts in a field. For example, there is no way that I can completely comprehend nuclear physics as well as someone that has been spending several years studying it, and there is no point in my duplicating his or her work, if they have provided the subroutines so that I can just call the EOS routines.

For example, if you like semiconductor physics then you can write a code for bandstructure calculation and visualization/plotting.

This is kindergarten.

Edit: if I'm not mistaken, computational physics books basically consist of tackling multiple mini projects/codes.

Yes. This is first grade stuff. Textbooks are useful, but you aren't going to learn coding from a textbook any more than you can learn to ride a bike by just reading about it.
 
  • #39
hadsed said:
I never really quite understood the point of FORTRAN 90. Why not just use C, or in the case of compatibility issues, just make calls to the old F77 code?

Fortran 90 has some structures that tell the compiler (this line can be parallelized, put everything in the L1 cache). If you have a good compiler, they can take the hint and generate better code.

I still don't know. I've always been told that C++ was rather thrown together and not really well managed as far as features go. I'm still something of a noob with it, but sometimes I catch glimpses of this, so I always imagined that something like D (or another more elegant/organized/easier language) would come along and make the world happy again.

C++ is a mess but so is the human body. C++ is an example of how evolution sometimes works better than intelligent design. People add random stuff to C++, some of it sticks, most of it doesn't, and the language evolves.
 
  • #40
physiker_192 said:
Immediately jumping to large codes is not encouraging in my opinion, especially if the code has a GUI and a large number of classes.

That's actually the point. Very well written code is a joy to read. If the code has a GUI and a massive number of classes with no documentation, then it's painful to figure out what is going on. This is your first lesson in how not to write things.
 
  • #41
What about theoretical high energy physics ? Is programming of use in this case?
 
  • #42
zahero_2007 said:
What about theoretical high energy physics ? Is programming of use in this case?
Yes, absolutely. For one thing, knowing how to use a computer algebra system (i.e. Mathematica) is a huge boon. Many calculations done in high-energy physics involve working with matrices or other multi-indexed objects, which basically comes down to repeating the same operation on many different mathematical expressions, and Mathematica's programming facilities are perfect for that sort of work. Also, a lot of work in theoretical HEP is done with computer simulations these days, and in order to work with one of these you would have to know how to write it and maintain it, understand the algorithms involved, and be able to analyze and process the output, all of which require programming skill.
 
  • #43
zahero_2007 said:
What about theoretical high energy physics ? Is programming of use in this case?

Look at this:

http://root.cern.ch/drupal/
 
  • #44
physiker_192 said:
Looking at others people's codes and trying to analyze and understand how it works is a waste of time in my opinion.

Welcome to the real world. Million+ line projects don't get done by a group of people that have the same experience/coding philosophy/design standard/documentation standard and so on.

Also this reminded me of some young programmers in a diploma I did, where they all wanted to have their own game engine built entirely from scratch which was going to be superior and so on.

When there is only finite time to work on complex projects, you will need other peoples libraries to get the job done in time. For a lot of projects there is no way around this.

Also its good to see others code to put yourself relative to other people. You may find out that you're coding is not so crash hot, or you might find out a horrible way of doing something so that you have a mental note of what is really bad. Sometimes it's good to get how you are relative to other people both better and worse than yourself.
 

Similar threads

Replies
2
Views
897
  • STEM Academic Advising
Replies
7
Views
1K
  • STEM Academic Advising
Replies
12
Views
671
  • STEM Academic Advising
Replies
3
Views
1K
  • STEM Academic Advising
Replies
2
Views
851
Replies
11
Views
3K
  • STEM Academic Advising
Replies
3
Views
1K
Replies
10
Views
2K
Replies
16
Views
1K
  • STEM Academic Advising
Replies
3
Views
572
Back
Top