Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial PHP程序写大量注释好吗?

PHP程序写大量注释好吗?

Jun 23, 2016 pm 01:44 PM

我写php代码有大量注释,会不会有什么对php运行性能有不好的影响啊?
注释多的很,有时间比代码本身还多。有没有什么弊端?


如:

//这个是投票的核心功能区,只要该用户今天没有投票就可以投票//投票成功:1.本投票表对应行记录增加一票 2.投票记录表增加该用户的投票记录,防止他今天再投。$voteid=$_GET["voteid"];//拿到id了,但是我们不是直接就给这个id添加一票。我们要先看看,这个ip今天是否已经投过票了。//有了ip黑名单功能,我们应该在最先核实该用户是否已经进入我们的黑名单了,如果进了黑名单,后面的所有都不用走了。//我们先拿到这个朋友的ip。$nowip=$_SERVER["REMOTE_ADDR"];$today=date("Ymd");//然后去我们ip记录表查询今天这个ip是否有记录$where="ip='$nowip' and votedate='$today'";//下面我们查询记录表,看看有没有相关记录$record=new Record();$res=$record->fetchAll($where)->toArray();if(count($res) > 10){$this->view->res="您今天已经投过票了";$this->render("res");}else{//如果进到这里,说明这个ip是可以投票的,我们先增加他的ip信息,再增加一个票数$recordarr=array("ip"=>$nowip,"votedate"=>$today,"voteid"=>$voteid);//增加一条记录,如果添加成功返回添加成功的id值$insertres=$record->insert($recordarr);if($insertres){//如果进来,说明添加记录成功,那么我们就直接增加该用户投的对应的一票,下面我们又要操作vote表$vote=new Vote();
Copy after login


回复讨论(解决方案)

存了占点 可以忽略的磁盘外 运行 会被无视的

写代码注释要写关键点,有些明显的程序一看就会懂的,就不需要写的,写的话,反而看起来累赘。

编程中注释是一个非常重要的环节。 当然一眼能看懂的 就跟楼上说的那样。 注释是为了以后方便维护,不会影响运行速度的。

大段的注释不会影响程序的执行效率

注释分为两类
1、工作流程描述,说明“做什么”
2、算法实现描述,说明“怎么做”

通常 工作流程描述 宜放在程序文件的开始处
算法实现描述 随代码紧要处出现

通常代码块不宜过大,以不超过三个视觉跨度为宜(百行以内,编辑器中翻屏两三次)
过多的行间注释,势必会影响阅读者对算法的理解(看到后面忘了前面)

撸主的注释语言很有意思,不过感觉有点罗嗦了,个人认为还是简洁些为好,‘我们’俩字也太多了吧

注释多是好事,但显然lz的注释不是多而是?嗦了。。语句要简单扼要才好 :)

php的注释到没所谓,html的注释是占流量的,看上去虽然很微小~

代码注释量在20%-30%之间为宜,不要用带感情色彩的文字。

//核心功能,没有投票的可以投//投票成功:1.本投票表对应行记录增加一票 2.投票记录表增加该用户的投票记录,投票次数不能大于1。 $voteid=$_GET["voteid"];//获得ID,检测其是否投过票 $nowip=$_SERVER["REMOTE_ADDR"];$today=date("Ymd");  //是否存在记录$where="ip='$nowip' and votedate='$today'";$record=new Record();$res=$record->fetchAll($where)->toArray();if(count($res) > 10){$this->view->res="您今天已经投过票了";$this->render("res");}else{ //可以投票$recordarr=array("ip"=>$nowip,"votedate"=>$today,"voteid"=>$voteid);  //增加一条记录,如果添加成功返回添加成功的id值$insertres=$record->insert($recordarr);if($insertres){//增加该用户投的对应的一票,操作vote表$vote=new Vote();
Copy after login


等号两边加个空格吧。

好啊,写了别人看的也清楚,自己也能回想

我觉不需要太过注意,适量就好。就像吃饭一样,吃多了对胃不好,吃少了就别活了。

适量就好!!!

哥们,注释简明扼要就好,打中文也挺累的吧?你里面很多一长段话都可以缩略成几个关键词。

/** * 投票核心处理部分 * 说明:每IP用户每日限制投一票。 * 流程:投票->判断该ip是否在黑名单->【是】中断并提示信息->判断该IP今日是否投票->【是】提示信息;【否】记录ip投票信息,记录投票内容 */$voteid=$_GET["voteid"];//ip$nowip=$_SERVER["REMOTE_ADDR"];$today=date("Ymd");//检查Ip今日是否投票$where="ip='$nowip' and votedate='$today'";$record=new Record();$res=$record->fetchAll($where)->toArray();if(count($res) > 10){$this->view->res="您今天已经投过票了";$this->render("res");}else{ //记录已投票ip$recordarr=array("ip"=>$nowip,"votedate"=>$today,"voteid"=>$voteid);$insertres=$record->insert($recordarr);//成功记录ip则记录投票内容if($insertres){//操作vote表$vote=new Vote();
Copy after login

关键的地方写上注释就可以了哦,不用那么?嗦的

注释不要超过代码就行了,自己给自己看的就看着办吧,要是给别人看的那么就机械点

注释的口气有点像老师在教小学生

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles