Table of Contents
Writing code is essential in scientific simulations: be it to automate the running of a task, to do complex calculations for a simulation, or to post-process results. A properly configured code editor can be a productivity boost in these tasks. Other software, such as a compiler, package manager, script interpreter, notebooks, are equally essential.
Code editor
A code editor is a program specialized in writing plain text, as opposed to the rich text of software like LibreOffice Writer or Microsoft Word. Good code editors give a lot of functionality to move around code, edit it, re-factor it, search it, compile and run it, etc.
There are code editors on Linux that can run in the CLI: it is worth spending some time to get familiar with them, as you can use them to edit code on remote machines (e.g. adjusting a script running on a cluster). The main three are:
- nano super simple editor (with powerful features nonetheless), easy to learn, almost always available by default on Linux machines
- vim a rather difficult editor to use at first because it differs from the standard experience of editing text, but extremely efficient when mastered. Highly customizable, and almost always installed by default on Linux machines. Type
vimtutor
in a terminal for a quick introduction - emacs perhaps easier to learn than vim, endlessly customizable with thousands of plugins (you can read your emails in emacs, or manage a git repository). Can be made to emulate vim's editing style with the
evil
package. Not installed by default on most Linux distributions, but can be found on clusters.
Some code editors can allow remote editing of code, this is the case of emacs and Visual Studio Code. While the latter is now widely popular, I would advise spending some time learning one of the three editors above, as they can be used entirely without a mouse (which can be very useful) or a GUI (which can happen easily if a graphical driver issue arises). All of the "nice" features of VS Code (completion, syntax check, code formatting, etc.) can be configured in emacs or vim (although they likely require more time to set up than VS Code).
Compilers
sudo apt install build-essential
should set you up nicely with the basic tools to write C/C++ code. cmake
is also a staple of C/C++ development. I use scons
to compile Tamaas.
Python
Python is ubiquitous in scientific computing thanks to its very large offer of third-party libraries dedicated to computation (most famously Numpy and Scipy). Python is however notoriously bad with dependency management. I would advise manually installing a specific Python version separate from the system's Python (which can sometimes be very outdated) using a tool like pyenv
, and using virtual environments for each "project". This limits the risks of custom or manually installed packages interacting with the system packages and causing trouble. This includes Jupyter Notebooks.
Git
Git is a version-control software, meant to record versions of code and allow collaborative work on a shared code. Since version-control is among the tenets of working with code, it is highly recommended to read the Pro Git book by Scott Chacon and Ben Straub, especially chapters 2, 3 and 4. The operations described in the Git Basics chapter should become second nature.
Learning Git with the command-line interface instead of a GUI (from VSCode or other) is highly recommended: the CLI is available everywhere and GUIs may have missing features or confusing language.