Efficiently Structuring a Program in C++

Hello,

Can any veteran programmers recommend books or give advice/tips for a beginner ordering (structuring) their first few programs.

Regards,

Dobush
closed account (zb0S216C)
http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list

Dobush wrote:
"advice/tips for a beginner ordering (structuring) their first few programs."

-- Don't use global variables until you understand how they can be used properly. Most teachers use global variables without informing their students about the risks associated with them.

-- Utilise function prototyping.
-- Use the standard library when possible.
-- Try to avoid "using namespace std" and use "std::something" instead.
-- Avoid "char const *" for strings and use "std::string" instead.
-- Avoid arrays and use "std::vector" if possible.

-- Use comments to annotate your programs. For example, document each variable/object so you know why it's there, what it's used for, etcetera. Do this also for functions. After a while, this sort of documentation may not be necessary -- it depends on the project's complexity.

-- Use proper indentation when you code for easier reading.
-- Use "int main( )" and avoid "void main( )".
-- Always "return" something from "main( )".
-- Never call "main( )". Ever!
-- Avoid "goto" unless it's confined to a very small area
-- Always check for null-pointers before dereferencing them.
-- Use "const" (or "constexpr") instead of "#define" for constant data.

I don't know what you know about C++ so some of the above may mean nothing to you.

Wazzak
Last edited on
Topic archived. No new replies allowed.