CDH-cookbook

Milestone Lesson 1: Your First Program

^ Main contents

Contents

Summary of Material Covered So Far

At this point, you have seen three lessons which cover the most fundamental concepts about coding in Python, as well as some foundational skills. You have also been presented with the opportunity to complete exercises which teach you to navigate the language and lightly process some data. Here is a list of the topics we have covered so far:

You have learned about the nature of ‘coding’:

We have discussed getting set up before writing code:

We have introduced some features of the Python language that one must know in order to code:

Coding, however, is a skill. Here is a checklist of the skills you need to confidently proceed to the next lessons:

Back to table of contents

Why Did I Learn This?

At this stage you may be asking yourself ‘So what? How does declaring a variable or knowing that functions begin with ‘def’ help me actually accomplish my research objectives?’ At this stage many Humanities researchers often feel disconnected from their actual goals and find that they are not concerned so much with the finer points of coding; their primary aim is a research output. At this point many people find themselves tuning out from tutorials and lessons because they feel that the concepts they are learning do not directly apply to what they want to achieve. If you have found yourself giving up programming tutorials after a few lessons, this is likely the issue.

The way to remedy this disconnect is to better understand what the concepts you have learned enable you to achieve right now. Since code is a tool, you have now learned enough of this tool to begin accomplishing something. Let’s break it down more directly:

  1. Understanding the boring details of how to install and load Python modules, how to click through cells in a Jupyter Notebook, or what is a variable, are absolutely fundamental concepts one must have in order to do anything with Python code. What you have learned so far are not arbitrary details but instead are the foundation necessary to achieve results.
  2. You now know that various modules exist in Python’s module collection which can help you navigate data more effectively. You also know that all Humanities research involves data, even if you are working only with straightforward texts and the concepts those texts contain. But even more importantly, you have been introduced to code repositories, where researchers in Digital Humanities publish their innovative code and methods. It is highly likely that someone out there has written code that you could begin using today which directly impacts your research, and you now know how to look for it and can begin to read some of it.

However, nothing is as powerful as a concrete application. In fact, learning these three things:

enables you to do something very powerful. At the heart of almost any Humanities research involving code is reading and analysing multiple files. If you were doing this manually, what is the process if you have 30 texts to study? You would open the file, perform the analysis, record your notes somewhere, and close the file. You would repeat this 30 times. It would probably take you quite a while.

This, however, is actually a loop! You are iterating through your files and performing the same (or similar) things for each file. This can be translated into code, and then achieved at a much faster rate than if you were doing it by hand. For example, say you have 30 essays, and you want to find data in each essay and copy-paste that data into a spreadsheet. You have now learned the skills to write a loop of code that will do this:

  1. Open a file.
  2. Find the specific data.
  3. Copy that data.
  4. Paste that data into a spreadsheet.
  5. Close the file.
  6. Repeat for each of your 30 essays.

This is, essentially, a computer program, from start to finish. It automates a task that would perhaps waste time if attempted manually. This convenience puts you ahead of many others who opt to do this the hard way by hand.

The homework for this lesson is to follow a tutorial which helps you put your newfound skills together to write this program. You are encouraged to engage with it because it will help you understand how impactful a few simple coding concepts can be for your research.

In short, almost nothing one learns about coding is actually disconnected from real-world objectives, but it is easy to get lost in the details and lose sight of the bigger picture. Reminding yourself that there are concrete applications for everything you learn about code is the way to help keep your perspective and keep up your motivation to learn.

Back to table of contents

Should I Continue?

The previous three lessons covered the fundamentals of coding in Python. There are two points to consider before going forward. First, what are your objectives? If you simply need to slightly manipulate files and nothing more, it is likely that completing the homework tutorial for this lesson is sufficient for you to have an arsenal of necessary tools to carry forward. Your learning is by no means complete, but it can be directed by practical experience. However, if you want to do more complex things with your research, such as carry out different kinds of analyses, produce images and charts, link to databases or scrape internet data, or more – then you should continue to the end of this course.

Second, are you actually ready? The next lessons are more complex in concept and application. Check the list at the beginning of this lesson and ask yourself if you are confident with each of these items. Then, work through the homework tutorial and build your first program using a loop to iterate through some files on your computer. If you can build your first program with that tutorial, then you are ready to continue to the next few lessons.

Written by Estara Arrant, 2025-04-16
Licence: CC BY-SA 4.0

< Previous lesson | Next lesson >