search
HomeBackend DevelopmentPHP TutorialFind bad naming of code in your project_PHP Tutorial
Find bad naming of code in your project_PHP TutorialJul 21, 2016 pm 03:17 PM
superiorDowncodenameandexistdeal withLook forconditionof

Things you often do and think about

Obscure if condition

1) Processing of ||

                                                                                                             

 

While reducing the number of lines of code is a good goal, minimizing the time required to understand the code is an even better goal.

Return value

                                                                                                                                                                                                                                                                                                   Rather than using such an empty name, choose a name that describes the value or purpose of the entity.

              $alias declares that this variable is used to carry aliases - indicating the purpose of this variable. And may help us find defects

A good name should describe the purpose of the variable or the value it carries.

Temporary variable

The $ i here is "my temporary variable", which is specifically used to increase the statistical data automatically and avoid duplication of statistical points. But the most important thing about $i is not the temporary variable. Use charset_index to represent "the subscript of my statistical data", which is more "descriptive".

Loop iterator

I also found bad smell in my js code.

I variable name is very empty, so don't do it.

Names like i, j, iter and it are commonly used as indexes and loop iterators. Although the name is vague, everyone knows that they mean "I am an iterator". - Actually if you use these names to mean something else, it would be confusing. So don't do it.

If you insist on using vague names like i, j, it, then you must have a good reason to convince yourself.

Summary

When we are coding, if we spend a few more seconds to come up with a good name, you will find that our "naming ability" will quickly improve.

I usually think of a Chinese name first. If I really can’t think of a corresponding English name, I will use a translation tool to paste the Chinese name that comes to mind, and then cut out the named variable or function name.

Give me a gift with a nice name I saw recently

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325648.htmlTechArticleThings that are often done and often thought about. Obscure if conditions 1) For the processing of ||, the above code is better than The code below takes longer to understand. Although reducing the number of lines of code is a good goal,...
Statement
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
CS玩家的首选:推荐的电脑配置CS玩家的首选:推荐的电脑配置Jan 02, 2024 pm 04:26 PM

1.处理器在选择电脑配置时,处理器是至关重要的组件之一。对于玩CS这样的游戏来说,处理器的性能直接影响游戏的流畅度和反应速度。推荐选择IntelCorei5或i7系列的处理器,因为它们具有强大的多核处理能力和高频率,可以轻松应对CS的高要求。2.显卡显卡是游戏性能的重要因素之一。对于射击游戏如CS而言,显卡的性能直接影响游戏画面的清晰度和流畅度。建议选择NVIDIAGeForceGTX系列或AMDRadeonRX系列的显卡,它们具备出色的图形处理能力和高帧率输出,能够提供更好的游戏体验3.内存电

五个方便好用的Python自动化脚本五个方便好用的Python自动化脚本Apr 11, 2023 pm 07:31 PM

相比大家都听过自动化生产线、自动化办公等词汇,在没有人工干预的情况下,机器可以自己完成各项任务,这大大提升了工作效率。编程世界里有各种各样的自动化脚本,来完成不同的任务。尤其Python非常适合编写自动化脚本,因为它语法简洁易懂,而且有丰富的第三方工具库。这次我们使用Python来实现几个自动化场景,或许可以用到你的工作中。1、自动化阅读网页新闻这个脚本能够实现从网页中抓取文本,然后自动化语音朗读,当你想听新闻的时候,这是个不错的选择。代码分为两大部分,第一通过爬虫抓取网页文本呢,第二通过阅读工

用Python写了个小工具,再复杂的文件夹,分分钟帮你整理!用Python写了个小工具,再复杂的文件夹,分分钟帮你整理!Apr 11, 2023 pm 08:19 PM

糟透了我承认我不是一个爱整理桌面的人,因为我觉得乱糟糟的桌面,反而容易找到文件。哈哈,可是最近桌面实在是太乱了,自己都看不下去了,几乎占满了整个屏幕。虽然一键整理桌面的软件很多,但是对于其他路径下的文件,我同样需要整理,于是我想到使用Python,完成这个需求。效果展示我一共为将文件分为9个大类,分别是图片、视频、音频、文档、压缩文件、常用格式、程序脚本、可执行程序和字体文件。# 不同文件组成的嵌套字典 file_dict = { '图片': ['jpg','png','gif','webp

命运方舟寻找有烛光闪耀的地方在哪命运方舟寻找有烛光闪耀的地方在哪Mar 20, 2024 pm 05:46 PM

命运方舟新地图新版本的开启也是有着全新声望的任务,除了罗温地图外还有一个日常是在智慧岛的,前置的任务是从贝隆南开启的,很多小伙伴做到“寻找有烛光闪耀的地方”这一环的时候就没有指引的了,也是好奇具体的位置在哪,下面为大家带来该任务的攻略!命运方舟寻找有烛光闪耀的地方任务攻略在智慧岛里面的房间当中,大厅还有个走廊,能够进入到地下室,走进去就可以看到后续任务的位置了,如图:

用 WebAssembly 在浏览器中运行 Python用 WebAssembly 在浏览器中运行 PythonApr 11, 2023 pm 09:43 PM

长期以来,Python 社区一直在讨论如何使 Python 成为网页浏览器中流行的编程语言。然而网络浏览器实际上只支持一种编程语言:JavaScript。随着网络技术的发展,我们已经把越来越多的程序应用在网络上,如游戏、数据科学可视化以及音频和视频编辑软件。这意味着我们已经把繁重的计算带到了网络上——这并不是JavaScript的设计初衷。所有这些挑战提出了对新编程语言的需求,这种语言可以提供快速、可移植、紧凑和安全的代码执行。因此,主要的浏览器供应商致力于实现这个想法,并在2017年向世界推出

一文读懂层次聚类(Python代码)一文读懂层次聚类(Python代码)Apr 11, 2023 pm 09:13 PM

首先要说,聚类属于机器学习的无监督学习,而且也分很多种方法,比如大家熟知的有K-means。层次聚类也是聚类中的一种,也很常用。下面我先简单回顾一下K-means的基本原理,然后慢慢引出层次聚类的定义和分层步骤,这样更有助于大家理解。层次聚类和K-means有什么不同?K-means 工作原理可以简要概述为: 决定簇数(k) 从数据中随机选取 k 个点作为质心 将所有点分配到最近的聚类质心 计算新形成的簇的质心 重复步骤 3 和 4这是一个迭代过程,直到新形成的簇的质心不变,或者达到最大迭代次数

坂本智彦的算法-寻找星期几坂本智彦的算法-寻找星期几Sep 02, 2023 pm 07:09 PM

在本文中,我们将讨论什么是TomohikoSakamoto算法以及如何使用该算法来识别给定日期是一周中的哪一天。有多种算法可以知道星期几,但这种算法是最强大的一种。该算法以尽可能最小的时间和最小的空间复杂度找到该日期出现的月份中的哪一天。问题陈述-我们根据格鲁吉亚历给出一个日期,我们的任务是使用TomohikoSakamoto的算法找出给定日期是一周中的哪一天。示例输入-日期=30,月份=04,年份=2020输出-给定日期是星期一输入-日期=15,月份=03,年份=2012输出-给定日期是星期四

从头开始构建,DeepMind新论文用伪代码详解Transformer从头开始构建,DeepMind新论文用伪代码详解TransformerApr 09, 2023 pm 08:31 PM

2017 年 Transformer 横空出世,由谷歌在论文《Attention is all you need》中引入。这篇论文抛弃了以往深度学习任务里面使用到的 CNN 和 RNN。这一开创性的研究颠覆了以往序列建模和 RNN 划等号的思路,如今被广泛用于 NLP。大热的 GPT、BERT 等都是基于 Transformer 构建的。Transformer 自推出以来,研究者已经提出了许多变体。但大家对 Transformer 的描述似乎都是以口头形式、图形解释等方式介绍该架构。关于 Tra

See all articles

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),