🧠 2.0 Introduction to Programming for Data Analysis

Welcome to the foundation of programming! This notebook introduces key programming concepts and explains what programming is, why it’s useful, and how Python fits into the world of data analysis—especially in nutrition, food, and sensory sciences.

Objectives: - Understand what programming is and what it is used for. - Learn about different programming paradigms. - Recognise Python’s strengths and why it’s a good fit for this course.

Context: Just as recipes guide a chef, code tells the computer what to do. Let’s explore how! 🦛

🧾 What is Programming?

Programming is the process of writing instructions that a computer can follow to perform tasks.

In nutrition and food science, we use programs to: - Analyse large datasets (e.g., NDNS or lab results) - Perform calculations (e.g., nutrient intake, sensory scores) - Create visualisations (e.g., graphs of dietary intake) - Automate repetitive tasks

Think of a program like a recipe: clear steps to achieve a tasty result. 🍲

🌐 Programming Languages Overview

Just like there are different languages spoken around the world, there are many programming languages. Some common ones include:

  • Python (our focus)
  • R (used in statistics)
  • JavaScript (web development)
  • C/C++ (high-performance computing)
  • SQL (databases)
🧪 Examples of Each

Python

# Python prints a message
print("Hello, hippo!")

R

# R prints a message
print("Hello, hippo!")

JavaScript

// JavaScript prints a message
console.log("Hello, hippo!");

C

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

SQL

-- SQL returns a message
SELECT 'Hello, hippo!' AS message;

🧠 Obscure Programming Languages

Click to explore Ada, Fortran, COBOL, Forth, Brainfuck, Rust and more

Ada

with Ada.Text_IO;
procedure Hello is
begin
   Ada.Text_IO.Put_Line("Hello, hippo!");
end Hello;

Fortran

program hello
  print *, "Hello, hippo!"
end program hello

COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
PROCEDURE DIVISION.
    DISPLAY "Hello, hippo!".
    STOP RUN.

Forth

." Hello, hippo!" CR

Brainfuck

+[----->+++<]>+.---.+++++++..+++.[--->+<]>-----.---[->+++<]>-.--------.+++.

Rust

fn main() {
    println!("Hello, hippo!");
}

Lisp

(print "Hello, hippo!")

Julia

println("Hello, hippo!")

Pascal

program HelloHippo;
begin
  writeln('Hello, hippo!');
end.

Haskell

main = putStrLn "Hello, hippo!"

Prolog

hello :- write('Hello, hippo!'), nl.

Assembly languages

6502

    LDX #$00        ; Load X with 0
    LDY #$00        ; Load Y with 0
    LDA #"H"        ; Load A with ASCII of 'H'
    JSR $FFD2       ; Print character
    LDA #"i"
    JSR $FFD2
    LDA #"!"
    JSR $FFD2
    RTS             ; Return from subroutine

x86

section .data
    msg db 'Hello, hippo!', 0Dh, 0Ah, '$'

section .text
    global _start

_start:
    mov ah, 09h         ; DOS print function
    mov dx, msg         ; Address of message
    int 21h             ; Call DOS interrupt

    mov ah, 4Ch         ; Exit to DOS
    int 21h

🧭 Programming Paradigms

Paradigms are different styles of organising code. The main ones are:

  • Procedural Programming (like a recipe): You write step-by-step instructions.
  • Object-Oriented Programming (like describing ingredients as objects): You define “things” (objects) and actions they can perform.
  • Functional Programming (like maths): You build programs using pure functions.

In this course, we’ll mostly use procedural and a little object-oriented programming.

🐍 Why Python?

Python is widely used in data science because it’s: - Easy to read and write (clean syntax) - Free and open-source - Supported by a huge community - Rich in data analysis tools (e.g., pandas, matplotlib)

Python works great for everything from analysing diet logs to building interactive visualisations or machine learning models!

✅ Summary

In this notebook, we’ve covered: - What programming is - Different types of programming paradigms - Why Python is the language of choice for this course

Next Steps: Head to 2.1_syntax_variables_comments.ipynb to write your first lines of Python code! 🦛