Does the PHP program write a lot of comments? How to fix it

Source: Internet
Author: User
Tags ticket
Does the PHP program write a lot of comments?
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 functional area of the vote, as long as the user does not vote today can vote 
//Vote success: 1. This voting table corresponds to the record of the row added 2. The Voting record table increases the user's voting record to prevent him from casting again today.

$voteid =$_get["Voteid"];

//Get ID, but we don't add a ticket to this ID directly. 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'll get this friend's IP first.
$nowip =$_server["REMOTE_ADDR"];
$today =date ("YMD");


//Then go to our IP record table to find out if this IP has a record today
$where = "ip= ' $nowip ' and votedate= ' $today '";

//Below we check the record table to see if there are any related records
$record =new record ();
$res = $record->fetchall ($where)->toarray ();
if (count ($res) >) {
$this->view->res= "You have voted today";
$this->render ("res");
}else{

//If the IP is allowed to be voted in here, let's increase his IP information and add one more ticket

$recordarr =array (
"IP" + $nowip,
" Votedate "= $today,
" Voteid "and" = $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 a record, then we directly increase the user vote of the corresponding vote, the following we also operate vote table
$vote =new vote ();

------to solve the idea----------------------
An out-of-disk operation with a negligible footprint can be ignored.
------to solve the idea----------------------
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.
------to solve the idea----------------------
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.
------to solve the idea----------------------
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)
------to solve the idea----------------------
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?
------to solve the idea----------------------
Comments are good, but the LZ's comments are not many but wordy. The statement should be simple and concise:)
------to solve the idea----------------------
PHP comments to not so-called, HTML comments are accounted for the traffic, although it seems very small ~
------to solve the idea----------------------
The code comment Amount between 20%-30% is advisable, do not use the sentimental color text.

Core function, no voting can be cast
Vote succeeded: 1. This voting table corresponds to the record of the row added 2. The Voting record table increases the user's voting record, and the number of votes cannot be greater than 1.

$voteid =$_get["Voteid"];


$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) > 10) {
$this->view->res= "You have voted today";
$this->render ("res");
}else{

Can vote
$recordarr =array (
"IP" = $nowip,
"Votedate" = $today,
"Voteid" = $voteid
);


Adds a record if added successfully returns the ID value of the added success
$insertres = $record->insert ($recordarr);
if ($insertres) {
Increase the user vote for the corresponding vote, Operation vote table
$vote =new vote ();



------to solve the idea----------------------
Add a space on both sides of the equals sign.

------to solve the idea----------------------
Well, it's clear what other people are looking at, and they can think back.
------to solve the idea----------------------
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!!!
------to solve the idea----------------------
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: 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 if IP is voting today
$where = "ip= ' $nowip '? and?votedate= ' $today '";
$record =new? Record ();
$res = $record->fetchall ($where)->toarray ();
if (count ($res)? >?10) {
$this->view->res= "You have voted today";
$this->render ("res");
}else{
?
Record voted IP
$recordarr =array (
"IP" = $nowip,
"Votedate" = $today,
"Voteid" = $voteid
);
$insertres = $record->insert ($recordarr);

Successful record IP records voting content
if ($insertres) {
Operation Vote Table
$vote =new? Vote ();

------to solve the idea----------------------
The key place to write the comments on it oh, don't be so wordy
------to solve the idea----------------------
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.