In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what are the five code comments that web programmers should avoid?" friends who are interested may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor learn what are the five code comments that web programmers should avoid.
1. A programmer who thinks he is very good.
Public class Program {static void Main (string [] args) {string message = "Hello World!"; / 07 Bob Console.WriteLine 24 Bob 2010 Bob Console.WriteLine (message); / 07 Bob Console.WriteLine 24 Bob 2010 Bob}}
The programmer thought he had written a great piece of code, so he felt the need to mark each line of code with his own name. Implementing a version control system (VCS) enables accountability for code changes, but it is not so obvious who is responsible.
two。 An outdated programmer
Public class Program {static void Main (string [] args) {/ * This block of code is no longer needed * because we found out that Y2K was a hoax * and our systems did not roll over to 1ax 1900 * / / DateTime today = DateTime.Today; / / if (today = = new DateTime (1900, 1,1)) / / {/ / today = today.AddYears / / string message = "The date has been fixed for Y2K."; / / Console.WriteLine (message); / /}
If a piece of code is no longer in use (that is, out of date), delete it-don't waste time commenting on the code. In addition, if you need to copy this deleted code, don't forget that there is a version control system, and you can recover the code from earlier versions.
3. Superfluous programmers
Public class Program {static void Main (string [] args) {/ * This is a for loop that prints the * words "I Rule!" To the console screen * 1 million times, each on its own line. It * accomplishes this by starting at 0 and * incrementing by 1. If the value of the * counter equals 1 million the for loop * stops executing.*/ for (int I = 0; I < 1000000; iTunes +) {Console.WriteLine ("I Rule!");}
We all know how basic programming logic works-so you don't have to bother to explain these obvious working principles, although you explain it very happy, it's a waste of time and space.
4. A programmer who loves to tell stories
Public class Program {static void Main (string [] args) {/ * I discussed with Jim from Sales over coffee * at the Starbucks on main street one day and he * told me that Sales Reps receive commission * based upon the following structure. * Friday: 25 * Wednesday: 15 * All Other Days: 5 * Did I mention that I ordered the Caramel Latte with * a double shot of Espresso? * / double price = 5.00; double commissionRate; double commission; if (DateTime.Today.DayOfWeek = = DayOfWeek.Friday) {commissionRate = .25 } else if (DateTime.Today.DayOfWeek = = DayOfWeek.Wednesday) {commissionRate = .15;} else {commissionRate = .05;} commission = price * commissionRate;}}
If you must mention the requirements in the comments, don't mention other people's names. The Jim of the sales department may leave the company, and it is likely that most programmers have no idea who this is. Don't mention irrelevant facts in the notes.
5. Programmers who "do it later"
Public class Program {static void Main (string [] args) {/ / TODO: I need to fix this someday-07 2004 Bob / * I know this error message is hard coded and * I am relying on a Contains function, but * someday I will make this code print a * meaningful error message and exit gracefully. * I just don't have the time right now. * / string message = "An error has occurred"; if (message.Contains ("error")) {throw new Exception (message);}
This type of comment contains all the other types above. This kind of pending comments can be useful if you are in the initial development phase of the project, but if it is the product code in a few years' time-- it will be a problem. If there is anything that needs to be repaired, solve it immediately. Don't put it aside and "do it later."
At this point, I believe you have a deeper understanding of "what are the five code comments that web programmers should avoid?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.