Recently, spotted a pretty old but still very good article on web, about coding and commenting and how to in C#.
We could not agree more with on a couple of points as highlighted there:
"Don't insult the reader's intelligence
Avoid obvious comments such as:
int age = 45;
if (age >= 18) // If age is greater than 18 a person can vote
Console.WriteLine("Vote");
else
Console.WriteLine("Can't Vote");
This wastes your time writing needless comments and distracts the reader with details that can be easily removed from the code."
"The golden rule.
Let the code speak for itself. You code should be written in such a way that everyone should easily understand it.
For example:
public Form1()
{
InitializeComponent();
SqlConnection con = new SqlConnection("Data Source=MCN002;Initial Catalog=puran; Integrated Security=True");
string cmd = "Select * from testpuran";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd, con);
DataSet ds = new DataSet();
da.Fill(ds);
dataGrid1.DataSource = ds;
}"
In case interested in reading it, here is the link:
Recent Comments