Click here to Skip to main content
15,905,068 members
Home / Discussions / C#
   

C#

 
AnswerRe: Exam preparation Pin
PIEBALDconsult22-Apr-10 13:05
mvePIEBALDconsult22-Apr-10 13:05 
AnswerRe: Exam preparation Pin
yu-jian22-Apr-10 15:42
yu-jian22-Apr-10 15:42 
GeneralRe: Exam preparation Pin
Peace ON22-Apr-10 22:09
Peace ON22-Apr-10 22:09 
AnswerRe: Exam preparation Pin
Peace ON22-Apr-10 22:07
Peace ON22-Apr-10 22:07 
GeneralRe: Exam preparation Pin
netJP12L23-Apr-10 4:43
netJP12L23-Apr-10 4:43 
Questioncomments? Pin
Megidolaon22-Apr-10 10:46
Megidolaon22-Apr-10 10:46 
AnswerRe: comments? Pin
Luc Pattyn22-Apr-10 11:05
sitebuilderLuc Pattyn22-Apr-10 11:05 
AnswerRe: comments? Pin
AspDotNetDev22-Apr-10 11:09
protectorAspDotNetDev22-Apr-10 11:09 
I usually clump things into logical groups, then I toss some comment above that group of code. If it's a simple bit of code, I use a small comment... if it's more complex, I might use a bigger comment. All my methods have comments on them (though some disagree with this practice and only comment public methods). I comment so others will be able to understand the code easily if they come across it later. I also have various practices for how I comment that I've just adopted over time. For example, I typically shove most of the variables at the top of the method and comment that section with:
C#
// Variables.
int x;
Person person;

It's standard for me, so I know when I see that that I can pretty much skip over that section of code. That illustrates another point -- that comments aren't always to describe the code, but have other purposes. In this case, the other purpose is so I know what code to skip over, which speeds up reading the code. For a similar reason, I comment every single property I have. I do this because it avoids an interruption in reading the code... the consistency between each property means there is one less thing my brain has to process when scanning code.

Also, most of the time, you should avoid commenting what the code does and instead comment what the code was made to do. For example, this would be a bad comment:
C#
// Iterates over a list of people and processes each in succession.
foreach(Person p in this.GetPeople())
{
    if(p.Height > Person.AverageHeight)
    {
        tallPeople.Add(p);
    }
    else if(p.Height == Person.AverageHeight)
    {
        averagePeople.Add(p);
    }
    else
    {
        shortPeople.Add(p);
    }
}

A better comment might be:
C#
// Categorize people by their height.
foreach(Person p in this.GetPeople())
{
    if(p.Height > Person.AverageHeight)
    {
        tallPeople.Add(p);
    }
    else if(p.Height == Person.AverageHeight)
    {
        averagePeople.Add(p);
    }
    else
    {
        shortPeople.Add(p);
    }
}

There are other nuances when it comes to commenting code, but you'll develop an intuition for these types of things as time goes on. Whatever system you develop, just follow it consistently.

AnswerRe: comments? Pin
hammerstein0522-Apr-10 11:26
hammerstein0522-Apr-10 11:26 
AnswerRe: comments? Pin
Gregory Gadow22-Apr-10 11:50
Gregory Gadow22-Apr-10 11:50 
AnswerRe: comments? Pin
Abhinav S22-Apr-10 16:41
Abhinav S22-Apr-10 16:41 
AnswerRe: comments? Pin
Megidolaon23-Apr-10 4:01
Megidolaon23-Apr-10 4:01 
AnswerRe: comments? Pin
Alan Balkany23-Apr-10 4:09
Alan Balkany23-Apr-10 4:09 
QuestionConnecting to RFID Reader Pin
Member 407767222-Apr-10 10:25
Member 407767222-Apr-10 10:25 
AnswerRe: Connecting to RFID Reader Pin
Migounette22-Apr-10 10:30
Migounette22-Apr-10 10:30 
GeneralRe: Connecting to RFID Reader Pin
Member 407767223-Apr-10 4:34
Member 407767223-Apr-10 4:34 
GeneralRe: Connecting to RFID Reader Pin
Migounette23-Apr-10 6:49
Migounette23-Apr-10 6:49 
QuestionDataList doesn't go into Edit mode correctly Pin
MWRivera22-Apr-10 8:54
MWRivera22-Apr-10 8:54 
QuestionDataGridView-Database in csharp smart device Pin
Tunisien8622-Apr-10 6:14
Tunisien8622-Apr-10 6:14 
AnswerRe: DataGridView-Database in csharp smart device Pin
Dan Mos22-Apr-10 7:55
Dan Mos22-Apr-10 7:55 
GeneralRe: DataGridView-Database in csharp smart device Pin
Tunisien8623-Apr-10 10:00
Tunisien8623-Apr-10 10:00 
QuestionThread Sync Query Pin
AmitDey22-Apr-10 5:09
AmitDey22-Apr-10 5:09 
AnswerRe: Thread Sync Query Pin
Luc Pattyn22-Apr-10 5:18
sitebuilderLuc Pattyn22-Apr-10 5:18 
QuestionListviewItems arrangement with csharp smart device [modified] Pin
Tunisien8622-Apr-10 3:55
Tunisien8622-Apr-10 3:55 
AnswerRe: ListviewItems arrangement with csharp smart device Pin
Tunisien8622-Apr-10 5:30
Tunisien8622-Apr-10 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.