Skip to main content

4. The Build → Improve → Secure Cycle

Every software project evolves through three stages:

  1. Build – Get it working.
  2. Improve – Make it efficient and maintainable.
  3. Secure – Fortify it against real-world misuse.

Example: Evolving a Simple Reader

# 4. Build
def read_file(path):
return open(path).read()

# 4. Improve
def read_file_clean(path):
with open(path, "r", encoding="utf-8") as f:
return f.read()

# 4. Secure
import os
def read_file_secure(path):
if not os.path.exists(path):
raise FileNotFoundError("Missing file!")
if ".." in path or path.startswith("/"):
raise ValueError("Invalid path.")
with open(path, "r", encoding="utf-8") as f:
return f.read()

Lesson: The final step isn’t just polish — it’s protection.