IMP Manual
for IMP version 2.9.0
|
To ensure code consistency and readability, certain conventions must be adhered to when writing code for IMP. Some of these conventions are automatically checked for by source control before allowing a new commit, and can also be checked yourself in new code by running check_standards.py.
All new code should also conform to the previously-described naming and interface conventions.
All C++ headers and code should be indented with 2-space indents. Do not use tabs. cleanup_code.py can help you do this formatting automatically.
All Python code should conform to the Python style guide. In essence this translates to 4-space indents, no tabs, and similar class, method and variable naming to the C++ code. You can ensure that your Python code is correctly indented by using the cleanup_code.py script.
In addition to the previously-described naming and interface conventions, developers should be aware that
IMP
.SpecialVector
class could be implemented in SpecialVector.h
and SpecialVector.cpp
separated_by_underscores
, for example container_macros.h
separated_by_underscores
and should not have a file extension (such as .py
). (Note also that since tools are installed, care should be taken to give them non-generic names so they don't conflict with other programs users may have installed on their system. Also consider using IMP::CommandDispatcher to provide a single command line interface to many individual Python scripts, rather than making each one a command line tool.)Name
using a Names
. Declare functions that accept them to take a NamesTemp
(Names
is a NamesTemp)
. Names
are reference counted (see IMP::Object for details); NamesTemp
are not. Store collections of particles using IMP::ParticleIndexes, rather than using IMP::Particles or decorators.double
type. (In most cases on modern 64-bit systems, float
isn't any more efficient.) Use the IMP::Float type (and derived types, such as IMP::FloatPair) only to work with floating-point attributes of IMP::Model objects. (Similarly, use int
and std::string
for integer and string data, except for accessing IMP::Model attributes where the IMP::Int and IMP::String types should be utilized.)std::vector
but adds extra functionality, and turns on bounds checks when IMP is built in debug mode.All values must have a show
method which takes an optional std::ostream
and prints information about the object (see IMP::Array::show() for an example). Add a write
method if you want to provide output that can be read back in.
Classes and methods should use IMP exceptions to report errors. See IMP::Exception for a list of existing exceptions (click on the "Inheritance diagram" link on that page). See checks for more information.
Use the provided IMPMODULE_BEGIN_NAMESPACE
, IMPMODULE_END_NAMESPACE
, IMPMODULE_BEGIN_INTERNAL_NAMESPACE
and IMPMODULE_END_INTERNAL_NAMESPACE
macros to put declarations in a namespace appropriate for module MODULE
.
Each module has an internal namespace, eg IMP::atom::internal
, and an internal include directory IMP/atom/internal
. Any function which is
should be declared in an internal header and placed in the internal namespace.
The functionality in such internal headers is
As a result, such functions do not need to obey all the coding conventions (but we recommend that they do).
IMP now turns on C++ 11 support when it can. However, since compilers are still quite variable in which C++ 11 features they support, it is not advisable to use them directly in IMP code at this point. To aid in their use when practical we provide several helper macros:
IMP_OVERRIDE
inserts the override
keyword when availableIMP_FINAL
inserts the final
keyword when availableMore will come.