In addition to correctness, solutions will be graded for style and
design. Detail is given below; but the quick list is
- meaningful identifiers
- format code nicely with spaces around operators
and no
tabs
- include a banner comment at the top of each source file that includes
your name and the assignment name
- document each class, function as discussed below; methods may need
documentation as defined in the writeup
- minimal scope for variables
- methods, classes have clear purpose, generally 15 lines or less
(including blank lines and comments)
- clear logic including not not exiting loops in the middle,
using goto, good exception processing, and minimal dead code
- code compiles with no warnings
In more detail:
Standards Specific to C and C++ Projects
- File names are to be all lower case. This ensures your projects will
build on Unix as well as Windows.
- Use the extensions .cpp and .h for C++ sources.
- Use -Wall in your C and C++ builds (to generate all warnings)
and ensure your code compiles with no warnings. In most cases, the
warnings indicate issues that make your code unstable.
- Avoid C libraries in C++ programs. In particular, do not
use printf, scanf, atoi, and other C functions
in C++ code. Generally use std::string over C-style
(null-terminated) strings, though in places we will require you to
use <cstring> operations like strcpy.
- Follow
the standard
structure for header files:
- Use #ifndef...#endif to ensure each header file is processed
at most once in each compilation unit.
- Do not include "using namespace XXX" declarations in header
(.h) files. It is fine to put this in a .cpp file.
- The first include in an implementation (.cpp or .c) file
needs to be the header file giving the interface. For instance, the
first include for mycontainer.cpp must
be mycontainer.h.
- Put includes for project-specific headers before standard
headers; for instance, mycontainer.h
before stdexcept.
- Use forward declarations (such as class Money;) where
possible to avoid including one header file in another.
- If forward declarations do not work and a piece of code depends
on a particular header, explicitly include that header. For example,
if a class uses string, then #include
<string> in the header file for that class, even though
the header file might include other header files that also
include string.
- Don't include
bits/stdc++.h
. This file is not part of
the standard template library and should only be used for internal
purposes.
- Generally separate interfaces from implementations, but it is
acceptable to define short, non-virtual methods in header files.
- In C++, use C++17 constructs where appropriate; for instance,
use nullptr rather than NULL.
Note there is no rule that only one class appear in a particular source
file.
Git Repositories
Some projects will require you to create Git repositories. Standards for
these:
- Do not push build products. In particular, never push
the build-Debug and related folders from Codelite. Every
Codelite project should
include a .gitignore with the content
build-*
This will capture the various builds, especially build-Debug
.
- The repository name needs to be all lower case letters with no
spaces. This facilites processing multiple repositories.
Note that using non-standard build tools generally leads to checking in
build products by mistake. Use the approved build tools.
Note:
By default, Windows is configured to not show extensions such as
"
.cpp" for file names. This causes problems for engineering
students. See
here
to enable showing extensions.