variables (generally, of different types: integer, floating point, character; arrays; structures)
control statements: if/then/else
loops: for, while
libraries for common tasks
support for reading and writing data in various formats (ASCII / FITS / custom)
Different kinds of languages:
compiled languages: source code needs to be explicitly translated into machine code, generally in two steps: compilation and linking
machine language
basic languages: C, Fortran
more advanced languages (often "object-oriented"): C++, many others
"interactive" languages
provide interactive programming as well as the ability to run existing programs
can be (but are not always) less computationally efficient than compiled programs
generally provide more extensive libraries, e.g. for plotting
astronomy possibilities:
Python, with matplotlib for plotting
IDL, with Astronomy Users Library
MATLAB
SuperMongo
gnuplot
in astronomy, Python is undoubtedly the most ``up and coming"; also, freely available; also, widely used outside of astronomy/academics
languages evolve and change! Understand the principles and be open-minded!
Overall programming principles:
Programming may be one of the more important skills you develop in the graduate program!
Think about coming out of NMSU with a programming portfolio!
Assume that everything you write has an error in it (it usually does!): consider how you can test things!
less is more (to a point) - don't repeat work, make the tool better and reusable
If your code has blocks that are very similar to each other, you can probably make it more efficient
Use functions/subroutines
Think before you program: outline what needs to be included and consider how it can be made more modular
all software should be written as if someone else will use it: document and share
style, e.g. PEP8 guidelines, e.g., white space, indentation rules, ...
Make your program readable. Use white space judiciously, recognizing tradeoff between separating program blocks and increasing length of code. Modular code is generally easier to read and digest.
comments: every program must be commmented! Include an overview comment at the top and clarification comments throughout the code as needed. Don't need to comment what is apparent from reading the code if the code is straightforward. Separate comment statements are usually preferable to ``end-of-line" comments.
Avoid hard-wired directories: consider use of environment variables to specify root directories
Avoid hard-wired constants, file lengths
Don't be too reluctant to rewrite code! Be self-critical.
With "interactive" languages, experiment "interactively", but produce all final output using saved programs, so it is repeatable
Show your code to others!
Most astronomers think they are good programmers; most programmers would probably disagree,
see, e.g., here , realize what you don't know, and learn it as appropriate
what astronomers can bring to the table: knowledge of analysis techniques, coming up with creative
approaches/solutions to problems
standard for distribution of packages: often you download a package, unpack it, and enter: make to compile the whole
thing, make install to install the final executables to some location in your PATH