PHP程序写大量注释好吗?
我写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();
回复讨论(解决方案)
存了占点 可以忽略的磁盘外 运行 会被无视的
写代码注释要写关键点,有些明显的程序一看就会懂的,就不需要写的,写的话,反而看起来累赘。
编程中注释是一个非常重要的环节。 当然一眼能看懂的 就跟楼上说的那样。 注释是为了以后方便维护,不会影响运行速度的。
大段的注释不会影响程序的执行效率
注释分为两类
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();
等号两边加个空格吧。
好啊,写了别人看的也清楚,自己也能回想
我觉不需要太过注意,适量就好。就像吃饭一样,吃多了对胃不好,吃少了就别活了。
适量就好!!!
哥们,注释简明扼要就好,打中文也挺累的吧?你里面很多一长段话都可以缩略成几个关键词。
/** * 投票核心处理部分 * 说明:每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();
关键的地方写上注释就可以了哦,不用那么?嗦的
注释不要超过代码就行了,自己给自己看的就看着办吧,要是给别人看的那么就机械点
注释的口气有点像老师在教小学生

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
