当前位置:网站首页>In a bad mood, I just write code like this
In a bad mood, I just write code like this
2022-06-26 16:21:00 【Embedded Linux,】
stay GitHub There's a project on , It describes the 「 The best garbage code 」 19 key principles of . From variable naming to annotation writing , These guidelines will guide you to write the most brilliant bad code .
In order to keep up with the original GitHub Project consistent style , There is no conversion below . Readers can understand all points of view in the opposite way , This is the perfect way to avoid writing junk code .
Project address :
https://github.com/trekhleb/state-of-the-art-shitcode
Of course , The following 19 garbage code writing guidelines are not comprehensive , If readers find that there are some unbearable bad code habits , You can also express your views .
Article 1 with a : The less you type, the better
If we type less , So the more time you have to think about code logic . As shown below ,「Good」 Indicates an example of following this rule ,Bad An example of not following the rule .

Second : Variable / Function mix naming style
We need to mix naming methods and variables , In this way, we can reflect the diversity of naming .

Article 3 the : Don't write notes
Anyway, the code can understand , Why write notes ? Or say , No one's looking at my code anyway , Why write notes ?

Article 4. : Write notes in your native language
If you break rule three , At least you need to write notes in your native language or other languages . If your native language is English , Then you're violating the rule . Since most programming languages are in English , So why don't you use other languages to comment on ?

Article 5. : Mix different formats as much as possible
Again , For the diversity of the code , We need to mix as many different formats as possible , For example, single or double quotation marks . If they have the same semantics , Then we should mix .

Article 6. : Write the code as one line as much as possible
If a series of parameters and methods are implemented together , So the code has to be written together .

Article 7. : Keep quiet when you find mistakes
When you find something wrong , Others don't need to understand it , So there's no need to print out logs or Traceback.

Article 8. : Global variables are widely used
Use global variables , It's for 「 Globalization 」 An indispensable part .

Article 9. : Build standby variables
In case of a one thousand , We need to create some spare variables , Call them whenever you need them .

Article 10. :Type Use with caution
Generally, do not specify variable type or do type checking frequently , No type is the best type .

Article 11 : Get ready 「Plan B」
You need to prepare some code that you can't run (unreachable code), They can be your 「Plan B」.

Twelfth article : Nested trigonometry
If the code has some nested structure , Or the structure of indenting empty lines , The triangle rule is the most beautiful .

Article 13 : Mixed indent
We need to avoid indenting , Because indenting makes complex code take up more space in the editor . If you have to indent , Then use a mixed indentation strategy . Of course , This strategy Python It doesn't work , Because it determines the structure of the code by shrinking in .

Article 14 : Don't lock dependencies
Every time you install a new library , Update existing dependencies . Why maintain the previous version , We need to keep up-to-date with third-party code bases .

Article 15 : Long function is better than short function
Don't divide the whole logic of the program into code blocks , If IDE Suddenly not , It can't find the necessary files or functions . So write the code in a body function , And no longer maintain additional function imports or code files , So this method is the most stable .
There's no problem with 10000 lines of code in a single file , A thousand lines of code for a single function is no problem .
Article 16 : The code doesn't need to be tested specifically
These tests are often repetitive and meaningless work .
Article 17. : Try to avoid duplicate code
Write the code as you want , Especially in small teams , It is, after all, 「 free 」 Rules .
Article 18 : Building a new project doesn't require README file
In the early stages of the project , We can keep it for a while .
Article 19 : Save unnecessary code
In the process of writing code , A lot of test code is often generated . These codes are also very important information , So you can't delete , At most, it can only be commented out .
END
edit :Jack-Cui
source : Almost Human
The copyright belongs to the original author , If there is any infringement , Please contact to delete .

边栏推荐
- Failed to get convolution algorithm. This is probably because cuDNN failed to initialize
- Oilfield exploration problems
- Detailed explanation of cookies and sessions
- Angel 3.2.0 new version released! Figure the computing power is strengthened again
- Mono 的一些实例方法
- 了解下常见的函数式接口
- The first batch in the industry! Tencent cloud security and privacy computing products based on angel powerfl passed CFCA evaluation
- Least squares system identification class II: recursive least squares
- 【时间复杂度和空间复杂度】
- 数据分析----numpy快速入门
猜你喜欢

11 introduction to CNN

心情不好,我就这样写代码

2 三种建模方式

【从删库到跑路】JDBC 完结篇(一天学完系列!!学完赶紧跑!)

# 补齐短板-开源IM项目OpenIM关于初始化/登录/好友接口文档介绍

手写数字体识别,用保存的模型跑自己的图片

(1) Keras handwritten numeral recognition and recognition of self written numbers

The details of the first pig heart transplantation were fully disclosed: human herpes virus was found in the patient, the weight of the heart doubled after death, and myocardial cell fibrosis

【力扣刷题】单调栈:84. 柱状图中最大的矩形

Anaconda3 installation tensorflow version 2.0 CPU and GPU installation, win10 system
随机推荐
Oilfield exploration problems
Net based on girdview control to delete and edit row data
Kept to implement redis autofailover (redisha)
mha 切换(操作流程建议)
Redis migration (recommended operation process) 1
Ideal path problem
H5 close the current page, including wechat browser (with source code)
最小二乘系统辨识课 中篇:递归最小二乘
Comprehensive analysis of discord security issues
今年高考英语AI得分134,复旦武大校友这项研究有点意思
请指教同花顺软件究竟是什么?网上开户是否安全么?
大话领域驱动设计——表示层及其他
若依微服务特殊字符串被过滤的解决办法
Least squares system identification class II: recursive least squares
Handwritten numeral recognition, run your own picture with the saved model
Pybullet robot simulation environment construction 5 Robot pose visualization
[time complexity and space complexity]
Lifeifei's team applied vit to the robot, increased the maximum speed of planning reasoning by 512 times, and also cued hekaiming's Mae
Keepalived 实现 Redis AutoFailover (RedisHA)
R语言广义线性模型函数GLM、glm函数构建逻辑回归模型(Logistic regression)、分析模型是否过离散(Overdispersion)、使用残差偏差与二项式模型中的剩余自由度的比率评估