paint-brush
Clean Code for .NET Coding Craftsmanby@thangchung
3,548 reads
3,548 reads

Clean Code for .NET Coding Craftsman

by Thang ChungDecember 18th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

When I started my very first career in software development many years ago, I remembered that I really like to <strong>learn and achieve a lot of skills in software development</strong> via <strong>read notably books by gurus</strong> in this fields as well as read <strong>blogs of them</strong>. Some of the very famous books that I have read are <a href="https://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/073561967" target="_blank"><strong>Code Complete: A Practical Handbook of Software Construction</strong></a>, <a href="https://www.amazon.com/Clean-Coder-Conduct-Professional-Programmers/dp/0137081073" target="_blank"><strong>The Clean Coder: A Code of Conduct for Professional Programmers</strong></a>, <a href="https://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612" target="_blank"><strong>Design Patterns: Elements of Reusable Object-Oriented Software</strong></a>, <a href="https://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672" target="_blank"><strong>Refactoring: Improving the Design of Existing Code</strong></a>, and so on. And I strongly believed that all developers just like me also stepped into the software development industry in this way.

Company Mentioned

Mention Thumbnail
featured image - Clean Code for .NET Coding Craftsman
Thang Chung HackerNoon profile picture

When I started my very first career in software development many years ago, I remembered that I really like to learn and achieve a lot of skills in software development via read notably books by gurus in this fields as well as read blogs of them. Some of the very famous books that I have read are Code Complete: A Practical Handbook of Software Construction, The Clean Coder: A Code of Conduct for Professional Programmers, Design Patterns: Elements of Reusable Object-Oriented Software, Refactoring: Improving the Design of Existing Code, and so on. And I strongly believed that all developers just like me also stepped into the software development industry in this way.

By the time, I wondered how to share what I have learned to the software development communities out there so that it will help them save their efforts for the first stage of their career. Just the last year, I saw there are couples of projects about Clean Code in JavaScript and PHP languages, and now is Ruby language. Then I thought that it would be great if I started the list just like them but customized sections for .NET/.NET Core, and that pushed me to start immediately in that night to create the very first Clean Code for .NET developers list at https://github.com/thangchung/clean-code-dotnet

To make it easy to readers, .NET developers in specially, I start with the different way by other lists (JavaScript, PHP, or Ruby language). I grouped them to the big group with collapsible sub-items which help readers couldn’t be scary when they walk through the big list with huge items accordingly. In case they want to investigate or read in details, they can click on the title of the sub-item to read more. Tony — my colleague — is also eager to join this project so that I told him to help me and he’s a person who proposed this IDEAS as well, and actually it makes the list became short and succinct. Talking a lot of the history of this list, let now go into details to see what inside those group.

Naming

  • Avoiding using a bad name
  • Avoid disinformation name
  • Use pronounceable names
  • Use camel-case notation
  • Use domain name.

Variables

  • Use meaningful and pronounceable variable names
  • Use the same vocabulary for the same type of variable
  • Use searchable names
  • Use explanatory variables
  • Avoid nesting too deeply and return early
  • Avoid Mental Mapping
  • Don’t add unneeded context
  • Use default arguments instead of short circuiting or conditionals
  • Avoid magic string

Functions

  • Function arguments (2 or fewer ideally)
  • Functions should do one thing
  • Function names should say what they do
  • Functions should only be one level of abstraction
  • Don’t use flags as function parameters
  • Avoid Side Effects
  • Don’t write to global functions
  • Don’t use a Singleton pattern
  • Encapsulate conditionals
  • Avoid negative conditionals
  • Avoid conditionals
  • Avoid type-checking
  • Remove dead code

Objects and Data Structures

  • Use getters and setters
  • Make objects have private/protected members

Classes

  • Use method chaining
  • Prefer composition over inheritance

SOLID

  • Single Responsibility Principle (SRP)
  • Open/Closed Principle (OCP)
  • Liskov Substitution Principle (LSP)
  • Interface Segregation Principle (ISP)
  • Dependency Inversion Principle (DIP)
  • Don’t repeat yourself (DRY)

Testing

  • Single concept per test

Concurrency

  • Use Async Await

Error Handling

  • Don’t ignore caught errors
  • Use consistent capitalization
  • Function callers and callees should be close

Formatting

  • Uses .editorconfig file

Comments

  • Only comment things that have business logic complexity
  • Don’t leave commented out code in your codebase
  • Don’t have journal comments
  • Avoid positional markers

Recap

We’re still working on this list, and I believe that it will be longer and accuracy. Our team looks forward to having all of you to involve, contribute and help to make this list more useful for .NET/.NET Core Community.

Again, the clean code list for .NET/.NET Core can be found at https://github.com/thangchung/clean-code-dotnet

Thanks for reading! If you enjoyed this article, be sure to click 👏 symbol below so others will see it.