(naming, plural → singular, variables, functions, and data types)

A variable is just a treasure chest with a label. You stash loot inside and call it by name later.

  • gold = 100 → you’ve got 100 coins in a chest named gold.

A function is like the ship’s cook. You hand him ingredients (arguments), he hands you back a meal (return value).

Data types are categories of treasure:

  • integers → gold coins (countable treasure)
  • strings → wanted posters (names written down)
  • lists → treasure maps bundled together (collections in order)
  • booleans → Jolly Roger flag (up = True, down = False)

Pirate Rule #1: Names mean things

  • Collections = plural (fleets of ships).
  • Items = singular (a single ship).
  • If the name doesn’t tell you what’s inside, you’re cursed. Rename it before the curse spreads.

Example: Variables and Loops

ships = [
    {"name": "Thousand Sunny", "crew_size": 9},
    {"name": "Going Merry", "crew_size": 7}
]

for ship in ships:
    context.log.info(
        "Ship registered",
        extra={"name": ship["name"], "crew_size": ship["crew_size"]}
    )

Example: Functions

def count_crew(ship):
    # ship is the argument (input chest)
    return ship["crew_size"]  # returning the value inside

for ship in ships:
    crew = count_crew(ship)
    context.log.info(
        "Crew counted",
        extra={"name": ship["name"], "crew_size": crew}
    )

Arguments = the ingredients you hand to the cook (the ship).
Return value = the meal he serves back (crew size).


A variable is a labeled container for a value.

  • count = 100 → a box named count that stores the integer 100.

A function is reusable logic. You provide inputs (arguments), and it returns an output (return value).

Data types classify what a variable can hold:

  • integers → whole numbers
  • strings → text values
  • lists → ordered collections
  • booleans → True/False flags

Engineering Rule: Names should mean something

  • Collections = plural (users).
  • Items = singular (user).
  • Optimize for clarity, not brevity. Your future self will thank you.

Example: Variables and Loops

users = [
    {"name": "Alice", "status": "active"},
    {"name": "Bob", "status": "inactive"}
]

for user in users:
    context.log.info(
        "User processed",
        extra={"name": user["name"], "status": user["status"]}
    )

Example: Functions

def is_active(user):
    # user is the argument (input)
    return user["status"] == "active"  # return value is True/False

for user in users:
    active = is_active(user)
    context.log.info(
        "Checked user status",
        extra={"name": user["name"], "active": active}
    )

Arguments = the inputs you hand to the function.
Return value = the result it hands back.