Skip to content

Latest commit

 

History

History
107 lines (77 loc) · 5.82 KB

File metadata and controls

107 lines (77 loc) · 5.82 KB

Refactoring

Overview

Refactoring is the process of improving the structure, readability, and maintainability of code—without changing its external behavior. It's a crucial skill in professional software engineering, enabling developers to clean up code, reduce duplication, simplify logic, and enhance architecture while ensuring existing functionality remains intact.


Status: 🟢 Mandatory

Who should learn this?
✅ Every developer working in a production codebase
✅ Anyone responsible for bug fixing, feature extension, or code review
✅ Strongly recommended for algorithmic trading engineers modifying high-risk systems

Learning Objectives

  • Understand when and why to refactor
  • Use small, safe steps to restructure code while preserving behavior
  • Identify common “code smells” and appropriate refactorings
  • Apply refactoring patterns: extract method, introduce parameter, replace conditional, etc.
  • Utilize IDE support or scripts for safe, automated refactors
  • Prepare code for testability, modularity, or design pattern usage

Key Concepts

  • Code Smells – Indicators of potential issues in code design (e.g., long methods, duplicated code)
  • Behavior Preservation – Ensuring refactoring doesn't alter what the code does
  • Micro-refactors – Small changes that reduce risk (e.g., renaming a variable)
  • Test-Covered Refactoring – Using automated tests to detect regressions
  • Refactoring Catalogs – Collections of common transformations used across languages
  • Continuous Refactoring – Ongoing improvement of code during development

Study Materials

Books

Title Author Description
Refactoring: Improving the Design of Existing Code Martin Fowler The definitive refactoring reference—highly recommended
Refactoring to Patterns Joshua Kerievsky Transition from messy code to common patterns through structured steps
Clean Code Robert C. Martin Guide to writing readable, maintainable code
Working Effectively with Legacy Code Michael Feathers Strategies for refactoring untested, complex, or brittle codebases
The Art of Readable Code Dustin Boswell Techniques to improve code clarity and maintainability

Online Courses / Resources

Course Platform Description
Refactoring Techniques in Java Udemy Core refactoring techniques and their automation
Refactoring Guru Web Visual walkthroughs of refactoring patterns in multiple languages
Martin Fowler’s Refactoring Guide Blog Authoritative articles and catalogs of common refactorings
JetBrains Refactoring Series JetBrains Docs Tool-based refactoring strategies with IntelliJ / PyCharm
Refactoring for Readability Pluralsight Focus on human-centric refactoring for team readability
Dive Into Refactoring Refactoring Guru Interactive course covering 21 code smells and 66 refactoring techniques with examples in Java, C#, and PHP
Clean Coding and Refactoring Code with Mosh Practical course on writing clean, maintainable code and refactoring techniques
Test-Driven Development MOOC University of Helsinki Course on TDD, including refactoring practices and exercises
Advanced Object-Oriented Design MOOC with Pharo Inria Course focusing on object-oriented design principles and refactoring examples

Applications in Algorithmic Trading

Scenario Refactor
Long function with multiple responsibilities Extract method and introduce intermediate abstractions
Strategy logic mixed with data I/O Separate concerns into modules (e.g., data, logic, risk, logging)
Poorly tested signal code Wrap legacy logic in test harness before changing
Repeated validation / logging logic Replace duplication with decorators or utility modules
Unclear naming or magic constants Rename and extract named config parameters for clarity

Hands-On Projects

  • Refactor a function longer than 30 lines using “extract method” and “rename variable”
  • Write tests around a module before performing a structural change
  • Refactor an if/else ladder into a dictionary, polymorphism, or pattern match
  • Apply 5 refactorings from Refactoring Guru to a hobby project
  • Replace a conditional block with the Strategy or State pattern

Assessment

  • Can you identify at least 5 code smells in a codebase?
  • Can you apply 5–10 refactorings without changing behavior?
  • Do you refactor continuously (e.g., rename, extract, restructure) while building features?
  • Can you prepare code for modularity, testing, or architecture improvements?

Next Steps