AlexLecture_ProfessionalC++Coding

AlexLecture_ProfessionalC++Coding - Professional C+ Coding...

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

View Full Document Right Arrow Icon
1 Professional C++ Coding Alex X. Liu 2 Source Code Organization ± Files and project organization Files containing class definitions and implementations should contain only one class . The name of the file should be the same as the name of the class. ± Header Files Include Statements: include statements should never refer to a header file in terms of absolute path. Bad: #include "/code/TelephonyMgr/Include/TMPhoneLine.h" Good: #include "TMPPhoneLine.h" makefile is the place for specifying path Multiple Inclusion of a header file: multiple inclusion of a header file can have unexpected and unwanted effects. guarding pre-compiler code must be added to every header file. #ifndef _TMPhoneLine_H_ #define _TMPhoneLine_H_ ... Rest of Header File . .. #endif
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Alex X. Liu 3 Naming Conventions ± Function Names: The function name should be a concatenated string of words with the first letter of all word capitalized except for the first one. The name should describe everything the routine does. For a procedure name, use a strong verb followed by an object. Example: printReport(), calcMonthlyRevenues(), and repaginateDocument() For a function name, use a description of the return value. Example: cos(), nextCustomerID(), printerReady(), and currentPenColor() ± Avoid meaningless verbs. Some verbs are elastic, stretched to cover just about any meaning. Routine names like handleCalculation(), performServices(), processInput(), and dealWithOutput() don't tell you what the routines do. The exception would be when the verb "handle" was used in the specific technical sense of handling an event. Example: handleOutput() is bad, formatAndPrintOutput() is good. ± The verb is vague because the operations performed by the routine are vague. The routine suffers from a weakness of purpose, and the weak name is a symptom. If that's the case, the best solution is to restructure the routine and any related routines so that they all have stronger purposes and stronger names that accurately describe them. ± The properties of a class should be accessible through functions named: getSomething(), setSomething(), isSomething(), Alex X. Liu 4 Class Names ± The name is a concatenated string of words with the first letters of all words capitalized. For example: FocusEvent, DeviceContext, Customer.
Background image of page 2
3 Alex X. Liu 5 Variable Names ± Variable names are a concatenated string of words with the first letter of all word capitalized except for the first one. The name chosen should clearly represent the content of the variable. For example: windowHandle, eventConsumed, index. ± All variables that are a member of a class should have a "m_" prefix. For example: m_windowHandle, m_eventConsumed, m_index. ± Constant variables should follow the same standard as C++
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/14/2009 for the course CSE 335 taught by Professor Kraemer during the Fall '08 term at Michigan State University.

Page1 / 8

AlexLecture_ProfessionalC++Coding - Professional C+ Coding...

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

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