Programmer’s Toolbox

Just like biologists and chemists have microscopes and beakers, we in computer science have our own set of tools that help create the magic of programming. This document gives an overview of the tools we will be using as part of CSCI 134. They are already installed on the CS lab machines. For a guide on how to install and set these on your own machines, refer to the Mac OS setup guide, Windows OS setup guide.

../../_images/image3.png Python Programming Language

In CSCI 134, we will be using python programming language as it is a beginning friendly language. We will be using version 3.6 or above of python. One of the main benefits of python is that it is an interactive language: in lecture and office hours, we will often open up the python interpreter, or “interactive python” which lets you enter simple python commands as input, and gives you an immediate output. Interactive python is great for testing out small snippets of code, almost like having a “calculator” for your code. Of course, for longer pieces of code, we need to write our program as a script, for which we need a suitable editor.

../../_images/image13.png Atom Editor

Just like microsoft word or google docs are an editor of text, we need an editor tailored for writing computer programs. As CSCI 134 is a beginner programming course, we will use an editor with a GUI (graphical user interface) called Atom. There are of course a dizzying array of choices once you grow more comfortable with programming. (The choice of editor can even become a point of contention among advanced programmers!)

Atom has a simple user interface. When you open it should look something like this:

../../_images/image8.png

You can close all the extra tabs, and navigate to “New file” or “Open” from the File menu on the top right, just like you would with other editors.

../../_images/image9.png

You can create a new file and add a simple python script: print(“Hello World”)

../../_images/image2.png

Once you save this file as hellworld.py (the extension .pytells your computer that this is a python script), perhaps in a new folder called cs134in your home directory. Now you have written your first python program!

How do we actually execute this program (get it to actually print out Hello World to our console)? This leads us to our next tool: the terminal.

../../_images/image1.png ../../_images/image7.png Terminal

We need an interface to communicate with our computer and issue “commands” in text format. Command-line interfaces provide this for us. These are sometimes referred to as a terminalor a shell, or bashetc in unix based operating systems such as Mac or Linux. Inherently Windows has limited support for such shells, and you can work around it by using the “Windows Subsystem for Linux” (WSL) as explained in the Windows setup document.

We will use this terminal (which refers to the terminal application in Macs and Ubuntu shell in WSL) to execute our python programs. Moreover, we will learn simple commands to navigate the files in our computer using this shell.

Once you open the terminal, it looks something like this:

../../_images/image10.png

We now need to navigate to the folder where we stored our helloworld.py file. If you stored it in the home directory in cs134, you can navigate to your cs134 folder by typing cd cs134/ (which is short for change directory to cs134).

../../_images/image11.png

You can “list” all the files in this folder by typing the command ls

../../_images/image12.png

Here it shows that we only have one file “helloworld.py” in our cs134 folder.

Now it is time to execute our first python program: we can do this by typing python3 helloworld.py and pressing Enter/Return.

../../_images/image5.png

Voila! We asked our computer to print the text “Hello World” and it did! Congratulations on writing your first computer program. While this may not feel like much right now, we can use these same tools to do some pretty incredible things.

../../_images/image6.png Git Version Control System

Git is a professional “version control” tool that lets you keep track of your work. In applications like google docs, we don’t worry about losing our work because it automatically “saves” it for us in the background, and maintains old versions of our work if we need to revert to them. Keeping track of previous versions is also important when programming, and we can do that through Git.

We will also use a web-based interface of Git (called Gitlab) which will allow you to store versions of your program on the CS server called evolene securely. This is also how you will submit your lab work: by maintaining an up-to-date version of your program on evolene.

The high-level git typical workflow for lab assignment is explained below. The details of the exact command will be given to you in the lab handout. For each lab assignment, we post “starter code” which is just an outline for the program you will write for that assignment.

  • To start, you type git clone URL, where URL is the url for your starter repository for the lab on evolene.
    This command just creates a local copy of the starter code on your local machine. You will need to enter your cs username and password when you clone a new repository.

  • As you edit and fill in the starter code, it is good practice to periodically git add filename (you should add each file you have edited) and git commit -m 'message' your work . Think of this as saving a snapshot of your work.

  • When you hit a stopping point on the machine you are working on (e.g., your lab section is over), you should git commit -m "message" and finally git push your work to send it to the evolene server. This ensures the most up-to-date copy of your work always lives on evolene and not any particular machine.

  • Whenever you are ready to resume your work (on the same or different machine), you should first git pull your work from evolene to ensure you are starting on the most up-to-date version. Note that if this is the first time you are using this machine for this lab, then you need to start by doing a git clone of your lab repository first.

../../_images/image4.png Jupyter Notebooks

Finally, we will be using Jupyter Notebooks as a teaching tool in the course. Jupyter notebooks allow us to have a rich web-based interface to run interactive python examples. They are also widely used as a professional tool to communicate in fields such as data science, and thus useful to be familiar with.

How to read Jupyter Notebooks. Typing a command in a ‘In[]’ cell in a Jupyter notebook is the same as typing it in an interactive python session. The ‘Out[]’ cell of the notebook gives the resulting output. Thus, Jupyter notebook is essentially an enhanced way to use interactive python: it stores code examples that can be executed live and are rendered in a rich format.

Learn more about installing and using Jupyter Notebooks. You may view the static notebook from class as an htmlfile, but if you would like to run the examples dynamically, see the How To Use Jupyter Notebooks guide.