This repository holds the code examples and snapshots as well as any other resources belonging to our "Clean Code" course.
This repository comes with many branches - different branches reflect different attachments. In the course, links to the appropriate branches are added directly to the course lectures.
- question your old code and refactor it.
- writing clean code is an iterative process.
- refactoring today is work you save tomorrow
- codebase can survive.
- varaibles, constants, properties
- functions, methods
- classes
- bad: should not be redundant
- good: legal information, warning, Todo, name cannot be self-explanatory
- improves readability, and transports meaning
- number and order of parameters matter.
- keep parameters less, make function powerful!
- level of abstraction
- stay DRY
- guard: fail, return
- throw built-in error adding extra info
- global enums: avoid typo and DRY
- private vs protected. For children, we choose protected sometimes
other objects which you don't directly know
- single responsibility
- o: open for extension .. close for modification
- l: Liskov substitution principle
- interface segregation: small, independent interface
- dependency inversion: depend on abstractions, not concertions open, e,g. class Printer { printPdf, printWebpage} . for adding printing word, extension. interface print{ print();}; class WebPrint implements print { }
objects should be replaceable with instances of their subclasses without altering the behavior. basic class, super class, child class should extend right super class.
- Early return principle
- Merge if statements
- Use LINQ for conciseness
- Bool expression -> Method
- Prefer custom exceptions
- Magic number -> Constant
- Magic string -> Enum
- Use result objects