Introduction to Code Development
Just getting started with setting up your code workspace? Here are a few common and IDEs used by SBN members. editors
Code Editors
emacs
Emacs is a lot of different things: a Lisp interpreter with text editing, some OS features, a shell (like bash) which modifies or adds on to existing bash shell features. Realistically, though, for a particle physics application, one would simply be using emacs as a text editor. A guide on how to use Emacs as a text editor can be found here.
vim
Vim is a customizable text editor, commonly used by programmers. It runs in the terminal. Its commands can seem a bit unintuitive at first, but after a brief learning curve, people often find Vim flexible. Here is a cheat sheet for Vim commands.
Visual Studio Code
Visual Studio Code, also commonly referred to as VS Code, is a source-code editor with features and support for debugging, syntax highlighting, intelligent code completion, embedded Git, and more. Extensions for VSCode are open source, so there are a ton of useful features and it’s super personalizable. You can also port keymaps from emacs or vim if you’re looking to make the transition! For new coders, VSCode is relatively easy to pick up. It also has lots of themes and icons, so you can make your workspace look very nice.
Particularly useful features for SBN-ers:
- SSH remote editing! Easily SSH into the gpvms and edit any kind of file remotely: LArsoft modules, ROOT macros, Python scripts, Jupyter notebooks, etc.
- Syntax highlighting for everything! There are extensions for syntax highlighting C++, Python, Markdown, LaTeX, FHiCL, json, yaml, etc. You can also customize the syntax highlighting for any file type.
- Git integration!! Commit, push, pull, branch, merge, etc. all from within VS Code. It’s important to learn how to use Git from the command line, but there are lots of features and extensions to help build your intuition and make your life easier.
- Port Forwarding!! If you’re working on a remote machine, you can easily forward ports to your local machine to view plots, Jupyter notebooks, etc.
Super Helpful VSCode extensions
- ROOT File Viewer: open ROOT TTrees without ROOT!!! You can also view and save histograms/plots as images, format plots on-the-fly, and more. Be careful to not open artROOT files with this extension though, as it will try to open the file as a TTree and will crash.
- FHiCL support: Syntax highlighting for .fcl files!
- Github Copilot: AI pair programming assistant. As a student (or someone with an .edu or fnal.gov email), you get a free CoPilot subscription!! Big time saver if you are writing any repetitive code (such as plotting), need simple code suggestions, or are writing documentation. There is also an integrated Copilot chat; you can ask Copilot coding questions or ask it to perform simple tasks. FYI: you should always double check what Copilot suggests, do not rely on it to completely write your code for you.
- GitLens: Git supercharged! Toggle git blame, view git history, view git diffs, and more. Easily view who committed what when, and what changes were made.
- Jupyter: Jupyter notebook support! See the Python page for more details on how to use Python and Jupyer on the gpvms.
- Remote Development: This extension pack includes three extensions: Remote - SSH, Remote - Containers, and Remote - WSL. These extensions enable you to open any folder in a container, on a remote machine, or in the Windows Subsystem for Linux (WSL) and take advantage of VS Code’s full feature set.
Terminals
tmux
tmux is an open-source terminal multiplexer, which allows you to run multiple terminal sessions within a single window. It’s super useful for running multiple processes at once, and you can easily detach and reattach to sessions. You can also split windows and panes, and customize your tmux environment.
If you ever have to run a command that takes longer than a couple minutes, you can run it in a tmux session, detach, and reattach later to check on the process. You can even exit completely out of the Fermilab computer while your command is running in a tmux session then reconnect later.
tmux is natively installed on the gpvms, and you can also install it on your local machine.
The basic structure of how to use it is as follows:
- Either create a new session or attach an existing session:
tmux new -s my_session
ortmux a -t my_session
- Ctrl+B prepares tmux to take in another keyword command. For example, you can create another tmux pane with Ctrl+B -> C.
- Detach a session with Ctrl+B -> D
Here is a very helpful tmux cheat sheet