Lec06C2 - Lecture 6 Coding Conventions Outline Coding...

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

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
Image of page 1

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

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
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
Image of page 3

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

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
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
Image of page 5

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

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
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…) }
Image of page 7

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

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
Image of page 8
ECE 471 6-C2-9 Nested if Statements Use curly-brackets! if (a==b) { if (c==d) { DoSomething(); } } else { DoSomethingElse(); }
Image of page 9

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

ECE 471 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.
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '08
  • Chien
  • high memory, System File, Low memory, Hungarian Notation Constructors

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern