Home php教程 php手册 在项目中寻找代码的坏命名

在项目中寻找代码的坏命名

Jun 13, 2016 am 11:59 AM
superior Down code name and exist deal with Look for condition of

常做的和常想的事情

晦涩的if条件

1)对于||的处理

                                上面的代码要比下面的代码理解起来花更多的时间

 尽管减少代码行数是一个好目标,但把理解代码所需的时间最小化是一个更好的目标。

 

返回值

                                   上面的"$ret"是“我想不出名字“的托词。与其使用这样空洞的名字,不如挑一个能描述这个实体的值或者目的的名字。

                                     $alias声明了这个变量是用来承载别名的——标明了这个变量的目的。并且可能帮我们找到缺陷

好的名字应当描述变量的目的或者它所承载的值。

临时变量

                                  这里的$i是“我的临时变量",专门用来让统计数据自动增加,避免统计点的重复。但是对这个$i来讲最重要的并不是临时变量。用charset_index表示“我的统计数据的下标”,更具“描述性”。

循环迭代器

我在我的js代码中也发现了坏味道。

                                 i变量名字很空泛,所以不要这么做。

像i,j,iter和it等名字常用做索引和循环迭代器。尽管名字很空泛,但是大家都知道它们的意思是“我是一个迭代器“。——实际上你用这些名字来表示其他含义,那会很混乱。所以不要这么做。

如果你非要用i,j,it这样空泛的名字,那么你要有个好的理由说服自己。

总结

  我们在编码的过程中,多花几秒钟想出一个好名字,你会发现我们的“命名能力“很快提升上去。

  我一般是先想中文名字,如果实在想不出对应的英文名字,我就会用翻译工具把想到的中文贴上去,然后进行裁剪命名变量或者函数名称。

赠送一张最近看到的不错的命名

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The operation process of WIN10 service host occupying too much CPU The operation process of WIN10 service host occupying too much CPU Mar 27, 2024 pm 02:41 PM

1. First, we right-click the blank space of the taskbar and select the [Task Manager] option, or right-click the start logo, and then select the [Task Manager] option. 2. In the opened Task Manager interface, we click the [Services] tab on the far right. 3. In the opened [Service] tab, click the [Open Service] option below. 4. In the [Services] window that opens, right-click the [InternetConnectionSharing(ICS)] service, and then select the [Properties] option. 5. In the properties window that opens, change [Open with] to [Disabled], click [Apply] and then click [OK]. 6. Click the start logo, then click the shutdown button, select [Restart], and complete the computer restart.

What to do if the blue screen code 0x0000001 occurs What to do if the blue screen code 0x0000001 occurs Feb 23, 2024 am 08:09 AM

What to do with blue screen code 0x0000001? The blue screen error is a warning mechanism when there is a problem with the computer system or hardware. Code 0x0000001 usually indicates a hardware or driver failure. When users suddenly encounter a blue screen error while using their computer, they may feel panicked and at a loss. Fortunately, most blue screen errors can be troubleshooted and dealt with with a few simple steps. This article will introduce readers to some methods to solve the blue screen error code 0x0000001. First, when encountering a blue screen error, we can try to restart

Resolve code 0xc000007b error Resolve code 0xc000007b error Feb 18, 2024 pm 07:34 PM

Termination Code 0xc000007b While using your computer, you sometimes encounter various problems and error codes. Among them, the termination code is the most disturbing, especially the termination code 0xc000007b. This code indicates that an application cannot start properly, causing inconvenience to the user. First, let’s understand the meaning of termination code 0xc000007b. This code is a Windows operating system error code that usually occurs when a 32-bit application tries to run on a 64-bit operating system. It means it should

GE universal remote codes program on any device GE universal remote codes program on any device Mar 02, 2024 pm 01:58 PM

If you need to program any device remotely, this article will help you. We will share the top GE universal remote codes for programming any device. What is a GE remote control? GEUniversalRemote is a remote control that can be used to control multiple devices such as smart TVs, LG, Vizio, Sony, Blu-ray, DVD, DVR, Roku, AppleTV, streaming media players and more. GEUniversal remote controls come in various models with different features and functions. GEUniversalRemote can control up to four devices. Top Universal Remote Codes to Program on Any Device GE remotes come with a set of codes that allow them to work with different devices. you may

What does the blue screen code 0x000000d1 represent? What does the blue screen code 0x000000d1 represent? Feb 18, 2024 pm 01:35 PM

What does the 0x000000d1 blue screen code mean? In recent years, with the popularization of computers and the rapid development of the Internet, the stability and security issues of the operating system have become increasingly prominent. A common problem is blue screen errors, code 0x000000d1 is one of them. A blue screen error, or "Blue Screen of Death," is a condition that occurs when a computer experiences a severe system failure. When the system cannot recover from the error, the Windows operating system displays a blue screen with the error code on the screen. These error codes

Considerations for parameter order in C++ function naming Considerations for parameter order in C++ function naming Apr 24, 2024 pm 04:21 PM

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

Learn how to handle special characters and convert single quotes in PHP Learn how to handle special characters and convert single quotes in PHP Mar 27, 2024 pm 12:39 PM

In the process of PHP development, dealing with special characters is a common problem, especially in string processing, special characters are often escaped. Among them, converting special characters into single quotes is a relatively common requirement, because in PHP, single quotes are a common way to wrap strings. In this article, we will explain how to handle special character conversion single quotes in PHP and provide specific code examples. In PHP, special characters include but are not limited to single quotes ('), double quotes ("), backslash (), etc. In strings

Where is the place where the candlelight shines in Destiny Ark? Where is the place where the candlelight shines in Destiny Ark? Mar 20, 2024 pm 05:46 PM

The opening of a new version of the new map of Ark of Destiny also has a new reputation mission. In addition to the Rowan map, there is also a daily mission on the Wisdom Island. The prerequisite mission is started from Belongnan. Many friends have achieved the goal of "finding the right map". There is no guidance for this link "The place where the candlelight shines". I am also curious about the specific location. Here is the guide for this task! The guide for the mission of Destiny Ark to find the place where the candlelight shines is in the room in the Wisdom Island. There is also a corridor in the hall, which can lead to the basement. When you walk in, you can see the location of the subsequent tasks, as shown in the picture:

See all articles