Average: 3.0
Research Faciliation, Dartmouth Libraries
2026-01-13
understand code to verify AI outputs
debug when AI gives you broken code
need practice with computational thinking to break problems down
control your data and methods (unlike black-box AI tools)
preserve AGENCY over your research workflow
Think of AI as an assistant, but YOU are still the researcher who needs to understand and validate the work
Most popular language in research
Massive ecosystem for research: pandas, numpy, scipy, matplotlib, scikit-learn, etc.
numbers <- c(1, 2, 3, 4, 5)
average <- mean(numbers)
print(paste("Average:", average))
public class AverageCalculator {
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
double sum = 0;
for (int number : numbers) {
sum += number;
}
double average = sum / numbers.length;
System.out.println("Average: " + average);
}
}
#include <iostream>
#include <vector>
#include <numeric>
int main() {
std::vector<int> numbers = {1, 2, 3, 4, 5};
double sum = std::accumulate(numbers.begin(), numbers.end(), 0);
double average = sum / numbers.size();
std::cout << "Average: " << average << std::endl;
return 0;
}
const numbers = [1, 2, 3, 4, 5];
const average = numbers.reduce((sum, num) => sum + num, 0) / numbers.length;
console.log(`Average: ${average}`);
| Language | Lines of Code | Complexity |
|---|---|---|
| Python | 3 | ⭐ Simple |
| R | 3 | ⭐ Simple |
| JavaScript | 3 | ⭐ Simple |
| Ruby | 3 | ⭐ Simple |
| Julia | 3 | ⭐ Simple |
| PHP | 5 | ⭐⭐ Moderate |
| Perl | 5 | ⭐⭐ Moderate |
| Rust | 6 | ⭐⭐⭐ Complex |
| Scala | 7 | ⭐⭐⭐ Complex |
| Fortran | 8 | ⭐⭐⭐ Complex |
| C++ | 11 | ⭐⭐⭐⭐ Very Complex |
| Java | 12 | ⭐⭐⭐⭐ Very Complex |
| Go | 13 | ⭐⭐⭐ Complex |
| C | 14 | ⭐⭐⭐⭐ Very Complex |
Strong community support
Free and open source
Cross-platform
Used across disciplines: from digital humanities to computational biology
'python' is not recognized as an internal or external command
ModuleNotFoundError: No module named 'pandas'
Python version mismatch
Permission denied
Go to 01_setup-instructions (qmd, pdf, or html)
Slides below offer “best practices” recommendations for setting up a Python project on your computer. For workshop participants, we will introduce these as we go. For asynchronous learners, you may want to review these on your own before continuing to notebook 01.
One folder – one project
Folder Organization:
my-research-project/
├── data/
│ ├── raw/ # Original, untouched data
│ └── processed/ # Cleaned, transformed data
├── code # this may include Python scripts (.py) and coding notebooks
├── results/
│ ├── figures/ # Plots and visualizations
│ └── tables/ # Output tables/statistics
├── docs/ # Documentation, notes
├── .gitignore # Tell git what NOT to track
├── README.md # Project description and instructions
└── pyproject.toml # Python dependencies (with uv)
Why this structure?
+ Separation of concerns: Raw data stays pristine, processed data is separate
+ Findability: Six months from now, you'll know where everything is
+ Collaboration: Others can navigate your project easily
+ Scalability: Works for small and large projects
Key principles:
+ Keep raw data in data/raw/ and NEVER modify it directly
+ All data processing should be scripted and reproducible
+ Results should be generated by code, not manually created
+ One project = one self-contained folder"
Some common conventions:
Lowercase with underscores: my-script.py or my_script.py
Be descriptive: Names should tell you what the file contains or does
NO SPACES: For file names, you should replace whitespace with hyphens or underscores instead. Spaces cause issues in terminals. For Python code and folders containing Python code, it is recommended to avoid hyphens too as Python has difficulty importing code from folders or files with hyphens or any special characters besides underscores. Using hyphens for data files is perfectly fine.
Avoid special characters with exception of underscore _ whenever possible.
Use number prefixes for sequences: 01_, 02_, 03_ keeps scripts in order
Include dates if relevant: YYYY_MM_DD or YYYYMMDD to format sorts chronologically (you may also use hyphens, i.e. YYYY-MM-DD for data files and other files or folders that DO NOT contain Python code).
Consistent within a project: Pick a style and stick with it
For general file management naming conventions see Harvard’s guide to file naming.
For Python specific naming conventions (for files and folders, but also for the names of variables, functions, classes, etc. see The Pep 8 Style Guide.
Most important document: README.md file. This is where users go to first to learn more about a project.
What goes in a README:
Problem
Project A (from 2022) needs pandas version 1.3
Project B (new project) needs pandas version 2.0
If you just install your Python dependencies to a global environment (meaning they can be accessed anywhere on your personal computer) then your Python setup can only work for one of these packages. For example, if you try to run Project A, but you have pandas 2.0 installed on your computer, then you may receive a dependency conflict error.
A virtual environment is like a separate, isolated workspace for each Python project on your computer.
A virtual environment keeps each project’s packages separate and organized, preventing conflicts and making your code easy to share
Think of it as:
A project-specific toolbox that contains only the tools (packages) you need for that project
A separate room for each project, so things don’t get mixed up
A backpack you pack differently for each trip/project
WITHOUT Virtual Environments:
┌─────────────────────────────┐
│ YOUR COMPUTER │
│ │
│ All Projects → One Big │
│ Messy Pile of Packages 😵 │
│ │
│ (Conflicts! Confusion!) │
└─────────────────────────────┘
WITH Virtual Environments:
┌─────────────────────────────┐
│ YOUR COMPUTER │
│ │
│ Project A → 📦 Its packages │
│ Project B → 📦 Its packages │
│ Project C → 📦 Its packages │
│ │
│ (Clean! Organized! 😊) │
└─────────────────────────────┘
An IDE is your coding workspace. Some examples (Visual Studio Code, Pycharm, Spyder, etc.). Today we are using Visual Studio Code (VSC) because”:
Free and open source
Excellent Python support
Built-in git integration
Integrated terminal
IntelliSense (code completion)
Debugging tools
Works with both .py scripts and Jupyter notebooks
Huge extension ecosystem
Works on Windows, Mac, and Linux