Presentation is loading. Please wait.

Presentation is loading. Please wait.

Coding Practices. What are Coding Practices ? Coding practices are a set of informal rules that the software development community has learned over time.

Similar presentations


Presentation on theme: "Coding Practices. What are Coding Practices ? Coding practices are a set of informal rules that the software development community has learned over time."— Presentation transcript:

1 Coding Practices

2 What are Coding Practices ? Coding practices are a set of informal rules that the software development community has learned over time which can help improve the quality of software

3 Need for Coding Practices Many computer programs remain in use for far longer than the original authors ever imagined (sometimes 40 years or more) So rules are need to facilitate both initial development and subsequent maintenance and enhancement by people other than the original authors

4 Ninety Ninety Rule Tim Cargill is credited with this explanation as to why programming projects often run late: "The first 90% of the code accounts for the first 10% of the development time. The remaining 10% of the code accounts for the other 90% of the development time." Guidance is needed to remedy this lack of foresight

5 Software Quality Several attributes contribute to software quality: Clear concise requirements. A solid design to which to code Conformity to any relevant standards such as naming conventions (all caps for global variables, custom blocks, etc). Clear, accurate comments

6 Prerequisites – Before Coding From Meek & Heath: "What happens before one gets to the coding stage is often of crucial importance to the success of the project.” Requirements – what is the project to do, very difficult to on large projects Architecture - concerned with deciding what has to be done, and which program component is going to do it (how something is done is left to the detailed design phase)

7 Prerequisites (Continued) Design - fill in the details which have been glossed over in the architectural design. For example, at the architectural level it may have been noted that some data has to be sorted, while at the design level it is necessary to decide which sorting algorithm is to be used.

8 Coding Standards McConnell points out: "Establish programming conventions before you begin programming. It's nearly impossible to change code to match them later.” For example, if a student used capitals for local variables, it would be a job to change the names, select from drop downs, etc It is much easier for a programmer (maybe thousands) to read code written by someone else if all code follows the same conventions. Do not want a Tower of Babylon

9 Coding Standards (Continued) Commenting – more than one person working on a module, later maintenance programmers, explain what is going on (especially complex or tricky code)

10 Coding Standards (Continued) Naming conventions – makes the code much more comprehensible to others, such as names for globals, locals and custom blocks Sometimes programmers use X1, Y1, etc. as variables and forget to replace them with meaningful ones, causing confusion. Example: A variable for taking in weight as a parameter for a truck can be named TrkWeight or TruckWeight (the preferred one)

11 KISS Keep it Simple Stupid (KISS) Complicated logic for achieving a simple thing should be kept to a minimum due to future modifications The logic one programmer implemented may not make perfect sense to another. So, always keep the code as simple as possible Good programmers are egoless, good team players and eager/willing to learn (no shame)

12 KISS Example

13 Code Building Debugging the code and correcting errors - Programmers tend to write the complete code and then begin debugging and checking for errors Good to debug small parts as they are coded and not the entire program Stub out parts as other parts are developed Tests small pieces of code by moving the cursor to the code and pressing the cursor Integrated Tests – as the smaller pieces are brought together

14 An Example Design down from start (green flag) followed by control flow (how the program logic flows) and pushing down work (details) and doing work in custom blocks

15 Caution – Things to Beware Of Global variables - set in many places Race Conditions – timing causes strange things, one sprite draws another erases Misplacing of statements – statements placed outside of proper C block, i.e. if statements

16 Debug Help Check variable show block to see values Put in wait statements to slow down execution for better visibility Put in say blocks to see where execution is going and values Caution – debug can cause different code paths to be taken, timing changed

17 Summary Know what the code block must perform Comment flow and “tricky” code Correct errors as they occur. Keep your code simple Maintain naming conventions which are uniform throughout.


Download ppt "Coding Practices. What are Coding Practices ? Coding practices are a set of informal rules that the software development community has learned over time."

Similar presentations


Ads by Google