| Home | Classes | Papers | Essays | Short Fiction | About |

Table of Contents

Class Tools

Being a good programmer goes beyond detailed knowledge of programming languages, it also requires familiarity with the tools of the trade. So, before we start learning how to program we're going to learn a bit more about how we can interact with the machine to write and keep track of computer programs.

Editing Programs

Throughout this semester you will primarily be writing into two sorts of files .c and .h files. .c files are files which contain C source code (.h files also contain C source code, but we'll talk what's special about them a bit later). Despite appearances to the contrary, there is nothing special about .c files. .c files only store text. That means all we need to write C code is a text editor.

There are a lot of text editors available out in the wild. I'll name just a few here:

  • nano
  • notepad
  • textedit
  • etc.

Since this is a programming class we're interested in text editors which have been created with editing source code in mind (not just plaintext). Examples include:

  • emacs
  • notepad++
  • sublime
  • vim
  • etc.

These programs provide extra features like parentheses highlighting, syntax highlighting, linting, code completion, and much more. All of these are quality of life improvements to the programmer, they are not essential to the writing of computer programs. In fact, I could write a computer program entirely using the echo program:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example$ echo -e '#include<stdio.h>\nint main(){\n\tprintf("Hello, World!\\n");\n}' > hello.c
josephraskind@josephraskind-ThinkPad-T470:/tmp/example$ cat ./hello.c 
#include<stdio.h>
int main(){
        printf("Hello, World!\n");
}
josephraskind@josephraskind-ThinkPad-T470:/tmp/example$ gcc hello.c -o hello; ./hello
Hello, World!

…but doing so is clearly a bit of a pain and tough to read. I was able to write a fully functional hello world program in Listing 1 because source code is just text. There is nothing special about it from the perspective of the filesystem. For example, the filesystem does not perceive a difference between a .c file containing the entirety of Shakespeare's Hamlet and a .c file containing a program to sort two lists. They are simply files that store text.

Things are a little bit different from the perspective of a text editor. Text editors will color the words in the text with different colors to give the programmer a nice way to visualize the source code. I've set my website's css to mimic the color scheme I use in emacs (the zenburn theme):

#include<stdio.h>
int main(){
        printf("Hello, World!\n");
}

You'll notice that various words and phrases have different colors assigned to them. int is highlighted in a mint green, main in a lime green, #include in a peach, printf in a grey, etc. This is because all of these words refer to different "phrases" in the C language: variable type, function header, macro, and function call, respectively.

Emacs

My text editor of choice is Emacs. What I like about it is that everything in emacs is text. There is never any need for me to touch my mouse or trackpad when I'm inside of emacs. Some people may think that's crazy, but I find it really helps speed up my workflow and adds to my enjoyment when writing code. The first lab for this class goes into greater detail explaining how you can use it too. I suggest that you really do give it a try. It's not for everyone, but I think some students really take to it so it's worth the effort.

The second best thing about emacs is that it is inherently customizable. Not to confuse things too much, but Emacs itself is an interpreter of emacs lisp, a dialect of the lisp programming language. When I do code demos in class you will see me using an emacs that looks different than the default version installed on the remote servers that you might use (or the default installation that you may have performed on your own machine). This is because I have a few different packages installed on my personal copy. You can take a look at the manual page on installing packages here. Here's a list of the packages I like to use on my emacs:

magit
Github integration
marginalia
Adds marginalia to the minibuffer completions
markdown-mode
Full emacs mode for editing markdown files
treemacs
Tree layout file explorer
vertico
Vertical minibuffer command completion

Integrated Development Environments

Integrated Development Environments, or IDEs, are souped-up text editors. They are complex programs dedicated to helping software developers write code for large projects. Here are a few examples of IDEs:

  • Eclipse
  • IDLE
  • VSCode
  • etc.

IDEs go a bit further than the standard text editors. In addition to editing source code and highlighting the containing text, they also provide navigable directory trees, in-program terminals, debugging options, integration with popular tools, object browsers, and more. Compared to basic text editors like notepad or nano, IDEs are heavy duty weaponry.

Even though IDEs provide many more features than the humble text editor, I don't suggest you use any for this course. There is nothing inherently wrong with using an IDE, and I am not preventing anybody from doing so in the class; however, I think that IDEs should only be used after you have become familiar with the basics of the coding process. Far too often I see students make mistakes in their workflow that could have been avoided if they had actually bothered to learn all of the steps the go into the IDE code, run, debug cycle.

Emacs as IDE

Due to the infinite customizability of emacs, it doesn't take too long1 to convert it from a simple text editor to a power IDE. All of the advantages provided by the IDEs listed above can be matched by an intelligent combination of freely available packages.

Keeping Track of Programs

Now that we can write programs, or at least know what kinds of programs we can use to write programs, we're going to need some way of keeping track of the changes we make to our source code. For example, take a look again at listing 2 and assume it is stored in a file named ex.c. Let's say we want to change our message from "Hello, World!" to "Salutations, World!". All I would need to do is change the string constant contained within the printf statement in my text editor:

#include<stdio.h>
int main(){
        printf(Salutations, World!\n");
}

and then save the file. All I need to do now is compile and run my new program…but when I try to do so I get a compilation error!

josephraskind@josephraskind-ThinkPad-T470:/tmp/example$ gcc ex.c -o ex
ex.c: In function ‘main’:
ex.c:3:10: error: ‘Salutations’ undeclared (first use in this function)
    3 |   printf(Salutations, World!\n");
      |          ^~~~~~~~~~~
ex.c:3:10: note: each undeclared identifier is reported only once for each function it appears in
ex.c:3:23: error: ‘World’ undeclared (first use in this function)
    3 |   printf(Salutations, World!\n");
      |                       ^~~~~
ex.c:3:28: error: expected ‘)’ before ‘!’ token
    3 |   printf(Salutations, World!\n");
      |                            ^
      |                            )
ex.c:3:29: error: stray ‘\’ in program
    3 |   printf(Salutations, World!\n");
      |                             ^
ex.c:3:31: warning: missing terminating " character
    3 |   printf(Salutations, World!\n");
      |                               ^
ex.c:3:31: error: missing terminating " character
    3 |   printf(Salutations, World!\n");
      |                               ^~~
ex.c:3:31: error: expected ‘;’ before ‘}’ token
    3 |   printf(Salutations, World!\n");
      |                               ^
      |                               ;
    4 | }
      | ~                              

We'll talk more about compilation in the next lecture. All you need to know is that this prevents our program from being turned into a runnable executable file. In order to see where I went wrong it would be convenient to be able to compare to the previous version of my program, but when I saved the file I overwrote the old data with the new text!

Naive Solution

One way to fix this issue is to save a copy of old versions before you change them:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example$ cp ex.c ex_old.c #Copy before making changes
josephraskind@josephraskind-ThinkPad-T470:/tmp/example$ emacs ex.c #New changes

This works, but think about what happens when I want to make another change, and then another, and another. I would need a different file for each change, or I would have to accept the fact that I'll lose the history of my changes. Both of these are not particularly satisfying solutions. This is where bespoke version control software can helped.

Git

Git is an incredibly powerful version control tool. It is also a bit unintuitive to use, especially for people who are not used to entering commands onto a command line. Despite first appearances, it's not too difficult to wrap your head around (at least for simple use-cases). I highly, highly suggest you flip through the Pro Git book, particularly the introductory chapters. Let's see how we can address the issue we had with our little hello world program.

First, I need to make a git repo:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example$ git init my_repo/
Initialized empty Git repository in /tmp/example/my_repo/.git/  

In Listing 6 I tell git that I want to create a new repo in a directory called my_repo. All git repo files are stored in a hidden directory at the base, or root, of the repo called .git/.

I can check the status of my_repo by moving inside of the directory and using the git status command:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example/$ cd ./my_repo
josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        ex.c

nothing added to commit but untracked files present (use "git add" to track)

You'll notice that ex.c is listed as an untracked file despite the fact that we just put it in the repo. This is because git will only track the files you tell it to!

Next, I need to add my ex.c file to the repository:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git add ex.c 
josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   ex.c

Git is telling me that I have a file called ex.c in my repo, but it hasn't been committed yet. When a file is committed that means a snapshot of that file has been recorded onto the internal git repo data structure stored within the .git/ directory. I can store a snapshot of all my files by using the git commit command:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git commit -m "Adding ex.c to the repo"
[master (root-commit) 40d18f3] Adding ex.c to the repo
 1 file changed, 4 insertions(+)
 create mode 100644 ex.c
josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git status
On branch master
nothing to commit, working tree clean

Now let's try making a change and committing that change:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ emacs ex.c #making change
josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ cat ./ex.c 
#include<stdio.h>
int main(){
  printf(Salutations, World!\n");
}
josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git add ex.c 
josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git commit -m "Updating printf message"
[master f5c21c7] Updating printf message
 1 file changed, 1 insertion(+), 1 deletion(-)

I can check and see what's been changed using the git log command:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git log
commit f5c21c7aa6865f53c8fa8b4e6f678ef7bb74c8f1 (HEAD -> master)
Author: Joe Raskind <[email protected]>
Date:   Wed Jun 10 18:36:59 2026 -0400

    Updating printf message

commit 40d18f3d5de5b48e074a179728affcb48828f5ef
Author: Joe Raskind <[email protected]>
Date:   Wed Jun 10 18:31:27 2026 -0400

    Adding ex.c to the repo

This is nice, but it doesn't really show me what's different about the code itself. I can add a couple flags to my command to get some more information:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git log -p -1
commit f5c21c7aa6865f53c8fa8b4e6f678ef7bb74c8f1 (HEAD -> master)
Author: Joe Raskind <[email protected]>
Date:   Wed Jun 10 18:36:59 2026 -0400

    Updating printf message

diff --git a/ex.c b/ex.c
index e50b95b..862b3be 100644
--- a/ex.c
+++ b/ex.c
@@ -1,4 +1,4 @@
 #include<stdio.h>
 int main(){
-  printf("Hello, World!\n");
+  printf(Salutations, World!\n");
 }

This command tells git to look at the last snapshot, compare it with the current snapshot on the active branch, and generate a diff, or a set of comparisons indicating differences between the two files. Finally, I can rollback my changes with the following command:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git revert HEAD
[master 650e2cb] Revert "Updating printf message"
 1 file changed, 1 insertion(+), 1 deletion(-)
josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ cat ex.c 
#include<stdio.h>
int main(){
  printf("Hello, World!\n");
}  

And just like that I'm back to my old version! We can check the changelog to see this new update reflected:

josephraskind@josephraskind-ThinkPad-T470:/tmp/example/my_repo$ git log
commit 650e2cb7c8ad8bddfe2b5a8facc2deb34efffec2 (HEAD -> master)
Author: Joe Raskind <[email protected]>
Date:   Wed Jun 10 18:49:40 2026 -0400

    Revert "Updating printf message"

    This reverts commit f5c21c7aa6865f53c8fa8b4e6f678ef7bb74c8f1.

commit f5c21c7aa6865f53c8fa8b4e6f678ef7bb74c8f1
Author: Joe Raskind <[email protected]>
Date:   Wed Jun 10 18:36:59 2026 -0400

    Updating printf message

commit 40d18f3d5de5b48e074a179728affcb48828f5ef
Author: Joe Raskind <[email protected]>
Date:   Wed Jun 10 18:31:27 2026 -0400

    Adding ex.c to the repo

This is likely a lot to take in at once. I suggest you try your best to pay attention to the first lab as closely as possible and cross reference with this lecture and the Pro Git book.

If you get stuck or are confused, always reach out to me or the CAs!

Github

Github, unlike git, is not free and open source software. Github is a proprietary, online developer platform owned by Microsoft which uses git as its basis. All of the labs and projects for this class use Github as it is the easiest way for me to track your assignment submissions without you zipping up files and submitting them through Brightspace. The only extra wrinkle that Github adds is the need to pull from and push to a remote repository. The first lab details how exactly that's done.

Exercises

  1. Create a directory called my_first_repo somewhere on the filesystem. Initialize a git repository inside it, create a file called hello.c containing any text you like, add it, and make your first commit with a descriptive message. Run git status after each step and note how the output changes.
  2. Make two separate edits to hello.c, committing after each change with a meaningful commit message. Then run git log to view the history. What information does each commit entry contain?
  3. Use git log -p -1 to inspect the most recent diff. What do the + and - symbols indicate?
  4. Intentionally introduce a typo into hello.c and commit it. Then use git revert HEAD to undo the change. Verify with cat that the file has been restored and with git log that the revert appears as a new commit rather than erasing the old one. Why do you think git records a revert as a new commit rather than deleting the bad one?
  5. Without using a text editor, use echo and a redirect to create a file called note.txt containing a sentence of your choice. Add and commit it to your repository.
  6. What is the difference between git and Github? Could you use git without Github? Could you use Github without git?
  7. What is the purpose of the .git/ directory? What do you think would happen if you deleted it?

Footnotes:

1

Like with anything software related, your mileage may vary…

Contact: [email protected] | rss feed | Compiled with org-mode