当前位置:网站首页>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 .

边栏推荐
- TCP拥塞控制详解 | 1. 概述
- C# 读写文件从用户态切到内核态,到底是个什么流程?
- JS教程之 使用 Electron.JS 构建原生桌面应用程序乒乓游戏
- MHA switching (recommended operation process)
- Quickly get started with federal learning -- the practice of Tencent's self-developed federal learning platform powerfl
- Kept to implement redis autofailover (redisha) 1
- 2 三种建模方式
- [207] several possible causes of Apache crash
- C language reading data
- 5 model saving and loading
猜你喜欢

Pybullet robot simulation environment construction 5 Robot pose visualization

How to implement interface current limiting?

3. Keras version model training

NFT transaction principle analysis (2)

Anaconda3安装tensorflow 2.0版本cpu和gpu安装,Win10系统

Beijing University and Tencent jointly build angel4.0, and the self-developed in-depth learning framework "River map" is integrated into the ecology

Arduino UNO + DS1302简单获取时间并串口打印

TCP拥塞控制详解 | 1. 概述

11 introduction to CNN

长安链交易防重之布谷鸟过滤器
随机推荐
Kept to implement redis autofailover (redisha) 1
[from deleting the database to running] the end of MySQL Foundation (the first step is to run.)
油田勘探问题
100+ data science interview questions and answers Summary - basic knowledge and data analysis
5 model saving and loading
Redis migration (recommended operation process) 1
Solidus Labs欢迎香港前金融创新主管赵嘉丽担任战略顾问
【力扣刷题】单调栈:84. 柱状图中最大的矩形
Handwritten numeral recognition, run your own picture with the saved model
Develop operator based on kubebuilder (for getting started)
Lifeifei's team applied vit to the robot, increased the maximum speed of planning reasoning by 512 times, and also cued hekaiming's Mae
11 cnn简介
R语言plotly可视化:plotly可视化归一化的直方图(historgram)并在直方图中添加密度曲线kde、并在直方图的底部边缘使用geom_rug函数添加边缘轴须图
理想路径问题
Redis 迁移(操作流程建议)
我把它当副业月入3万多,新手月入过万的干货分享!
Scala 基础 (二):变量和数据类型
Mono 的一些实例方法
最小二乘系统辨识课 中篇:递归最小二乘
若依打包如何分离jar包和资源文件?