Ardour Code Style
This isn’t meant to be a strict listing of how your code must be. It is intended to help your code fit in with the rest of the Ardour codebase. This is the style that we have evolved to.
- Use tabs, not spaces for C++ code. Many of us use different indentation levels and this lets us view it as we like.
- That said, in Python files, use spaces, not tabs. Tabs seem to get a little messed up and spaces are more rigorous where it is important.
- Always use curly braces with if-, for-, do-, and while-statements.
- Since this is C++, use 0, not NULL.
- Similarly, use true/false, not TRUE/FALSE
- If an argument is being passed by reference, and cannot be null, always pass it as a reference, not a pointer.
- Prefer references over pointers
- For core (libardour) data structures, prefer shared_ptr to manage lifetimes
- Never, ever bind a shared_ptr to a sigc::signal. Always convert to a weak_ptr first.
- In GNU Emacs, use the “linux” C and C++ mode style
- When incrementing any STL iterator, always use
++iter, notiter++ - When looping over any STL container and performing operations on its contents or iterators to it, always consider the possibility that the operation may remove items from the container and thus invalidate the iterator you are currently operating on. The typical approach looks like this:
for (iter = container.begin(); iter != container.end(); ) { Iterator tmp; tmp = iter; ++tmp; .... do something ... iter = tmp; } - Because of the previous issue, generally prefer
std::listoverstd::vector. Erasing an element within a vector invalidates iterators to all later elements. Usevectoronly when confident that this issue doesn’t exist. - Class types have names like SomeClassType; variables have names like a_pleasant_name.
- Use
constwherever possible. - Throw
PBD::failed_constructorto exit constructors abnormally, and catch this exception. - That said, attempt to perform object initialization in an
initfunction that is called post-construction. See Meyers for more information on this pattern. - Use cstdio, not stdio.h style standard includes.
- Never declare
using namespacein a header. - Don’t even think of using Microsoft-style “Hungarian” notation
- When constructing paths (“filenames”) do not include separators (“/”) and try to use
Glib::build_filename() - Use Glib for any file-system related activities (creating/removing/testing for files)




