Download presentation
Presentation is loading. Please wait.
Published byGriffin Adams Modified over 5 years ago
1
Coding practices For IT and Computing students 2014
2
Introduction Superior coding techniques and programming practices are hallmarks of a professional programmer These slides cover: fundamental coding techniques to improve the readability and maintainability of code coding practices to enhance performance Assignments award marks for good programming Information adapted from Rob Caron Microsoft Corporation February 2000
3
Techniques: Naming A name should tell “what” instead of “how”
GetNextStudent() instead of GetNextArrayElement() Use the verb-noun method for naming routines or functions that perform some operation on a given object, such as CalculateInvoiceTotal()
4
Techniques: Naming Use Pascal naming for functions – start with a capital letter CalculateInvoiceTotal() Use Camel Case for variables – start with lower case documentFormatType Use upper case with underscores for constants NUM_DAYS_IN_WEEK
5
Techniques: Naming Hungarian and Leszynski/Reddick
Prefixes or tags are used at the front of the variable to indicate type strUserName intOrderQuantity tblUsers qryGetOrders Mainly used by Microsoft but discouraged in their latest design guide
6
Techniques: Naming When naming tables, express the name in the singular form. Spaces are not allowed. Employee instead of Employees Avoid single-letter variable names, such as i, or j, other than for x,y,z coordinates Boolean variable names should contain Is which implies True/False values fileIsFound
7
Techniques: Naming Do not use literal numbers or literal strings, such as For dayCount = 1 To 7 Instead, use named constants, For dayCount = 1 To NUM_DAYS_IN_WEEK
8
Techniques: Comments Comment as you code
Code which is obvious today probably won't be obvious six weeks from now (or even tomorrow) Comment anything that is not readily obvious in the code Comment code that consists of loops and logic branches Don’t put comments at the end of a line of code unless annotating variable declarations or ending a loop.
9
Techniques: Comments At the beginning of every module or file provide
Name and version of the module. Purpose of the Module. Description of the Module (In brief). Original Author /* File: connection.php V1.1 By: Bob Date: This script connects to a database */
10
Techniques: Format Establish a standard size for an indent, such as 4 spaces Align sections of code using indentation If … Then … Else End If
11
Techniques: Format Align open and close braces vertically for (count = 0; count < 100; count++) { … } Or put open braces at the end of the line and close braces at the beginning of the line for (count = 0; count < 100; count++){
12
Techniques: Format When writing SQL statements, use all uppercase for keywords and mixed case for database elements, such as tables, columns, and views Put each major SQL clause on a separate line SELECT FirstName, LastName FROM Customers WHERE County = 'Hereford'
13
Practice: General Select data types to ensure the size of a variable is not excessively large Keep the scope of variables as small as possible Use variables and routines for one and only one purpose. Develop and use error-handling routines Treat compilation warnings as errors Use Select Case or Switch statements instead of repetitive checking of a common variable using If…Then statements
14
Practice: Data specific
Never use SELECT *. Always be explicit in which columns to retrieve and retrieve only the columns that are required Verify the row count when performing DELETE operations Perform data validation at the client during data entry Avoid using functions in WHERE clauses
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.