Can PHP programs write a large number of comments? I write php code with a lot of comments. Will there be any negative impact on the php running performance?
There are a lot of comments, and there is more time than the code itself. Are there any drawbacks?
For example:
// This is the core function area of voting. if this user does not vote today, he can vote successfully: 1. add one vote for the corresponding row record in this voting table. the voting record table adds the user's voting record to prevent him from making another vote today. $ Voteid = $ _ GET ["voteid"]; // GET the id, but we do not directly add a ticket to this id. Let's first check whether this ip address has been voted for today. // With the ip blacklist function, we should first check whether the user has been blacklisted. if the user has been blacklisted, no further steps will be taken. // We get the ip address of this friend first. $ Nowip = $ _ SERVER ["REMOTE_ADDR"]; $ today = date ("Ymd "); // then go to our ip record table to check whether there is a record for this ip address today $ where = "ip = '$ nowip' and votedate = '$ today'"; // we will query the record table below, check whether there are related records $ record = new Record (); $ res = $ record-> fetchAll ($ where)-> toArray (); if (count ($ res)> 10) {$ this-> view-> res = "You have voted today"; $ this-> render ("res");} else {// If you enter here, this indicates that this ip address can be voted. First, we add the ip address information and then add a ticket $ recordarr = array ("ip" => $ nowip, "votedate" => $ today, "voteid" => $ voteid); // add a record, if the record is added successfully, return the value of the added id $ insertres = $ record-> insert ($ recordarr); if ($ insertres) {// if the record is added successfully, then we will directly add the corresponding vote for this user. next we will operate the vote table $ Vote = new vote ();
Reply to discussion (solution)
Non-disk operations that can be ignored when the memory is occupied are ignored.
Writing code comments requires writing key points. some obvious programs can understand it at a glance and do not need to be written. writing seems cumbersome.
Annotations are an important part in programming. Of course, what I can understand at a glance is what I said upstairs. Annotations are used for convenience of future maintenance without affecting the running speed.
Comments of large segments do not affect program execution efficiency.
There are two types of annotations:
1. work flow description: "What to Do"
2. description of algorithm implementation: "How to do it"
Generally, the workflow description should be placed at the beginning of the program file.
The algorithm implementation description appears as the code becomes critical.
Generally, the code block should not be too large, so it should be up to three visual spans (within a hundred lines, two or three screen flip operations in the editor)
Too many inter-line comments will inevitably affect the reader's understanding of the algorithm (if you see it later, you forget it)
The comment language of the author is very interesting, but it feels a bit cool. I personally think it is better to be concise. there are too many words for 'ours.
Many comments are good, but obviously lz comments are not many? Long-winded .. The statement should be simple and concise :)
Php comments are not called. html comments occupy traffic, although very small ~
The amount of comments in the code is between 20% and 30%. do not use emotional text.
// Core function. if you do not have a vote, you can vote. // The vote is successful: 1. add one vote for the corresponding row record in this voting table. the voting record table adds the user's voting record. the number of votes cannot exceed 1. $ Voteid = $ _ GET ["voteid"]; // obtain the ID and check whether it has voted for $ nowip = $ _ SERVER ["REMOTE_ADDR"]; $ today = date ("Ymd"); // check whether a record exists $ 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 {// You can vote $ recordarr = array ("ip" => $ nowip, "votedate" => $ today, "voteid" => $ voteid ); // add a record. if the record is added successfully, the id value $ insertres = $ record-> insert ($ recordarr); if ($ insertres) is returned) {// add the corresponding vote for this user, and operate the vote table $ Vote = new vote ();
Add a space on both sides of the equal sign.
Well, I can think back to what others have read.
I don't think I need to pay too much attention. Just like eating a meal, eating too much is not good for the stomach. if you eat less, don't live.
The right amount is good !!!
Dude, it's easy to make the comments concise and concise. Is it too tired to speak Chinese? You can scale down a long term into several keywords.
/*** Voting core processing part **: One vote is restricted for each IP address user per day. * Process: Vote-> check whether the ip address is in the blacklist-> [yes] interrupt and prompt information-> check whether the IP address is voting today-> [yes] prompt information; [no] records ip voting information and voting content */$ voteid = $ _ GET ["voteid"]; // ip $ nowip = $ _ SERVER ["REMOTE_ADDR"]; $ today = date ("Ymd"); // check whether 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 voting ip $ recordarr = array ("ip" => $ nowip, "votedate" => $ today, "voteid" => $ voteid ); $ insertres = $ record-> insert ($ recordarr); // if ($ insertres) {// operate the vote table $ vote = new Vote ();
The key point is to write comments? Long
Just do not comment more than the code. just look at what you want to see for yourself. if you want to show it to others, it will be mechanical.
It sounds a bit like a teacher is teaching students.