In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you about the ways of program annotation that should be avoided in web development, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Have you ever come across a comment that you think is superfluous when you check the code? The purpose of using comments in code is to improve the readability of the code so that non-original code developers can better understand them.
I identified five categories of comments that annoyed me and five types of programmers who generated them. I hope that after reading this article, you will not fall into the same river as them. As a challenge, you might as well match the programmers who write these 5 types of comments with 5 types of programmers.
1. Proud programmer
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}}
Such programmers think highly of their code that they feel the need to sign their names after each line of code. The application version control system (VCS) is able to know who modified the code, but at first glance the person responsible will not be so eye-catching.
two。 Obsolete 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 1Accord 1900 * / / DateTime today = DateTime.Today; / / if (today = = new DateTime (1900 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 mess up your working code with lines of redundant comments. Also, any time you need to copy this deleted code, you can use the version control system so that you can recover it from the previous version.
3. Obvious type programmer
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 the basic working logic of programming-this is not an introduction to programming! You don't have to waste time explaining how the obvious program works, and while we're glad you're willing to explain what the code does-it's just icing on the cake.
4. Biographical programmer
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 have to mention something necessary in your code, don't mention a person's name. Jim from Sales (Jim) may have left the company, and programmers who read the code probably don't even know who he is, let alone the irrelevant things in the comments.
5. "one day" programmer
Public class Program {static void Main (string [] args) {/ / TODO: I need to fix this someday-07 Unix. 1995 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);}
To some extent, such comments are a hodgepodge of the previous types. TODO comments are useful in the initial development phase of a project, but if they appear in production code a few years later-that can be troublesome. If there's anything you need to fix, do it now instead of putting it off until later.
The above are the ways of program annotation that should be avoided in web development, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.