当前位置:网站首页>Code neatness -- format
Code neatness -- format
2022-06-28 00:13:00 【Hua Weiyun】
Preface
When writing code, you can't just focus on whether the code function is perfect , It should also check whether the format of the main code conforms to the specification , Maybe you think " Make code work " Is the top priority developers should consider , however , If there is no good code format , In the iteration and modification of later versions , The readability of the code will have a far-reaching impact on the subsequent modification behavior
One 、 Vertical format
1、 Read from the top down
When you read the newspaper , You'll want a headline , Tell you the subject of the newspaper , How the first paragraph is the outline of the whole story , But the details are hidden , Then read on , The details show slowly , Until you know when the whole story happened , Location and so on .
Newspapers consist of many articles , Most are short and exquisite , A few are a little long , But few of them occupy a full page , If the newspaper only carries a very long story , No one will read it .
So should our code , From the top down , From left to right .
2、 Conceptual vertical separation
Between defined functions , Should not be close together , Every function should be separated by blank numbers ;
3、 Approach vertically upwards
Closely related code should be close to each other , Member variables leave no spaces
4、 Closely related functions are close to each other
Avoid jumping from one function to another , So keep jumping . One function calls another , Try to ensure that the called function is next to the caller , It is more convenient to read in this way .
5、 Member variables should be declared in the class header
Function variables should be declared at the beginning of the function , If you need to declare in a function , Consider whether the function needs to be split into multiple functions for execution ;
Two 、 Horizontal format
1、 The width of a line of code
Keep lines of code short , Avoid lines of code that exceed your screen , If exceeded , Consider wrapping lines or changing more refined variable names
2、 Horizontal separation and proximity
Add 、 Subtraction 、 Multiplication 、 Assignment compliance (+、-、==、=) The symbol should be followed by a space , Indicates low priority , Multiplication 、 division (*、/) There should be no space between , Indicates high priority , The comma of a function argument should be followed by a space .
3、 Horizontal alignment is not necessary
Don't do that , There is no need to
4、 Code indentation
Even if the code has only one line , You should also write brackets , Line break , Don't save space
5、 Avoid recycling , Judgment statement , Function body is empty
summary
Write the code , Last review code, Check vertical formatting from top to bottom , Check horizontal formatting from left to right边栏推荐
- VMware virtual machine bridging connectivity
- [AI application] detailed parameters of NVIDIA Tesla v100-pcie-32gb
- 十大券商注册账户安全吗,会有风险吗?
- A summer party
- Mysql database tourism management system_ Jsp+mysql tourism management system based on SSM [easy to understand]
- How to solve the problem that the browser developed with CeF3 does not support flash
- Scu| gait switching and target navigation of micro swimming robot through deep reinforcement learning
- Systematic learning + active exploration is the most comfortable way to get started!
- Matlab基本函数 length函数
- 现代编程语言:Rust (铁锈,一文掌握钢铁是怎样生锈的)
猜你喜欢
Sentinel
ASP.NET仓库进销存ERP管理系统源码 ERP小程序源码
Eliminate gaps around El image images
用两个栈实现队列[两次先进后出便是先进先出]
认识微信小程序项目的基本组成结构
Safe, fuel-efficient and environment-friendly camel AGM start stop battery is full of charm
表单form 和 表单元素(input、select、textarea等)
2022 PMP project management examination agile knowledge points (3)
[PCL self study: Segmentation3] PCL based point cloud segmentation: region growth segmentation
Character interception triplets of data warehouse: substrb, substr, substring
随机推荐
Eliminate gaps around El image images
炼金术(3): 怎样做好1个业务流程的接口对接
Detailed explanation of MATLAB axis coordinate axis related settings
Recyclerview implements grouping effects in a variety of ways
[AI application] detailed parameters of NVIDIA geforce RTX 1080ti
How to solve the problem that the browser developed with CeF3 does not support flash
超纲练习题不超纲
【论文阅读|深读】SDNE:Structural Deep Network Embedding
零基础自学SQL课程 | CASE函数
零基础自学SQL课程 | IF函数
炼金术(4): 程序员的心智模型
Using two stacks to implement queues [two first in first out is first in first out]
数仓的字符截取三胞胎:substrb、substr、substring
解决新版chrome跨域问题:cookie丢失以及samesite属性问题「建议收藏」
吴恩达《机器学习》课程总结(14)_降维
Validaterequest= "false" is a "suggestion collection" for what
SQL报了一个不常见的错误,让新来的实习生懵了
Golang uses Mongo driver operation - query (Advanced)
SCU|通过深度强化学习进行微型游泳机器人的步态切换和目标导航
Sell notes | brief introduction to video text pre training