Home Backend Development PHP Tutorial 在项目中寻找代码的坏命名_PHP

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

Jun 01, 2016 pm 12:10 PM
name

常做的和常想的事情

晦涩的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)

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.

What mistakes should be avoided in golang function naming? What mistakes should be avoided in golang function naming? Apr 22, 2024 pm 09:18 PM

Go function naming errors and countermeasures: avoid empty names and use descriptive names. Avoid lengthy names and use abbreviations or concise terms. Use lowercase letters to name functions for consistency. Avoid using underscores to keep your code clear. Make sure the name is consistent with the function and accurately reflects the function's functionality.

All-caps nomenclature for C++ function naming All-caps nomenclature for C++ function naming Apr 24, 2024 pm 03:06 PM

C++ all-caps nomenclature is a convention for naming functions in which all uppercase letters are used for function names. It is usually used for macro definitions and inline functions to avoid name confusion. grammar:(){...}. For example: inlineintADD_NUMBERS(inta,intb){}, this function calculates the sum of two numbers.

Step-by-step guide for creating folders on Realme mobile phone Step-by-step guide for creating folders on Realme mobile phone Mar 23, 2024 pm 03:51 PM

Step-by-Step Guide to Creating Folders on Realme Mobile Phones In our daily lives, we use our phones to store a variety of files, including photos, videos, documents, and more. However, as time goes by, the number of files on your phone may increase, causing insufficient memory on your phone or making it difficult to manage files. In order to better organize files and improve the efficiency of mobile phone use, the establishment of mobile phone folders has become particularly important. Realme Mobile is a popular smartphone brand with a powerful system and diverse features. Creating folders on Realme phones can help users better organize files

Why is the Go language called Go? Why is the Go language called Go? Mar 08, 2024 am 10:21 AM

Title: Why is the Go language called Go? The Go language (also known as Golang) is a programming language developed by Google. Since its first release in 2009, its popularity has continued to grow and it is widely used in a variety of fields, including network programming, cloud computing, big data processing wait. However, many people are curious about why the word "Go" was chosen as the name of the Go language. In this article, we will explore the reason why the Go language is named "Go". First of all, the Go language was named after 200

Why is the Go language named Go? Why is the Go language named Go? Mar 07, 2024 am 10:45 AM

Go language, also known as Golang, is a programming language developed by Google. Its design goals are efficiency, readability, and simplicity. Go language has been widely used in cloud computing, big data processing, network programming and other fields. However, for many people, a question about the Go language is: why did you choose to name this language "Go"? The origins of the Go language can be traced back to 2007, when three Google engineers Robert Griesemer, Rob Pike and Ken

Choosing between abbreviations and full names in C++ function naming Choosing between abbreviations and full names in C++ function naming May 04, 2024 am 09:33 AM

When naming C++ functions, it is recommended to use the full name for clarity, readability, and searchability. The abbreviation for ただし and では is used in the following situations: できます. Abbreviations are well-known for long function names. Code libraries use a uniform abbreviation convention.

C++ function best practices: How to define meaningful function names? C++ function best practices: How to define meaningful function names? May 02, 2024 am 09:36 AM

In order to ensure the readability and maintainability of C++ code, it is important to define meaningful function names. Specific guidelines include: Use verbs and nouns to describe function purpose, such as "GetAverage" or "UpdateUserInfo". Keep names short but descriptive and avoid long or ambiguous names. Use camelCase nomenclature, using capital letters to indicate word boundaries. Avoid abbreviations or technical terms, keep naming consistent, and isolate function names to prevent conflicts.

See all articles