Read C# Code Cleanliness Notes 05_Use Tools to Improve Code and Unit Testing
1. High-quality code
1.1. Performance
-
1.1.1. Only perform the required operations and perform them quickly
-
1.1.2. Will not bring the system to a standstill
1.2. Availability
-
1.2.1. Continuously available at the required performance level
-
1.2.2. Topic1
1.3. Security
-
1.3.1. Validate input correctly
-
1.3.2. Prevent invalid data formats or invalid data out of range
-
1.3.3. Prevent malicious attack code
-
1.3.4. Identity Verification
-
1.3.5. Authentication operation
-
1.3.6. Fault-tolerant
1.4. Scalability
- 1.4.1. Safely handle exponential growth in the number of users without bringing the system to a halt
1.5. Maintainability
-
1.5.1. Ease of fixing defects and adding new features
-
1.5.2. Low coupling and high cohesion
1.6. Accessibility
-
1.6.1. Members with limited abilities can easily modify and use the software according to their own needs
-
1.6.2. High contrast user interface
-
1.6.3. Narration added for dyslexics and blind people
1.7. Deployability
-
1.7.1. For software users
-
1.7.1.1. Independent users
-
1.7.1.2. Remote access users
-
1.7.1.3. LAN users
-
1.7.2. Software should be easy to deploy without any problems
1.8. Extensibility
- 1.8.1. Ease of extension by adding new features
1.9. abbreviated as PASSMADE
2. Code Metrics
2.1. Pay attention to the complexity and maintainability of software
2.2. Maintainability Indicators
-
2.2.1. Important components of application life cycle management
-
2.2.1.1. (Application Lifecycle Management, ALM)
-
2.2.2. The color level of scores 20 and above is green
-
2.2.2.1. Good maintainability
-
2.2.3. The color level of scores from 10 to 19 is yellow
-
2.2.3.1. Medium maintainability
-
2.2.4. The color level of scores less than 10 points is red
-
2.2.4.1. Difficult to maintain
2.3. Cyclomatic Complexity
- 2.3.1. The more paths there are, the more complex the software will be
2.4. Inheritance depth
-
2.4.1. Measurement of the number of mutually inherited classes
-
2.4.2. The ideal inheritance depth is 1
2.5. Type coupling degrees
-
2.5.1. The degree of code coupling of a class determines the level of coupling between classes
-
2.5.2. Interface-based programming
2.6. The impact of object-oriented programming programming paradigm
- 2.6.1. (Object-Oriented Programming, OOP)
2.7. Lines of code
- 2.7.1. Complete statistical number of source code lines (including blank lines)
2.8. Number of lines of executable code
- 2.8.1. Number of operations in executable code
2.9. Comes with Visual Studio
3. Tools
3.1. Use quick actions
- 3.1.1. VS comes with it
3.2. JetBrains dotTrace
3.3. JetBrains ReSharper
3.4. JetBrains dotPeek
- 3.4.1. Free
3.5. JetBrains dotCover
3.6. JetBrains dotMemory
3.7. JetBrains Family Bucket
3.8. Telerik JustDecompile
- 3.8.1. Open source
4. Unit test
4.1. TDD is definitely a necessary choice to improve program capabilities
- 4.1.1. Test-Driven Development
4.2. Behavior-Driven Development (BDD)
- 4.2.1. BDD is a software development method evolved from TDD.
4.3. The more critical the software, the more attention you need to pay attention to the use of unit testing technologies (such as TDD and BDD)
4.4. During the code development stage, programmers should always test their own code
4.5. Only when the code is complete and ready to enter the production environment, “program It is correct that programmers should never test their own code”
4.6. Proper planning and design will actually speed up coding, especially when maintenance and expansion are considered. Next
-
4.6.1. Everything will be successful if it is forewarned, and it will be ruined if it is not forewarned.
-
4.6.2. The earlier you consider planning and the more comprehensive the plan, the easier it will be to deal with changes later
4.7. Unit tests should not depend on other tests that run before it
4.8. Unit tests are best completed within milliseconds
5. Software that cannot tolerate defects
5.1. Financial system that handles private and business investments
5.2. Medical Equipment
5.3. Transportation Signaling System for Traffic Management and Navigation System
5.4. Space Flight System
5.5. Weapon System
6. Delete redundancy
6.1. Useless code
- 6.1.1. Redundant code without caller
6.2. “Noise” comment
- 6.2.1. Programmers are bothered by these comments
6.3. Redundant Test
7. Test Tool
7.1. MSTest
7.2. NUnit
7.3. Test Framework
- 7.3.1. NUnit provides a more fine-grained testing method and better performance than MSTest
7.4. Moq
7.5. Rhino Mocks
7.6. Test Stand-in Framework
- 7.6.1. Moq is easier to learn and use than Rhion Mock
7.7. SpecFlow
- 7.7.1. BDD framework