Skip to content

Repository of real life and fictional code examples in their before and after states. Listing code smells with examples and solutions. Applying refactoring and clean code principles.

Notifications You must be signed in to change notification settings

Rolandisimo/clean-code

Repository files navigation

I created this repository because I feel I'm not a genious coder and rarely have a lightbulb pop over my head after reading pages of dry theory.

Hence, examples is how I learn best. I believe this stands true for many others as well.

This repo is inspired from the books "Refactoring" by Martin Fowler and "Clean Code" by Robert C. Martin.

This is a WIP repo 🦐

Structure 🤔

Folder Content
code-smells Contains .md files containing the description of the smell, bad and good examples, reasons for change, etc
refactoring Folders named after refactoring techniques containing numbered example folders with before, after examples and tests. Usage examples of a particular block of code can be best seen in the test files.
clean-code Contains .md files with examples of applying clean code principles on comments, functions, etc
quotes.txt Contains quotes on programming gathered from different resources

Content 🎉

Here you should be able to find most code smells covered, most refactoring techniques and clean code principles applied in action.

The refactoring techniques have example folders in no particular order. In them you'll have before, after and test files written in Typescript.

Part of the examples are from the books mentioned above while the other part comes from real life code examples.

Contributions ❤️

If you have an example code that you refactored, feel free to contribute to the appropriate refactoring technique used.

Most often there will be more than 1 technique used at the same time, but you need to distinguish the main one and mention others as bonus refactorings. You can also split the refactored code into even smaller parts and contribute to several refactoring techniques at once.

Contribution should follow the same guideline as other examples:

  • Name the folder as the next example number e.g. 2
  • Add before.ts and after.ts files
    • OPTIONAL: Add any additional files you need for the example e.g. types.ts, utils.ts, etc
  • Add a test file with the after example used. This will serve as a usage example and to prove that the refactoring code is functioning as intended
  • Add an entry to the approprate readme e.g. extract-class/readme.md
  • Describe the source of the before and after code, add concrete benefits of this particular code refactoring

Disclaimer 🙉

🕺This is not a definitive guide. Refactoring is always about compromising. Whether you agree with an approach or not depends on a multitude of factors - teams styleguide, how often a particular piece of code is changed, team sizes, roadmaps, etc.

👉Some of the refactoring techniques and examples can be considered as intermediate steps in a bigger refactoring process.

🙌 With this said, this repo is meant to be as a guide and not a judge.

📚For more information on these topics please read the fantastic books mentioned above.

About

Repository of real life and fictional code examples in their before and after states. Listing code smells with examples and solutions. Applying refactoring and clean code principles.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published