Tuesday, 3 November 2015

General Code Review

Code Review :- General 
1. Remove the  commented code
2. Variable name should not be contain "_".
3. Query should be in separate class.
4. Use Common log error when handle the exception
5. Use String.isNullorWhiteSpace instead of String.isNullorEmpty
6. Use Using Statement for variable scope should be limited.
7.  Remove unnecessary if ... else ...

e.g.   if (dtTasksAll != null && dtTasksAll.Rows.Count > 0)
{
            gv.DataSource = dtTasksAll;
            gv.DataBind();
        }
        else
        {
gv.EmptyDataText = "No New Tasks found";
lblviewimg.Visible=false;
gv.DataSource = dtTasksAll;
gv.DataBind();
}

Optimized code :-
if(dtTasksAll == null)
{
gv.EmptyDataText = "No New Tasks found";
lblviewimg.Visible=false;
}
gv.DataSource = dtTasksAll;
gv.DataBind();

8. Terminate loop as soon as possible

e.g.
foreach (SPUser user in group.Users)
{
if (!string.IsNullOrEmpty(user.Email))
{
MailTo += MailTo == string.Empty ? user.Email : "," + user.Email;
}
}

Optimized code :-
foreach (SPUser user in group.Users)
{
if (string.IsNullOrWhiteSpace(user.Email)) Continue;
MailTo += MailTo == string.Empty ? user.Email : "," + user.Email;
}

No comments:

Post a Comment

What is the Use of X and Y Properties in Power Apps SharePoint List Form?

If you've spent any time customizing SharePoint List Forms using Power Apps, you've likely come across the X and Y properties ...