Must avoid five kinds of program annotation Way Summary _ related skill

Source: Internet
Author: User
Tags comments version control system
I've categorized these depressing comments into five categories, and the programmers who write them are grouped into five categories. I hope that after reading this article you feel like you don't belong to any of these types. If you are interested, you can read another article Five programmers (English), compared to the five programmers mentioned in this article.

1. The Proud programmer
Copy Code code as follows:

public class Program
{
static void Main (string[] args)
{
String message = "Hello world!"; 07/24/2010 Bob
Console.WriteLine (message); 07/24/2010 Bob
Message = ' I am so proud ' of this code! '; 07/24/2010 Bob
Console.WriteLine (message); 07/24/2010 Bob
}
}

Such programmers are so appreciative of their programs that they have to have their name on every line of code. The version control system should be allowed to provide information about the changes to the program, and his doing so at a glance does not explain who is responsible for the line of code.

2. Outdated Programmers
Copy Code code as follows:

public class Program
{
static void Main (string[] args)
{
* * This program is no longer useful
* Because we found that the millennium bug problem was a false alarm.
* Our system will not return to 1/1/1900 * *
DateTime today = Datetime.today;
if (today = = new DateTime (1900, 1, 1))
//{
Today = today. Addyears (100);
String message = "The date has been fixed for Y2K.";
Console.WriteLine (message);
//}
}
}

If a program is no longer useful (such as discarding it), delete it-don't be confused by a few lines of useless annotations. Even if you could reuse the code later, you can use the version control system to restore your program to its previous form.

3. The Naïve programmer
Copy Code code as follows:

public class Program
{
static void Main (string[] args)
{
/* This program is used on the screen
* Cycle print 1 million times "I rule!"
* Output one line at a time. Loop count
* Starting from 0, add 1 each time.
* When the counter is equal to 1 million,
* The loop will stop running * *

for (int i = 0; i < 1000000; i++)
{
Console.WriteLine ("I rule!");
}
}
}

Basic programming grammar rules we all know-we don't need "getting started with programming." You don't have to waste time explaining an obvious thing, and what we'd rather know is your program function-it's a waste of space.

4. The legendary programmer
Copy Code code as follows:

public class Program
{
static void Main (string[] args)
{
* * One day I was in a Starbucks on the street
* Talking to Jim in the sales department and he told me
* The sales Representative is to withdraw the Commission according to the following proportion.
* Friday: 25%
* Wednesday: 15%
* Other Date: 5%
* Did I tell you that I ordered a Kalame
* Iron Coffee and two copies 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 write out the requirements in the comments, don't mention the names. Salesman Jim is likely to be no longer a sales agent in the company. And most programmers who read this note do not always know who Jim is. You're describing the actual situation, but it's irrelevant to our content, so skip it.

5. Future Programmers
Copy Code code as follows:

public class Program
{
static void Main (string[] args)
{
TODO: I'll fix the problem in the future –07/24/1995 Bob
/* I know this is a difficult problem to solve and
* I now rely on this contains function, but
* I'll use a more meaningful, more
* Print this code in an elegant way.
* I just don't have time now.
*/
String message = ' An error has occurred ';
if (message. Contains ("error"))
{
throw new Exception (message);
}
}
}

This annotation is a synthesizer that contains all the questions about the annotation mentioned above. Todo comments are useful in the initial development phase of a project, but this comment appears to have been in the product program several years ago-it proves that there is a problem with the program. If there is a problem to be solved, solve it immediately, don't drag it to the future.

If you have written such a note, or if you are looking for the best annotation scheme, I recommend that you read the book written by Steve McConnell, the code complete. This is one of six books that I recommend to all programmers to read. Or you can learn how to stop annotating your program (in English).

Have you seen any other meaningless or annoying annotations in your program? Welcome to share.

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.