当前位置:网站首页>Declare war on uncivilized code II
Declare war on uncivilized code II
2022-06-21 13:42:00 【Guo Mahua】
Last one , I introduced the transformation process of a function point Declare war on uncivilized code One , Let me show you some details of this article .
Case study 0 Using bit enumerations to represent permutations

The figure below shows the docking document of a certain platform , The orientation of the house is southeast, Northwest , given 16 A combination scheme .
Actually, it can be used 4 Bit binary to represent , such as : The southeast and northwest correspond to 1111, The southeast corresponds to 1100, The northwest corresponds to 0011, East correspondence 1000. However, the sequence number and orientation of the above figure have no rules to follow , It's completely random .
Case a What is this for ?

Logic is very simple : Analyze... In a set id, Can be converted into guid Is valid id, Add to collection .
I don't make complaints about it , Look directly at the optimized code :
var brokerIds = progress.Result.where(t=> Guid.TryParse(t.UserId, out var _)).select(t=> t.UserId).ToList();Case 2 It's puzzling

The original intention of this code is to use ClaimTypes.NameIdentifier obtain BrokerId , If you don't succeed, use "sub" To get , But why should it be foreach Well , In addition to increasing the difficulty of understanding , It doesn't work .
Case three Super long constructor

You can see that the constructor is written in nearly 100 lines , The part I circled is the processing of parameters , For example, house type : 1-1-1-1 It should be divided into one room, one living room, one kitchen and one bathroom .
This code has no maintainability whatsoever ! You must always pay attention to the order of parameters when modifying ! Like caring for a baby .
It should be transformed , For example, the logic of parameter processing is extracted into methods , Initialize the object in the form of a call chain .
public SecondHouse SetFloor(string floor)
{
if (!string.IsNullOrWhiteSpace(floor))
{
try
{
var array = floor.Split('/');
this.floor = Convert.ToInt32(array[0].Trim(' layer '));
this.totalFloor = Convert.ToInt32(array[1].Trim(' layer '));
}
catch (Exception)
{
throw new Push58DomainException(" Wrong floor format ");
}
}
return this;
} 
Case four You can pass any parameter you need !
Some students are very confused about the function definition , A good method signature should be understandable at a glance : What does this function do ? What input is ? What's the result ?
for instance , I have a function that needs to get the user Id And mobile phone number , Then you can directly pass these two parameters .
But some students do not know that it is for object reuse , Or the future expansion , Will directly put User Object is passed as a parameter ,
The function arguments also become (Dto input, User user) Such an ambiguous function .
Originally, you only need two fields , The result was that the user's birthday was given to !
actually , We can integrate the input parameters , Or directly specify the required parameters .
ending
I really want to make a big change in my project , But this thing has done no good , It's too much to do wrong , difficult .
For the time being, roast is here , The more you think about it, the higher your blood pressure , I'll add later .
边栏推荐
- Lamp architecture 5 - MySQL Cluster and master-slave structure
- 2. reference
- 3D slicer import label and view label
- 3000 frame animation illustrating why MySQL needs binlog, redo log and undo log
- Modification method of EKF extended Kalman filter for omnidirectional ground
- 如何使用搜索引擎?
- Tomorrow's interview, I can't sleep in the middle of the night to review the bottom implementation of STL
- Generalized Focal Loss: Learning Qualified and Distributed Bounding Boxes for Dense Object Detection
- 2. data type
- Repair for a while, decisively reconstruct and take responsibility -- talk about CRM distributed cache optimization
猜你喜欢

Kubernetes快速實戰與核心原理剖析

Deep understanding of convolution in convolution neural network

Annual special analysis of China Mobile Banking in 2022

Open source FTP server FileZilla server

Highly available configuration of database (MySQL)

Navigation bar switching, message board, text box losing focus

Are you still using generator to generate crud code of XXX management system? Let's see what I wrote

Hot information of Tami dog: Xiamen property right trading center creates its first time again!

Voltage detection and current detection based on stm32

Automatic operation and maintenance 3 - using playbook in ansible
随机推荐
Blazor webassembly integrates Ocelot gateway to solve cross domain problems
Setting of Seaborn drawing style
Chapter IX Cisco ASA application nat
MySQL constraints (descriptions of various conditions when creating tables)
curl常用参数详解及示例
Customize view to draw line chart (support zoom)
How to guarantee the test coverage
How to read AI summit papers?
MySQL - table operation
Highly available configuration of database (MySQL)
启牛商学院app下载证券开户,是安全的吗?有风险嘛?
5. array
The new plan for national treasures - the exclusive digital collection of the four museums is coming!
C language elementary level (10) type rename typedef
如何使用搜索引擎?
Apache shardingsphere 5.1.2 release | new driving API + cloud native deployment to create a high-performance data gateway
Work content of service governance
Unbounded territory won the title of innovative brand of digital culture industry in 2022
Modification method of EKF extended Kalman filter for omnidirectional ground
服务治理的工作内容