Unit1 Intro
Unit1 Intro
Chris Paciorek
2024-08-28
Table of contents
1. UNIX command line basics 1
2. Version control 2
3. Parts of a computer 2
5. Editors 3
Summary of some useful editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
(Optional) Basic emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
(Optional) Emacs keystroke sequence shortcuts (aka, key bindings). . . . . . . . . . . . . 4
(Optional) Basic vim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
PDF
1
2. Version control
Version control refers to the process of keeping track of changes to your materials on a computer,
often code files but other files as well. It generally works well with text files because version control
operates based on differences between two versions of a file, and those differences are kept track of on
a line-by-line basis. Version control is a central concept/practice in modern scientific computing.
A very popular and powerful tool for version control is Git. We’ll be using Git extensively for version
control.
Git stores the files for a project in a repository. Here are some basic Git commands you can use to
access the class materials from the command line. There are also graphical interfaces to Git that you
can explore. I’ve heard good things (albeit a few years ago) about GitHub Desktop, available for Mac
and Windows.
1. To clone (i.e., copy) a repository (in this case from GitHub) (berkeley-stat243 is the organi-
zation and fall-2024 is the repository):
git clone https://github.com/berkeley-stat243/fall-2024
2. To update a repository to reflect changes made in a remote copy of the repository:
cd /to/any/directory/within/the/local/repository ## e.g., cd fall-2024
git pull
More information is available in the Computing Skills Workshop as well as this tutorial on the basics of
using Git, as well as lots of information/tutorials online. We’ll see a lot more about Git in Section/Lab
sessions, where you’ll learn to set up a repository, make changes to repositories and work with local
and remote versons of the repository. In particular, you’ll have a chance to work through the tutorial
and practice with Git in the first section/lab (September 6). During the course, you’ll make use of
Git for submitting problem sets and for doing the final project. You should practice using it more
generally while preparing your problem set solutions, and you’ll need to use it extensively for the final
group project.
3. Parts of a computer
We won’t spend a lot of time thinking about computer hardware, but we do need to know some of
the basics that relate to using a computer and programming effectively. There are many layers of
technical detail one could get into, but the key things for now are to have a basic understanding of
these components of a computer:
• CPU
– cache (limited fast memory easily accessible from the CPU)
• main memory (RAM)
• bus
• disk
Depending on what your code is doing, the slow step in a computation might be:
• doing the actual calculations on the CPU,
• moving data back and forth from (main) memory (RAM) to the CPU, or
2
• reading/writing (I/O) data to/from disk.
Please read this overview from a class at CMU that is similar to this class. Don’t worry about too
much of the details in the “How Programs Run” section - just try to get the main idea.
5. Editors
For scientific computing, we need a text editor, not a word processor, because we’re going to be
operating on code files, plain-text data files, and markup language documents (e.g., Markdown/Quarto)
for which word processing formatting gets in the way. Don’t use Microsoft Word or Google Docs
to edit code files or Markdown/Quarto/R Markdown/LaTeX.
3
• VSCode has a powerful code editor that is customized to work with various languages, and it
has a Quarto extension.
As you get started it’s ok to use a very simple text editor such as Notepad in Windows, but you should
take the time in the next few weeks to try out more powerful editors such as one of those listed above.
It will be well worth your time over the course of your graduate work and then your career.
Be careful in Windows - file suffixes are often hidden.
Sequence Result
Ctrl-x,Ctrl-c Close the file
Ctrl-x,Ctrl-s Save the file
Ctrl-x,Ctrl-w Save with a new name
Ctrl-s Search
ESC Get out of command buffer at bottom of screen
Ctrl-a Go to beginning of line
Ctrl-e Go to end of line
Ctrl-k Delete the rest of the line from cursor forward
Ctrl-space, then move to end of block Highlight a block of text
Ctrl-w Remove the highlighted block, putting it in the kill buffer
Ctrl-y ( after using Ctrl-k or Ctrl-w) Paste from kill buffer (‘y’ is for ‘yank’)
4
basic things in vim.
For example, if you run git commit without the -m flag to add a message, you’ll be put in a vim editor
window by default (you can also modify what editor git uses).
vim has two modes: normal mode, which allows you to carry out various operations (such as navigation,
saving files, moving and deleting lines) and insert mode, which allows you to actually insert text.
To get into insert mode from normal mode, type “i”. To get back to normal mode, press Esc.
When in normal mode, you can type :w to save, :x to save and exit, and :q to exit. To search a
document for a string (e.g., “python docstring”, type /python docstring and return/enter. Type
Esc to get out of the search.