[go: nahoru, domu]

Skip to content

cxxyao2/clean-code-course-code

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Clean Code

This repository holds the code examples and snapshots as well as any other resources belonging to our "Clean Code" course.

How To Use

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.

my notes

why refactor the codebase

  • question your old code and refactor it.
  • writing clean code is an iterative process.
  • refactoring today is work you save tomorrow
  • codebase can survive.

name:

  • varaibles, constants, properties
  • functions, methods
  • classes

comments

  • bad: should not be redundant
  • good: legal information, warning, Todo, name cannot be self-explanatory

code formatting

  • improves readability, and transports meaning

functions

  • number and order of parameters matter.
  • keep parameters less, make function powerful!
  • level of abstraction
  • stay DRY

remove nested condition

  • guard: fail, return
  • throw built-in error adding extra info

other improvements

  • global enums: avoid typo and DRY

oop. class

  • private vs protected. For children, we choose protected sometimes

law of demeter: don't depend on the internals of strangers.

other objects which you don't directly know

solid

  • 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 { }

Liskov

objects should be replaceable with instances of their subclasses without altering the behavior. basic class, super class, child class should extend right super class.

csharp and dotnet tips

8 tips for writing clean code:

  • 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

About

Code and attachments for our clean code course (https://acad.link/clean-code)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published