Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson 4 Best Practices.

Similar presentations


Presentation on theme: "Lesson 4 Best Practices."— Presentation transcript:

1 Lesson 4 Best Practices

2 Best Practices The objectives for this lesson are as follows:
Overview of best practices Source Code indentation Naming conventions Separation of files into logical units Code style guides Commenting Code

3 Best Practices Overview of Best Practices Indentation Allman K&R
Best Practices are rules created by the software development community to improve and enhance the quality of software and ensure that code follows a consistent style. These rules help contributors understand the source code more clearly (readability) which improves efficiently by making software maintenance simpler. We will cover some of the most common best practices to integrate into your programming. Indentation Following proper indentation conventions creates the overall structure of your program. Here are the 2 common styles, Allman and K&R. Allman K&R The Allman method is more spaced out with each item of code on a new line. The K&R method is condensed and uses less lines of code.

4 Best Practices Naming Conventions Underscore - bar_code_read_092311
Naming conventions help developers stay organized and consistent when identifying their files, folders, documents, variables, etc. There are 3 main naming conventions used, choose one and be consistent. Underscore - bar_code_read_092311 Hyphens - bar-code-read CamelCase - barCodeRead092311 PascalCase - BarCodeRead092311 Note Hyphenated names will not be acceptable in most programming languages as the - character is often an operator used for subtraction. In the example above each word would be seen as its own variable.

5 Best Practices Separate Files into Logical Units
When developing software it is good practice to keep in mind the size of the files you are coding and to separate them into logical units. This will help you stay organized as your applications grow in complexity. As the complexity of your application increases, breaking up your code into multiple files can also help you understand how your own code will be running. The organization of the files will typically mirror the how your program is organized conceptually. My Game Login Lobby Level Select Game Area Levels my_game/ Login.java Lobby.java Level.java GameArea.java levels/ level1.xml level2.xml

6 Best Practices Code Style Guides CamelCase
Every programming language has a set of guidelines established called its Code Style Guide. The guide outlines the proper coding conventions of the programming language to create a foundation for how the shared code is structured. This helps to eliminate any problems interpreting the code. Let’s look at the JavaScript Code Style Guide for an example. Check out for more examples. Variable Names Spacing CamelCase Spaces around operators & after commas

7 Best Practices Commenting Your Code
Commenting your code is important because it helps you and other developers understand what’s going on in the source code. The main purpose of commenting is to explain in a general way what is happening in the code, but in plain english. Its also a great way of hiding the code from the compiler for testing purposes. There are specific formats for commenting code so it doesn’t interfere with the compilers and interpreters reading the program. All programming languages follow the same commenting structures for the most part. Single line comment //This is a single line comment OR #This is a single line comment in PHP Multi-line (block) comment /*This is a block comment displayed on multiple lines*/ HTML <!--HTML requires this format for commenting-->

8 Best Practices The objectives for this lesson are as follows:
Overview of best practices Source Code indentation Naming conventions Separation of files into logical units Code style guides Commenting Code

9 Sources “Best coding practices” Wikipedia, “JavaScript Style Guide and Coding Conventions” W3Schools, “Can I use hashtags for comments in PHP?” Stackoverflow, hashes-for-comments-in-php “Commenting code” Wikipedia, rogramming%29


Download ppt "Lesson 4 Best Practices."

Similar presentations


Ads by Google