Skip to content

Latest commit

 

History

History
115 lines (83 loc) · 5.4 KB

File metadata and controls

115 lines (83 loc) · 5.4 KB

Clean Code

Overview

Clean code is code that is easy to read, easy to understand, and easy to change. It minimizes cognitive overhead for future readers — including your future self — and lays the groundwork for long-term maintainability, collaboration, and system resilience.

Writing clean code is a core discipline in professional software engineering. It complements testing, architecture, and refactoring by ensuring that every line of code expresses intent clearly and avoids hidden complexity.


Status: 🟢 Mandatory

Who should learn this?
✅ Every developer — regardless of tech stack
✅ Especially important in collaborative, long-lived projects
✅ Core to code review culture, onboarding, and maintainability

Learning Objectives

  • Understand the principles of clean code and code smell detection
  • Improve naming, structure, and formatting for clarity
  • Reduce duplication and complexity through composition and abstraction
  • Write expressive functions, modules, and classes
  • Follow idioms and conventions in your chosen language(s)
  • Prepare code for easy testing, refactoring, and scaling

Key Concepts

  • Naming – Use meaningful, unambiguous names for variables, functions, and classes
  • Functions – Keep them small, do one thing, use clear parameters
  • Comments – Prefer self-documenting code over inline explanations
  • Code Smells – Detect signs of poor structure (e.g., long methods, magic numbers, deep nesting)
  • DRY Principle – Don’t repeat yourself
  • SOLID Principles – Foundation of OOP design cleanliness
  • Formatting & Style – Consistent indentation, spacing, structure
  • Cohesion and Coupling – Write focused modules with minimal interdependencies
  • Defensive Coding – Avoid nulls, unclear return types, silent failures

Study Materials

Books

Title Author Description
Clean Code Robert C. Martin The seminal book on readable, maintainable code
The Pragmatic Programmer Andrew Hunt & David Thomas Philosophy and patterns for practical development
Code That Fits in Your Head Mark Seemann Heuristics for writing code others can quickly understand
Refactoring Martin Fowler Complements clean code by showing how to improve messy code incrementally
Clean Architecture Robert C. Martin Goes beyond code to cover system-level cleanliness and boundaries

Online Courses / Resources

Course or Series Provider Description
Clean Code – Udemy Udemy Practical techniques for writing readable, maintainable, and expressive code
Clean Coding and Refactoring Code with Mosh Pragmatic course focusing on refactoring legacy code using clean coding principles
Clean Code Basics: How to Write Maintainable Code Coursera Intro to clean coding practices: naming, functions, comments, and structure
Writing Clean Code: 20 Code Smells & How to Avoid Them Coursera (Packt) Detect and avoid common code smells using modern design principles
Clean Code: The Next Chapter My Mooc / Victor Rentea Advanced talk on clean code habits and evolution from a software craftsman
Clean Code – FreeCodeCamp YouTube Long-form free workshop introducing clean coding through real JavaScript examples
Clean Code – The Odin Project The Odin Project Beginner-friendly introduction to clean code for web developers
Clean Code Tutorial Scrimba Interactive, hands-on clean code tutorial using small JavaScript projects
Clean Code Principles with Hands-on for Java and Python Udemy Language-agnostic best practices implemented in both Java and Python
Clean Code Series Uncle Bob (Paid) Video series by Robert C. Martin (author of Clean Code) at CleanCoders.com
The Pragmatic Engineer Gergely Orosz Industry-focused blog covering clean code habits, engineering management, and real-world tradeoffs

Applications in Algorithmic Trading

Concept Example
Function clarity Strategy logic is easier to test, audit, and explain
Naming Improves interpretability when reading complex financial pipelines
Small modules Enables plug-and-play architecture for signal, risk, and execution logic
Testability Clean code naturally integrates with testing frameworks for high confidence
Refactorability Simplifies adapting strategies to new markets, APIs, or risk models

Hands-On Practice

  • Rewrite a past script with clearer names, smaller functions, and comments removed
  • Refactor a function with 5+ parameters into a config object
  • Identify code smells in a small repo (e.g., long method, shotgun surgery, feature envy)
  • Perform a peer review on code using a "clean code" checklist
  • Rewrite a CLI tool using principles from Clean Code and SOLID

Assessment

  • Complete a Clean Code checklist for one of your own projects
  • Refactor a messy open-source function using clean code principles
  • Follow a code style guide (e.g., PEP8, Google Style Guide) and apply formatting tools
  • Explain the intent of any function/module in your codebase in one sentence

Next Steps

After clean code, move into: