Back to Home

Style Guide

Table of Contents

Overview

This document provides an overview of standard naming conventions in C#, aspx, and SQL so we can be more consistent with our code across applications.

C Sharp

Source: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions

Naming Conventions

It is a good rule of thumb to use names that reflect the function of the variable or method being defined. That way, the person who ends up maintaining the code spends less time trying to figure out what your code does.

Variables

When declaring a variable, use camel case:

string myVariable = "fooBar";

Functions/Methods

When defining a function, use Pascal case:

protected void MyFunction (string myVariable) {}    

Also, note the space between the function name and parameters. Details like this are small, but go a long way in making code readable.

Layout Conventions

General Layout Guidelines

Comments

Back to top

aspx

Naming Conventions

The formula for naming controls is, lowercase control-specific prefix + underscore + Pascal-cased descriptive name for control. Here are some examples for the most common controls used in PBC's pages:

Check Boxes

cb_MyCheckBox

Check Box Lists

cbl_MyCheckBoxList

Data Sources

sql_MyDataSource

ddl_MyDropDownList

Grid Views

gv_MyGridView

Labels

lbl_MyLabel

lbt_MyLinkButton

List Boxes

lb_MyListBox

Multi Views

mv_MyMultiView

Radio Buttons

rb_MyRadioButton

Radio Button Lists

rbl_MyRadioButtonList

Text Boxes

tb_MyTextBox

User Controls

uc_MyUserControl

Validators

Validators come in two flavors: Required, and Custom.

rfv_MyRequiredFieldValidator 
cv_MyCustomValisdator 

Views

mvv_MyView

Layout Conventions

Don't underestimate the value of indentation and spacing. For instance, this:

<asp:Label ID="lbl_MyFirstLabel" Text="Good Layout Example" runat="server">
<table>
    <td>
        <tr>
            <sam3:CodeListDropDown ID="cldd_MyFirstCodeListDropDown" runat="server"/>
            &nbsp;&nbsp;&nbsp;&nbsp;
        </tr>
    </td>
</table>

is much easier to read and understand than this:

<asp:Label ID="lbl_MySecondLabel" Text="Bad Layout Example" runat="server">
<table><td><tr>
<sam3:CodeListDropDown ID="cldd_MySecondCodeListDropDown" runat="server"/>&nbsp;&nbsp;&nbsp;&nbsp;</tr></td>
</table>

Generally, the rule of thumb is to use a new line for each new control, and indent with one tab for each new nested div, view, multiview, table row, and table column. It is also important to avoid superflous white space between lines. To take another example, this:

<asp:Panel ID="pn_MyFirstPanel" runat="server">
    <asp:MultiView ID="mv_MyFirstMultiView" runat="server">
        <asp:View ID="mvv_MyFirstView" runat="server">
            <asp:Label ID="lbl_MyFirstLabel" runat="server" />
            </asp:Label>
        </asp:View>
    </asp:MultiView>
</asp:Panel>

is much easier to read and understand than this:

<asp:Panel ID="pn_MyFirstPanel" runat="server">

    <asp:MultiView ID="mv_MyFirstMultiView" runat="server">


        <asp:View ID="mvv_MyFirstView" runat="server">

            <asp:Label ID="lbl_MyFirstLabel" runat="server" />

            </asp:Label>

        </asp:View>
    </asp:MultiView>
</asp:Panel>

Back to top

SQL

Naming Conventions

Variables

When declaring a variable, use Pascal case:

declare @MyVariable varchar(20) = "Hello World!";

Tables and Stored Procedures

When naming a new table or stored procedure, use the following convention:

smart.<projectname>_<Sproc_OrTableDescription>    

For instance,

smart.p11_Load_IntakeForm

Layout Conventions

General Layout Guidelines

Back to top

Git

Commit Messages

Do not underestimate the value of a descriptive commit message. It helps you and others understand what your change entailed and why it was necessary. For instance, this is a very unhelpful commit message:

$git commit -m "Added some new features."

The person who comes behind you has no easy way of understanding your changes. A more helpful commit message would be:

$git commit -m "[CP email notifications] Email notifications working
> Added a new condition to handle sending email notifications for
claims not audited in 250K. Changed the body of these emails to
reflect client needs."

or, equivilently:

$git commit -m "[CP email notifications] Email notifications working' -m 'Added 
a new condition to handle sending email notifications for claims not audited in 
250K. Changed the body of these emails to reflect client needs."

So the general format of a good commit message is:

[Name of the page or control you changed] Brief description of change
Elaboration on details of the change and why it was nescessary. 

Branch Naming

It is also very helpful to other members of the team when branches are named appropriately. Again, the name should reflect what is being added or changed on the branch. Names of branches should be prefixed with bugfix/ feature/ hotfix/ or release/. This is an example of poorly named branch:

my-new-features

And this is an example of a well-named branch:

feature/250K-CP-needs-email-notifications-on-claim-deletion

Back to top