Skip to content

Project that take beginner code through 10 refactoring steps to make it produciton ready

Notifications You must be signed in to change notification settings

CFFinch62/Refactor-Classes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Refactor Classes: Learn Software Engineering Through Games

A collection of comprehensive refactoring tutorials that teach software engineering principles through practical, hands-on game development. Each project takes a working but poorly-structured game and systematically transforms it into a production-ready, object-oriented application.


📚 What is This?

Refactor Classes is an educational programming curriculum that teaches software engineering through progressive refactoring. Instead of building projects from scratch, you'll learn by improving existing code—just like real-world software development.

Why Refactoring?

  • Real-world skill: Most professional programming is maintaining and improving existing code
  • Learn by comparison: See "before" and "after" side-by-side
  • Incremental learning: Each step builds on the previous one
  • Working code always: The game remains playable after every refactoring step
  • Practical application: Learn concepts in context, not in isolation

🎮 Available Projects

1. Chess Refactoring Tutorial

10 steps | Beginner to Advanced | Python + Pygame

Transform a beginner's chess game into a production-ready application with AI.

What You'll Learn:

  • Eliminating anti-patterns (exec(), global state, magic numbers)
  • Object-oriented programming (classes, inheritance, polymorphism)
  • Design patterns (Command, Observer, Factory, Strategy)
  • AI algorithms (Minimax with alpha-beta pruning)
  • Software architecture (Model-View separation, dependency injection)

Technologies: Python 3.10+, Pygame, Turtle Graphics

📁 View Chess Tutorial →


2. Tetris Refactoring Tutorial

11 steps | Beginner to Advanced | Python + Pygame + NumPy

Transform a monolithic Tetris game into a clean, production-ready application.

What You'll Learn:

  • Code cleanup and configuration management
  • Removing global state and dependency injection
  • Game loop architecture (Input → Update → Draw)
  • Object-oriented design (GameState, Piece, Board classes)
  • Renderer abstraction and separation of concerns
  • Input handling and timing systems (DAS/ARR, delta time)
  • Advanced game features (ghost piece, hold system, T-spins, combos)
  • Production polish (menus, sound, particles, AI, high scores)

Technologies: Python 3.10+, Pygame, NumPy

📁 View Tetris Tutorial →


🎯 Who Is This For?

Beginner Programmers

  • Learn what "good code" looks like and why it matters
  • See the difference between working code and professional code
  • Build confidence by improving real projects

Intermediate Developers

  • Master object-oriented programming and design patterns
  • Learn architectural thinking and separation of concerns
  • Practice refactoring techniques used in industry

Computer Science Students

  • See textbook concepts applied to real projects
  • Bridge the gap between theory and practice
  • Build portfolio-worthy projects

Self-Taught Programmers

  • Fill gaps in software engineering fundamentals
  • Learn industry best practices
  • Develop professional coding habits

🚀 Getting Started

Prerequisites

  • Python 3.10 or higher
  • Basic Python knowledge (variables, functions, loops, conditionals)
  • Willingness to learn and experiment

Quick Start

  1. Clone or download this repository

    git clone <repository-url>
    cd "Refactor Classes"
  2. Choose a project (Chess or Tetris)

    cd Chess  # or cd Tetris
  3. Set up virtual environment

    python3 -m venv chess_env  # or tetris_env
    source chess_env/bin/activate  # On Windows: chess_env\Scripts\activate
  4. Install dependencies

    pip install -r requirements.txt
  5. Run any step

    ./play.sh 1   # Run step 1
    ./play.sh 10  # Run step 10 (final version)

📖 Learning Path

Recommended Order

  1. Start with Chess if you:

    • Are newer to programming
    • Want to learn design patterns
    • Are interested in AI algorithms
  2. Start with Tetris if you:

    • Have some OOP experience
    • Want to learn game architecture
    • Are interested in game feel and polish
  3. Do both! The projects complement each other:

    • Chess focuses on AI and complex game logic
    • Tetris focuses on architecture and production polish

How to Use These Tutorials

  1. Read the README for your chosen project
  2. Run Step 0 to see the original code
  3. Read the documentation for Step 1 in refactor_steps_docs/
  4. Try refactoring yourself before looking at the solution
  5. Compare your solution with the provided step file
  6. Run and test the refactored code
  7. Repeat for each step

📂 Repository Structure

Refactor Classes/
├── README.md                 # This file
├── Chess/                    # Chess refactoring tutorial
│   ├── README.md            # Chess-specific documentation
│   ├── requirements.txt     # Python dependencies
│   ├── play.sh              # Launcher script
│   ├── code/                # All 10 step files
│   ├── refactor_steps_docs/ # Step-by-step guides
│   ├── fixes_docs/          # Bug fixes and technical notes
│   └── tests/               # Test suite
└── Tetris/                   # Tetris refactoring tutorial
    ├── README.md            # Tetris-specific documentation
    ├── requirements.txt     # Python dependencies
    ├── play.sh              # Launcher script
    ├── code/                # All 11 step files
    └── refactor_steps_docs/ # Step-by-step guides

🛠️ Technologies Used

  • Python 3.10+: Modern Python with type hints
  • Pygame: 2D game development library
  • NumPy: Numerical computing (Tetris only)
  • Turtle Graphics: Simple graphics (Chess early steps)

🎓 Learning Outcomes

By completing these tutorials, you will master:

Software Engineering Principles

  • ✅ Code quality and readability
  • ✅ DRY (Don't Repeat Yourself)
  • ✅ SOLID principles
  • ✅ Separation of concerns
  • ✅ Dependency injection

Object-Oriented Programming

  • ✅ Classes and objects
  • ✅ Inheritance and polymorphism
  • ✅ Encapsulation and abstraction
  • ✅ Composition over inheritance

Design Patterns

  • ✅ Factory pattern
  • ✅ Strategy pattern
  • ✅ Command pattern
  • ✅ Observer pattern
  • ✅ State machine pattern

Game Development

  • ✅ Game loop architecture
  • ✅ Input handling
  • ✅ Collision detection
  • ✅ Rendering systems
  • ✅ AI implementation
  • ✅ Sound and visual effects

📝 License

This is an educational project. Feel free to use, modify, and learn from the code.


🤝 Contributing

This is a teaching resource. If you find bugs or have suggestions for improvements, please feel free to contribute!


🌟 Acknowledgments

Created as a comprehensive resource for learning software engineering through practical refactoring exercises.

This project wqas insprieed by the 'commonLuke' YouTuibe channel and his attempts at learning to code in Python (https://www.youtube.com/@commonLuke). Both the original Chess and Tetris game code are his. All refactors are my own.

Happy Refactoring! 🚀

About

Project that take beginner code through 10 refactoring steps to make it produciton ready

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published