Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tonga Institute of Higher Education

Similar presentations


Presentation on theme: "Tonga Institute of Higher Education"— Presentation transcript:

1 Tonga Institute of Higher Education
Code Conventions Tonga Institute of Higher Education

2 What are Code Conventions?
Code Conventions are guidelines on how to write code. They are rules for File Organization Code Width Indentation Declarations Naming Conventions Etc.

3 Why Have Code Conventions
Code conventions are important to programmers for a number of reasons: Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. 80% of the lifetime cost of a piece of software goes to maintenance. Hardly any software is maintained for its whole life by the original author. If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. For code conventions to work, every person writing software must conform to the code conventions. Everyone.

4 What this means to you All homework must follow code conventions.
Points will be deducted if you do not follow code conventions. I will not look at any code that does not follow code conventions.

5 File Organization Source Code should be written in the following order: Comment flowerbox. Options Statements Option Explicit, Option Strict, etc. Import statements Imports System.Text Class Statements Variables Methods

6 Code Width Avoid lines longer than 80 characters, since they're not handled well by many terminals and tools. When an expression will not fit on a single line, break it according to these general principles: Break after a comma. Break before an operator. Use the line-continuation sequence, which is a space followed by an underscore ( _), at the point at which you want the line to break.

7 Break after a comma myObject.myMethod(AReallyLongVariableName, _
Subsequent lines use 1 tab

8 Break before an operator
Dim myString as String myString = “Hello, there! Welcome to Sony’s Online” _ & “Video Center” Break before An operator Subsequent lines use 1 tab Operator is first part of line

9 Indentation Indent all code contained within a statement Sub… End Sub
Function… End Function If… End If

10 Indent all code within brackets
This will help you debug your code Easy to see what is done in a class Easy to see what is done in a method Easy to see what is done in the body of the If statement

11 Declarations Initialize variables where they are declared.
The only reason not to initialize a variable where it's declared is if the initial value depends on some computation occurring first.

12 Naming Conventions Do not use spaces in your names
FindLastRecord RedrawMyForm Keep your names simple and descriptive Customer CheckInventory Each separate word in a name begins with a capital letter: Method names begin with a verb InitNameArray CloseDialog Class and Property names begin with a noun EmployeeName CarAccessory

13 Naming Conventions - 2 Constants All uppercase
Words separated by underscores ("_"). Example MIN_WIDTH MAX_WIDTH GET_THE_CPU

14 Different Conventions for Different Companies
Millions of people use code conventions Different companies have different standards The most important thing is to be consistent Find Microsoft’s recommendations here: Msdn.microsoft.com


Download ppt "Tonga Institute of Higher Education"

Similar presentations


Ads by Google