<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.panglossian.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Coding_Standards</id>
	<title>Coding Standards - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.panglossian.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Coding_Standards"/>
	<link rel="alternate" type="text/html" href="https://wiki.panglossian.net/wiki/index.php?title=Coding_Standards&amp;action=history"/>
	<updated>2026-07-09T01:18:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://wiki.panglossian.net/wiki/index.php?title=Coding_Standards&amp;diff=64&amp;oldid=prev</id>
		<title>Stuart: Not really working from here at the moment</title>
		<link rel="alternate" type="text/html" href="https://wiki.panglossian.net/wiki/index.php?title=Coding_Standards&amp;diff=64&amp;oldid=prev"/>
		<updated>2016-09-09T06:37:53Z</updated>

		<summary type="html">&lt;p&gt;Not really working from here at the moment&lt;/p&gt;
&lt;a href=&quot;https://wiki.panglossian.net/wiki/index.php?title=Coding_Standards&amp;amp;diff=64&amp;amp;oldid=58&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Stuart</name></author>
	</entry>
	<entry>
		<id>https://wiki.panglossian.net/wiki/index.php?title=Coding_Standards&amp;diff=58&amp;oldid=prev</id>
		<title>Stuart: Initial coding standards (direct from bp wiki)</title>
		<link rel="alternate" type="text/html" href="https://wiki.panglossian.net/wiki/index.php?title=Coding_Standards&amp;diff=58&amp;oldid=prev"/>
		<updated>2016-09-08T08:08:44Z</updated>

		<summary type="html">&lt;p&gt;Initial coding standards (direct from bp wiki)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{nav/stuart}}&lt;br /&gt;
= Coding Standards =&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note to self&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Things I want to cover in this:&lt;br /&gt;
* VB standards (global)&lt;br /&gt;
* C# standards (global)&lt;br /&gt;
* General standards (ours)&lt;br /&gt;
* SQL naming standards&lt;br /&gt;
* SQL code conventions? .NET/SQL conventions?&lt;br /&gt;
* Suggestions from me.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
It has become apparent that there is some disagreement over whether we follow any sort of coding standard at all. I submit that we do, but it is at a very high level, not a prescriptive set of &amp;#039;commandments&amp;#039; that all code should follow - and I would like to keep it like that, with only functionally dangerous conventions being forbidden rather than stuff that one or two developers don&amp;#039;t like the look of.&lt;br /&gt;
&lt;br /&gt;
In general, coding standards exist so that it&amp;#039;s one less barrier for a programmer skilled in the language to have to deal with when approaching a new project, so I think we should try and use the general standards and good practices that are largely agreed on within the larger programming community.&lt;br /&gt;
&lt;br /&gt;
As such, I think the best place to start is the Microsoft coding conventions - they are quite liberal, and are detailed in the pages:&lt;br /&gt;
* [https://msdn.microsoft.com/en-us/library/h63fsef3.aspx Visual Basic Coding Conventions]&lt;br /&gt;
* [https://msdn.microsoft.com/en-us/library/0b283bse.aspx Visual Basic Naming Conventions]&lt;br /&gt;
* [https://msdn.microsoft.com/en-gb/library/ff926074.aspx C# Coding Conventions]&lt;br /&gt;
&lt;br /&gt;
I haven&amp;#039;t really gone into it in detail, but it might also be worth looking at:&lt;br /&gt;
* [https://msdn.microsoft.com/en-us/library/8a3x2b7f.aspx Secure Coding Guidelines]&lt;br /&gt;
&lt;br /&gt;
We also have some coding standards, written mostly before my time (2009), which are some more restrictive and, possibly as a result, are largely not followed. These are on the wiki, currently at [Coding Standards]; it may be moved to another page as our current set of standards is promoted - if so, I&amp;#039;ll update this reference.&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to try and pull together a few different references here, namely:&lt;br /&gt;
* Microsoft&amp;#039;s conventions&lt;br /&gt;
* Our conventions&lt;br /&gt;
* My own preferences&lt;br /&gt;
&lt;br /&gt;
We can then argue about them at wholly unnecessary length and hopefully we&amp;#039;ll have something that we can all agree with (or at least compromise on) at the end of it.&lt;br /&gt;
&lt;br /&gt;
== Standards ==&lt;br /&gt;
Since we have mostly Visual Basic code, I&amp;#039;ll tackle that first.&lt;br /&gt;
&lt;br /&gt;
=== Visual Basic ===&lt;br /&gt;
This is largely cribbed from [https://msdn.microsoft.com/en-us/library/h63fsef3.aspx Visual Basic Coding Conventions]&lt;br /&gt;
&lt;br /&gt;
Microsoft develops samples and documentation that follow the guidelines in this topic. If you follow the same coding conventions, you may gain the following benefits:&lt;br /&gt;
* Your code will have a consistent look, so that readers can better focus on content, not layout.&lt;br /&gt;
* Readers understand your code more quickly because they can make assumptions based on previous experience.&lt;br /&gt;
* You can copy, change, and maintain the code more easily.&lt;br /&gt;
* You help ensure that your code demonstrates &amp;quot;best practices&amp;quot; for Visual Basic.&lt;br /&gt;
&lt;br /&gt;
==== Naming Conventions ====&lt;br /&gt;
* For information about naming guidelines, see [https://msdn.microsoft.com/en-us/library/ms229002.aspx Naming Guidelines] topic.&lt;br /&gt;
* Do not use &amp;quot;My&amp;quot; or &amp;quot;my&amp;quot; as part of a variable name. This practice creates confusion with the My objects.&lt;br /&gt;
* You do not have to change the names of objects in auto-generated code to make them fit the guidelines.&lt;br /&gt;
&lt;br /&gt;
==== Layout Conventions ====&lt;br /&gt;
* Insert tabs as spaces, and use smart indenting with four-space indents.&lt;br /&gt;
*  Pretty listing (reformatting) of code to reformat your code in the code editor. For more information, see Options, Text Editor, Basic (Visual Basic).&lt;br /&gt;
* Use only one statement per line. Don&amp;#039;t use the Visual Basic line separator character (:).&lt;br /&gt;
* Avoid using the explicit line continuation character &amp;quot;_&amp;quot; in favor of implicit line continuation wherever the language allows it.&lt;br /&gt;
* Use only one declaration per line.&lt;br /&gt;
* If Pretty listing (reformatting) of code doesn&amp;#039;t format continuation lines automatically, manually indent continuation lines one tab stop. However, always left-align items in a list.&lt;br /&gt;
 a As Integer,&lt;br /&gt;
 b As Integer&lt;br /&gt;
* Add at least one blank line between method and property definitions.&lt;br /&gt;
&lt;br /&gt;
==== Commenting Conventions ====&lt;br /&gt;
* Put comments on a separate line instead of at the end of a line of code.&lt;br /&gt;
* Start comment text with an uppercase letter, and end comment text with a period.&lt;br /&gt;
* Insert one space between the comment delimiter (&amp;#039;) and the comment text.&lt;br /&gt;
 &amp;#039; Here is a comment.&lt;br /&gt;
* Do not surround comments with formatted blocks of asterisks.&lt;br /&gt;
&lt;br /&gt;
==== Program Structure ====&lt;br /&gt;
* When you use the Main method, use the default construct for new console applications, and use My for command-line arguments.&lt;br /&gt;
 Sub Main()&lt;br /&gt;
   For Each argument As String In My.Application.CommandLineArgs&lt;br /&gt;
     &amp;#039; Add code here to use the string variable.&lt;br /&gt;
   Next&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
==== Language Guidelines ====&lt;br /&gt;
===== String Data Type =====&lt;br /&gt;
* To concatenate strings, use an ampersand (&amp;amp;).&lt;br /&gt;
 MsgBox(&amp;quot;hello&amp;quot; &amp;amp; vbCrLf &amp;amp; &amp;quot;goodbye&amp;quot;)&lt;br /&gt;
* To append strings in loops, use the StringBuilder object.&lt;br /&gt;
 Dim longString As New System.Text.StringBuilder&lt;br /&gt;
 For count As Integer = 1 To 1000&lt;br /&gt;
   longString.Append(count)&lt;br /&gt;
 Next&lt;br /&gt;
&lt;br /&gt;
===== Relaxed Delegates in Event Handlers =====&lt;br /&gt;
Do not explicitly qualify the arguments (Object and EventArgs) to event handlers. If you are not using the event arguments that are passed to an event (for example, sender as Object, e as EventArgs), use relaxed delegates, and leave out the event arguments in your code:&lt;br /&gt;
 Public Sub Form1_Load() Handles Form1.Load&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
===== Unsigned Data Type =====&lt;br /&gt;
* Use Integer rather than unsigned types, except where they are necessary. (?!)&lt;br /&gt;
&lt;br /&gt;
===== Arrays =====&lt;br /&gt;
* Use the short syntax when you initialize arrays on the declaration line. For example, use the following syntax.&lt;br /&gt;
 Dim letters1 As String() = {&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;}&lt;br /&gt;
:Do not use the following syntax.&lt;br /&gt;
 Dim letters2() As String = New String() {&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;}&lt;br /&gt;
* Put the array designator on the type, not on the variable. For example, use the following syntax:&lt;br /&gt;
 Dim letters4 As String() = {&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;}&lt;br /&gt;
:Do not use the following syntax:&lt;br /&gt;
 Dim letters3() As String = {&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;}&lt;br /&gt;
* Use the { } syntax when you declare and initialize arrays of basic data types. For example, use the following syntax:&lt;br /&gt;
 Dim letters5() As String = {&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;}&lt;br /&gt;
:Do not use the following syntax:&lt;br /&gt;
 Dim letters6(2) As String&lt;br /&gt;
 letters6(0) = &amp;quot;a&amp;quot;&lt;br /&gt;
 letters6(1) = &amp;quot;b&amp;quot;&lt;br /&gt;
 letters6(2) = &amp;quot;c&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===== Use the With Keyword =====&lt;br /&gt;
* When you make a series of calls to one object, consider using the With keyword:&lt;br /&gt;
 With orderLog&lt;br /&gt;
   .Log = &amp;quot;Application&amp;quot;&lt;br /&gt;
   .Source = &amp;quot;Application Name&amp;quot;&lt;br /&gt;
   .MachineName = &amp;quot;Computer Name&amp;quot;&lt;br /&gt;
 End With&lt;br /&gt;
&lt;br /&gt;
===== Use the Try...Catch and Using Statements when you use Exception Handling =====&lt;br /&gt;
* Do not use {{c|On Error Goto}}.&lt;br /&gt;
&lt;br /&gt;
===== Use the IsNot Keyword =====&lt;br /&gt;
* Use the IsNot keyword instead of Not...Is Nothing. &lt;br /&gt;
&lt;br /&gt;
===== New Keyword =====&lt;br /&gt;
* Use short instantiation. For example, use the following syntax:&lt;br /&gt;
 Dim employees As New List(Of String)&lt;br /&gt;
: The preceding line is equivalent to this:&lt;br /&gt;
 Dim employees2 As List(Of String) = New List(Of String)&lt;br /&gt;
* Use object initializers for new objects instead of the parameterless constructor:&lt;br /&gt;
 Dim orderLog As New EventLog With { &lt;br /&gt;
     .Log = &amp;quot;Application&amp;quot;, &lt;br /&gt;
     .Source = &amp;quot;Application Name&amp;quot;, &lt;br /&gt;
     .MachineName = &amp;quot;Computer Name&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
===== Event Handling =====&lt;br /&gt;
* Use Handles rather than AddHandler:&lt;br /&gt;
 Private Sub ToolStripMenuItem1_Click() Handles ToolStripMenuItem1.Click&lt;br /&gt;
 End Sub&lt;br /&gt;
* Use AddressOf, and do not instantiate the delegate explicitly:&lt;br /&gt;
 Dim closeItem As New ToolStripMenuItem( &lt;br /&gt;
     &amp;quot;Close&amp;quot;, Nothing, AddressOf ToolStripMenuItem1_Click)&lt;br /&gt;
 Me.MainMenuStrip.Items.Add(closeItem)&lt;br /&gt;
* When you define an event, use the short syntax, and let the compiler define the delegate:&lt;br /&gt;
 Public Event SampleEvent As EventHandler(Of SampleEventArgs)&lt;br /&gt;
 &amp;#039; or&lt;br /&gt;
 Public Event SampleEvent(ByVal source As Object, &lt;br /&gt;
                          ByVal e As SampleEventArgs)&lt;br /&gt;
* Do not verify whether an event is Nothing (null) before you call the RaiseEvent method. RaiseEvent checks for Nothing before it raises the event.&lt;br /&gt;
&lt;br /&gt;
===== Using Shared Members =====&lt;br /&gt;
* Call Shared members by using the class name, not from an instance variable. &lt;br /&gt;
&lt;br /&gt;
===== Use XML Literals =====&lt;br /&gt;
XML literals simplify the most common tasks that you encounter when you work with XML (for example, load, query, and transform). When you develop with XML, follow these guidelines:&lt;br /&gt;
* Use XML literals to create XML documents and fragments instead of calling XML APIs directly.&lt;br /&gt;
* Import XML namespaces at the file or project level to take advantage of the performance optimizations for XML literals.&lt;br /&gt;
* Use the XML axis properties to access elements and attributes in an XML document.&lt;br /&gt;
* Use embedded expressions to include values and to create XML from existing values instead of using API calls such as the {{c|Add}} method:&lt;br /&gt;
 Private Function GetHtmlDocument( &lt;br /&gt;
   ByVal items As IEnumerable(Of XElement)) As String&lt;br /&gt;
 &lt;br /&gt;
   Dim htmlDoc = &amp;lt;html&amp;gt;&lt;br /&gt;
                   &amp;lt;body&amp;gt;&lt;br /&gt;
                     &amp;amp;lt;table border=&amp;quot;0&amp;quot; cellspacing=&amp;quot;2&amp;quot;&amp;gt;&lt;br /&gt;
                       &amp;lt;%= &lt;br /&gt;
                         From item In items &lt;br /&gt;
                         Select &amp;lt;tr&amp;gt;&lt;br /&gt;
                                  &amp;lt;td style=&amp;quot;width:480&amp;quot;&amp;gt;&lt;br /&gt;
                                    &amp;lt;%= item.&amp;lt;title&amp;gt;.Value %&amp;gt;&lt;br /&gt;
                                  &amp;lt;/td&amp;gt;&lt;br /&gt;
                                  &amp;lt;td&amp;gt;&amp;lt;%= item.&amp;lt;pubDate&amp;gt;.Value %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
                                &amp;lt;/tr&amp;gt; &lt;br /&gt;
                       %&amp;gt;&lt;br /&gt;
                     &amp;amp;lt;/table&amp;gt;&lt;br /&gt;
                   &amp;lt;/body&amp;gt;&lt;br /&gt;
                 &amp;lt;/html&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
   Return htmlDoc.ToString()&lt;br /&gt;
 End Function&lt;br /&gt;
&lt;br /&gt;
===== LINQ Queries =====&lt;br /&gt;
* Use meaningful names for query variables:&lt;br /&gt;
 Dim seattleCustomers = From cust In customers &lt;br /&gt;
                        Where cust.City = &amp;quot;Seattle&amp;quot;&lt;br /&gt;
* Provide names for elements in a query to make sure that property names of anonymous types are correctly capitalized using Pascal casing:&lt;br /&gt;
 Dim customerOrders = From customer In customers &lt;br /&gt;
                      Join order In orders &lt;br /&gt;
                        On customer.CustomerID Equals order.CustomerID &lt;br /&gt;
                      Select Customer = customer, Order = order&lt;br /&gt;
* Rename properties when the property names in the result would be ambiguous. For example, if your query returns a customer name and an order ID, rename them instead of leaving them as Name and ID in the result:&lt;br /&gt;
 Dim customerOrders2 = From cust In customers &lt;br /&gt;
                       Join ord In orders&lt;br /&gt;
                         On cust.CustomerID Equals ord.CustomerID &lt;br /&gt;
                       Select CustomerName = cust.Name, &lt;br /&gt;
                              OrderID = ord.ID&lt;br /&gt;
* Use type inference in the declaration of query variables and range variables:&lt;br /&gt;
 Dim customerList = From cust In customers&lt;br /&gt;
* Align query clauses under the From statement:&lt;br /&gt;
 Dim newyorkCustomers = From cust In customers &lt;br /&gt;
                        Where cust.City = &amp;quot;New York&amp;quot; &lt;br /&gt;
                        Select cust.LastName, cust.CompanyName&lt;br /&gt;
* Use Where clauses before other query clauses so that later query clauses operate on the filtered set of data:&lt;br /&gt;
 Dim newyorkCustomers2 = From cust In customers &lt;br /&gt;
                         Where cust.City = &amp;quot;New York&amp;quot; &lt;br /&gt;
                         Order By cust.LastName&lt;br /&gt;
* Use the Join clause to explicitly define a join operation instead of using the Where clause to implicitly define a join operation:&lt;br /&gt;
 Dim customerList2 = From cust In customers &lt;br /&gt;
                     Join order In orders &lt;br /&gt;
                       On cust.CustomerID Equals order.CustomerID &lt;br /&gt;
                     Select cust, order&lt;/div&gt;</summary>
		<author><name>Stuart</name></author>
	</entry>
</feed>