ATLAS C++ coding guidelines

Version 2.1

January 1, 2026

1 Introduction

This note gives a set of guidelines and recommendations for coding in C++ for the ATLAS experiment.

There are several reasons for maintaining and following a set of programming guidelines. First, by following some rules, one can avoid some common errors and pitfalls in C++ programming, and thus have more reliable code. But even more important: a computer program should not only tell the machine what to do, but it should also tell other people what you want the machine to do. (For much more elaboration on this idea, look up references on “literate programming,” such as  [1].) This is obviously important any time when you have many people working on a given piece of software, and such considerations would naturally lead to code that is easy to read and understand. Think of writing ATLAS code as another form of publication, and take the same care as you would writing up an analysis for colleagues.

This document is derived from the original ATLAS C++ coding standard, ATL-SOFT-2002-001  [2], which was last revised in 2003. This itself derived from work done by the CERN “Project support team” and SPIDER project, as documented in CERN-UCO/1999/207  [3]. These previous guidelines have been significantly revised to take into account the evolution of the C++ language  [4], current practices in ATLAS, and the experience gained over the past decade.

Some additional useful information on C++ programming may be found in the references  [513].

This note is not intended to be a fixed set of rigid rules. Rather, it should evolve as experience warrants.

2 Naming

This section contains guidelines on how to name objects in a program.

2.1 Naming of files

2.2 Meaningful names

2.3 Required naming conventions:

Generally speaking, you should try to match the conventions used by whatever package you’re working on. But please try to always follow these rules:

If there is no already-established naming convention for the package you’re working on, the following guidelines are recommended as being generally consistent with ATLAS usage.

3 Coding

This section contains a set of items regarding the “content” of the code. Organization of the code, control flow, object life cycle, conversions, object-oriented programming, error handling, parts of C++ to avoid, portability, are all examples of issues that are covered here.

The purpose of the following items is to highlight some useful ways to exploit the features of the programming language, and to identify some common or potential errors to avoid.

3.1 Organizing the code

3.2 Control flow

3.3 Object life cycle

3.3.1 Initialization of variables and constants

3.3.2 Constructor initializer lists

3.3.3 Copying of objects

3.4 Conversions

3.5 The class interface

3.5.1 Inline functions

3.5.2 Argument passing and return values

3.5.3 const correctness

3.5.4 Overloading and default arguments

3.5.5 Comparisons

3.6 new and delete

3.7 Static and global objects

3.8 Object-oriented programming

3.9 Notes on the use of library functions.

3.10 Thread friendliness and thread safety

Code that is to be run in AthenaMT as part of an AthAlgorithm must be “thread-friendly.” While the framework will ensure that no more than one thread is executing a given AthAlgorithm instance at one time, the code must ensure that it doesn’t interfere with other threads. Some guidelines for this are outlined below; but in brief: don’t use static data, don’t use mutable, and don’t cast away const. Following these rules will keep you out of most potential trouble.

Code that runs as part of an AthService, an AthReentrantAlgorithm, a data object implementation, or other common code may need to be fully “thread-safe;” that is, allow for multiple threads to operate simultaneously on the same object. The easiest way to ensure this is for the object to have no mutable internal state, and only const methods. If, however, some threads may be modifying the state of the object, then some sort of locking or other means of synchronization will likely be required. A full discussion of this is beyond the scope of these guidelines.

To run successfully in a multithreaded environment, algorithmic code must also respect the rules imposed by the framework on event and conditions data access. This is also beyond the scope of these guidelines.

3.11 Formatted output

3.12 Assertions and error conditions

3.13 Error handling

3.14 Parts of C++ to avoid

Here a set of different items are collected. They highlight parts of the language which should be avoided, either because there are better ways to achieve the desired results or because the language features are still immature. In particular, programmers should avoid using the old standard C functions, where C++ has introduced new and safer possibilities.

3.15 Readability and maintainability

3.16 Portability

4 Style

This section concerns the style, as opposed to the functionality, of the code.

4.1 General aspects of style

4.2 Comments

The comment includes the fact that it is the perpendicular distance.

5 Changes

5.1 Version 2.1 (Jan 1, 2026)

5.2 Version 2.0 (March 6, 2024)

5.3 Version 0.7 (Sep 18, 2019)

5.4 Version 0.6 (Dec 20, 2017)

5.5 Version 0.5 (Nov 21, 2017)

5.6 Version 0.4 (Nov 16, 2017)

5.7 Version 0.3 (Aug 23, 2017)

5.8 Version 0.2 (Aug 9, 2017)

References

[1]
D. Knuth, Literate programming, The Computer Journal 27, 97 (1984).
[2]
ATLAS Quality Control Group, ATLAS C++ Coding Standard, ATL-SOFT-2002-001, 2001.
[3]
CERN Project Support Team, C++ Coding Standard, CERN-UCO/1999/207, 2000.
[4]
[5]
C++ reference, (n.d.).
[6]
[7]
C++ Stories, (n.d.).
[8]
R. Grimm, Modernes C++, (n.d.).
[9]
H. Sutter, Guru of the week archive, (2008).
[10]
H. Sutter, Guru of the week archive, (2013).
[11]
S. Meyers, Effective C++, 3rd Edition (Addison-Wesley, 2005).
[12]
S. Meyers, Effective STL (Addison-Wesley, 2001).
[13]
E. Gamma, R. Helm, R. Johnson, and J. Vlissides, Design Patterns, Elements of Reusable Object-Oriented Software (Addison-Wesley, 1994).
[14]
E. Niebler, Range library for C++, (n.d.).
[15]
H. Sutter, A Pragmatic Look at Exception Specifications, C++ Users Journal 20, (2002).
[16]
A. Krzemieński, noexcept — what for?, (2014).
[17]
[18]

Authors: Scott Snyder (BNL) Shaun Roe (CERN) and the former ATLAS Quality Control group

Correspondence to snyder@bnl.gov.

Version 2.1, dated January 1, 2026, generated from https://gitlab.cern.ch/ssnyder/coding-rules/-/blob/master/rules.md by pandoc version 3.1.11.1 on January 9, 2026