I write PHP code has a lot of comments, will there be anything to PHP performance has a bad impact ah?
Comments are much more, there is more time than the code itself. Are there any drawbacks?
Such as:
This is the core of the voting function area, as long as the user does not vote today can vote//vote success: 1. This voting table corresponds to the line record to increase one vote 2. The Voting record table increases the user's voting record to prevent him from voting again today. $voteid =$_get["Voteid"];//get the ID, but we do not directly add a ticket to this ID. We have to look first, whether this IP has been voted today. With the IP blacklist feature, we should first verify that the user has entered our blacklist, if the blacklist, the back of all do not have to go. We get this friend's IP first. $nowip =$_server["REMOTE_ADDR"]; $today =date ("YMD");//Then go to our IP record table query today whether this IP has a record $where= "ip= ' $nowip ' and votedate= ' $ Today ' ";///below we check the record table to see if there is any related record $record=new (); $res = $record->fetchall ($where)->toarray (); if (Count ($res >) {$this->view->res= "you have voted today"; $this->render ("res");} else{//if entered here, that the IP can be voted, we first increase his IP information, and then add a number of votes $recordarr=array ("IP" + $nowip, "votedate" and "=" = $today, "Voteid" = > $voteid);//Add a record if added successfully returns the ID value of the added success $insertres= $record->insert ($recordarr); if ($insertres) {//If it comes in, the description adds the record successfully , then we directly increase the user vote of the corresponding vote, below we also operate vote table $vote=new vote ();
Reply to discussion (solution)
An out-of-disk operation with a negligible footprint can be ignored.
Write code comments to write the key points, some obvious procedures can be understood at a glance, do not need to write, write, but seemingly cumbersome.
Annotation in programming is a very important part. Of course, one can read the same as the upstairs said. Note is for easy maintenance later, without affecting the speed of operation.
Large-segment annotations do not affect program execution efficiency
Comments fall into two categories
1. Workflow description, description of "What to Do"
2, the algorithm implementation description, explains "How to do"
Usually the workflow description should be placed at the beginning of the program file
Algorithm implementation description appears with code critical
Usually code block should not be too large, with no more than three visual span is advisable (within hundred lines, the editor in the flip screen two or three times)
Excessive row-to-row annotations will inevitably affect the reader's understanding of the algorithm (see back to the front)
The annotation language of the main is very interesting, but feel a bit wordy, personally think it is more concise as well, ' we ' both words too much?
Note Many is a good thing, but obviously the LZ's comments are not many, but. The statement should be simple and concise:)
PHP comments to not so-called, HTML comments are accounted for the traffic, although it seems very small ~
The code comment Amount between 20%-30% is advisable, do not use the sentimental color text.
Core functions, no votes can be voted//voted successfully: 1. This voting table corresponds to the line record to increase one vote 2. The Voting record table increases the user's voting record, and the number of votes cannot be greater than 1. $voteid =$_get["Voteid"];//obtains the ID, detects whether it has cast the ticket $nowip =$_server["REMOTE_ADDR"]; $today =date ("YMD"); Is there a record $where= "ip= ' $nowip ' and votedate= ' $today '"; $record =new record (); $res = $record->fetchall ($where), ToArray (); if (count ($res) >) {$this->view->res= "you have voted today"; $this->render ("res");} else{//can vote $recordarr=array ("IP" = $nowip, "votedate" and "* * * * $today," Voteid "and $voteid); Add a record if added successfully returns the added successful ID value $insertres= $record->insert ($recordarr), if ($insertres) {//Increase the user vote for the corresponding ticket, Operation vote table $vote= New Vote ();
Add a space on both sides of the equals sign.
Well, it's clear what other people are looking at, and they can think back.
I don't think I need to pay too much attention, just the right amount. Just like eating, eating more is bad for your stomach, eat less and don't live.
The right amount is good!!!
Man, the note is concise, and playing Chinese is very tired, right? A lot of words in you can be shortened into several keywords.
/** * Voting Core Processing Section * Description: A daily limit of one vote per IP user. * Process: Voting, determine if the IP is on the blacklist, "yes" interrupt and prompt information, whether the IP polling today, "yes" prompt message; "No" record IP voting information, record voting content */$voteid =$_get["Voteid"] ;//ip$nowip=$_server["REMOTE_ADDR"]; $today =date ("YMD");//Check whether IP today votes $where= "ip= ' $nowip ' and votedate= ' $today '"; $ Record=new Record (); $res = $record->fetchall ($where)->toarray (); if (count ($res) >) {$this->view-> Res= "You have voted today"; $this->render ("res");} else{//Record has been voted Ip$recordarr=array ("IP" = $nowip, "Votedate" and "Voteid" + $voteid); $insertres = $record- >insert ($recordarr);//Success record IP record voting if ($insertres) {//Operation vote table $vote=new vote ();
The key place to write the comments on it. Oh, no.
Note Do not exceed the code on the line, you see for yourself to do it, if you give others to see the mechanical point
The tone of the note is a bit like a teacher teaching pupils