Lec06C2

Lec06C2 - Lecture 6 Coding Conventions Outline Coding conventions Code Organization Indentation style Naming conventions Hungarian Notation

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 471 6-C2-1 Outline Coding conventions Code Organization Indentation style Naming conventions Hungarian Notation Variable Definition Discussion and Summary Lecture 6 Coding Conventions
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ECE 471 6-C2-2 Programming Style Guide Style Guides are used to enforce conventions and idioms used in the software development process. By standardizing on a common set of conventions, benefits include; improved software maintainability enhanced communication between developers
Background image of page 2
ECE 471 6-C2-3 Coding Conventions Overall Code Organization Preprocessor directives should be placed at the beginning of the file Next should come the function prototypes Constants and global variables should follow function prototypes Functions should be last in the file Comments should be added to identify the above sections
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ECE 471 6-C2-4 Constants Constants can be declared in two ways in C #define PI 3.14159 const float PI = 3.14159; The #define actually replaces PI with the literal number 3.14159. The const declaration actually allocates storage for the number PI and marks the storage as read-only USE ALL UPPER CASE LETTERS #define MAX_DELAY 100
Background image of page 4
ECE 471 6-C2-5 Variables Use underscores to separate words in names delay_count An alternative convention: names should start with a lower case letter and capitalize the first letter of every subsequent word. delayCount
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ECE 471 6-C2-6 Function Names Function names (other than main) follow a pattern of upper/lower case: ProcessRecord() GetUserChoice() HandleError() Begin each word in a function name with an uppercase letter
Background image of page 6
ECE 471 6-C2-7 Formatting Source Code Put open curly-brace on a separate line void DoDelay(int ms) { (indented code goes here…) } OR void DoDelay(int ms) { (code goes here…) }
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ECE 471 6-C2-8 Programming Style Additional coding conventions Tabs and autoindents should be set to 4 spaces in your IDE or editor environment. Single source lines after if, while or for should go on the next line. This simplifies debugging of such lines of code. if (a == b) a = c; // right not if (a == b) a = c; // wrong
Background image of page 8
ECE 471 6-C2-9 Nested if Statements Use curly-brackets! if (a==b) { if (c==d) { DoSomething(); } } else { DoSomethingElse(); }
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6-C2-10 Programming Style Commenting code Although well commented code requires some effort, it is an essential element of maintainable code. Write comments that add value to your code. Don't simply restate the obvious. Practice the following guidelines: All modules (interface and implementation - ex. *.h and *.c) should begin with a standard
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/31/2008 for the course ECE 471 taught by Professor Chien during the Spring '08 term at IUPUI.

Page1 / 35

Lec06C2 - Lecture 6 Coding Conventions Outline Coding conventions Code Organization Indentation style Naming conventions Hungarian Notation

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online