02
Start here / Beginner

Programming fundamentals

The core ideas shared by nearly every programming language: data, control flow, functions, scope, errors, files, and program structure.

variablesloopsfunctionsoopfundamentals

01The mental model

A program receives data, transforms it according to rules, and produces an effect or result. Good code makes those transformations explicit, keeps responsibilities small, and handles invalid input instead of assuming every value is correct.

  • Variables name values; types describe what operations make sense on those values.
  • Conditions choose a branch; loops repeat work; functions name reusable behavior.
  • Scope controls where a name is visible; modules organize larger programs.
  • Exceptions or error values represent failure paths that must be handled deliberately.
  • Objects group state with behavior; composition often keeps designs simpler than deep inheritance.

02Small complete example

pythonPython: validation + function + branch
def average(scores):
    if not scores:
        raise ValueError("scores cannot be empty")
    return sum(scores) / len(scores)

scores = [91, 84, 88]
result = average(scores)

if result >= 75:
    print(f"Passed: {result:.2f}")
else:
    print(f"Needs improvement: {result:.2f}")

03What clean code looks like

  • Use names that explain purpose: total_price is better than x.
  • Keep functions focused on one job and give them clear inputs/outputs.
  • Validate at trust boundaries: HTTP requests, files, database input, user forms, network packets.
  • Avoid duplicated rules; centralize important validation and security policy.
  • Write tests for expected behavior and failure behavior.