当前位置:网站首页>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 .
边栏推荐
- The new plan for national treasures - the exclusive digital collection of the four museums is coming!
- Application configuration management, basic principle analysis
- Test the interface between app and wechat applet
- 咨询:微证券是什么证券公司,开户安全吗?
- Automatic operation and maintenance 4 - variables and encryption in ansible
- curl常用参数详解及示例
- 如何使用搜索引擎?
- Two common schemes for handling interface idempotence
- ###数据库的高可用配置(mysql)
- SCCM creates a client collection based on the installed app and periodically pushes application updates
猜你喜欢

Sort query results according to the input order of fuzzy query jancode

Web3.js connection to metamask wallet transfer

Unbounded territory won the title of innovative brand of digital culture industry in 2022

MySQL - adding, deleting, querying and modifying tables

How to read AI summit papers?

seaborn绘图风格的设置

CVPR2022 | 上科大x小红书首次提出动作序列验证任务,可应用于体育赛事打分等多场景
![[deeply understand tcapulusdb technology] tmonitor background one click installation](/img/0a/742503e96a9b51735f5fd3f598b9af.png)
[deeply understand tcapulusdb technology] tmonitor background one click installation

Lamp Architecture 3 -- compilation and use of PHP source code

hands-on-data-analysis 第二单元 第四节数据可视化
随机推荐
MySQL - user management
Master the basic usage of SQLite3
Is the micro securities account opening regular and safe? How to open an account?
How to guarantee the test coverage
Explanation of common mesh generation methods in workbench
hands-on-data-analysis 第二单元 第四节数据可视化
Work content of service governance
4. procedure flow structure
map. Values() to copy list and ArrayList
618 Nuggets digital collection? Burberry and other luxury brands fight against metauniverse
MySQL - table operation
Memcached(高性能内存对象缓存)
IMU selection, calibration error analysis, AHRS integrated navigation
哪個期貨平臺 交易更安全放心。求推薦。
C language -- program compilation and linking
MySQL - adding, deleting, querying and modifying tables
Kubernets Rapid Practical fighting and Core Principle Analysis
Must the database primary key be self incremented? What scenarios do not suggest self augmentation?
PHP uses grafika to synthesize pictures and generate poster images
Swift return button