Skip to content

Commit 3694c47

Browse files
Initial developer guidelines (AcademySoftwareFoundation#2632)
This changelist expands upon the original Coding Style and Unit Tests sections of CONTRIBUTING.md, adding an initial, more comprehensive set of Developer Guidelines.
1 parent 6f8b18b commit 3694c47

File tree

1 file changed

+102
-2
lines changed

1 file changed

+102
-2
lines changed

CONTRIBUTING.md

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,96 @@ in the ASWF Slack or in TSC meetings before any PR is submitted, in order to
189189
solicit feedback, build consensus, and alert all stakeholders to be on the
190190
lookout for the eventual PR when it appears.
191191

192-
### Coding Conventions
192+
### Developer Guidelines
193+
194+
The following guidelines represent coding standards that we strive to follow
195+
in the MaterialX project. While not all existing code may adhere to these
196+
standards yet, we encourage all new contributions to follow these practices,
197+
and we welcome incremental improvements to bring existing code into alignment
198+
with these guidelines.
199+
200+
#### Naming Conventions
201+
202+
Class names should use PascalCase, as in `NodeGraph` or `ShaderGenerator`.
203+
Method names should use camelCase starting with a lowercase letter, for
204+
example `getNode` or `setName`. Protected and private member variables should
205+
use an underscore prefix, such as `_name` or `_parent`. Constants should be
206+
written in UPPER_CASE with underscores separating words, as in `EMPTY_STRING`
207+
or `CATEGORY`. Type aliases should append appropriate suffixes to indicate
208+
their purpose, using `Ptr` for pointers, `Vec` for vectors, `Map` for maps,
209+
and `Set` for sets.
210+
211+
#### Static Constants and Class Organization
212+
213+
Class members should be organized in order of decreasing visibility: public,
214+
protected, then private. Static constants should be placed at the end of their
215+
respective visibility section. String constants should be defined in implementation
216+
files rather than headers to avoid One Definition Rule violations. The
217+
`EMPTY_STRING` constant should be used instead of empty string literals (`""`)
218+
for clarity and consistency.
219+
220+
#### Smart Pointer Conventions
221+
222+
Heap-allocated objects in the public API should always use `shared_ptr` for
223+
memory management. Type aliases should be defined for all shared pointers,
224+
following the pattern of `ElementPtr` for `shared_ptr<Element>`. Both mutable
225+
and const versions of these type aliases should be provided, e.g. `ElementPtr`
226+
and `ConstElementPtr`. Raw pointers should be avoided except when representing
227+
non-owning references within implementation details.
228+
229+
#### Const Correctness
230+
231+
Methods that do not modify an object's state should be marked as `const`.
232+
Accessor methods should provide const versions to enable their use on const
233+
objects. Type aliases following the pattern `ConstElementPtr` should be used to
234+
indicate read-only access through shared pointers. Parameters that should not
235+
be modified within a function should be declared as const.
236+
237+
#### Parameter Passing and Return Values
238+
239+
Strings and complex objects should be passed by `const&` to avoid unnecessary
240+
copies. Shared pointers should be passed by value since they are designed to
241+
be cheap to copy. When returning shared pointers, they should be returned by
242+
value rather than by reference. Methods should be marked as `const` whenever
243+
they do not modify the object's state.
244+
245+
#### Exception Handling
246+
247+
Exceptions should be used for exceptional conditions rather than for normal
248+
control flow. Custom exception types should be defined by inheriting from
249+
`Exception` to represent specific error categories. Exception messages should
250+
be descriptive and include relevant context to aid in debugging. All exceptions
251+
that may be thrown by a method should be documented using the `@throws` tag in
252+
the method's documentation. When catching exceptions, specific exception types
253+
should be caught rather than generic exceptions whenever possible.
254+
255+
#### Header Includes
256+
257+
Header includes should be written with angle brackets, with paths relative to
258+
the root source folder (e.g. `#include <MaterialXCore/Element.h>`). This
259+
ensures consistent include paths across the entire codebase, regardless of the
260+
location of the referencing file.
261+
262+
Each implementation file should include its corresponding header file first,
263+
so the first include in `Element.cpp` should be `Element.h`. This ensures that
264+
the header file is self-contained and doesn't accidentally depend on includes
265+
from other headers.
266+
267+
After the corresponding header, include blocks should be ordered hierarchically,
268+
with high-level modules listed before low-level modules (e.g.
269+
`MaterialXGenShader`, followed by `MaterialXFormat`, followed by
270+
`MaterialXCore`). This maximizes opportunities to catch missing dependencies in
271+
the high-level modules, which might otherwise be hidden at build time. Within
272+
include blocks, individual includes should be ordered alphabetically, providing
273+
a simple canonical order that is straightforward for developers to check.
274+
275+
In the interest of avoiding include cycles, developers are free to leverage
276+
forward declarations of classes that are trivially referenced within another
277+
header. In the interest of clarity and efficiency, developers are free to
278+
leverage transitive header includes, where low-level headers that have already
279+
been included by a high-level header do not need to be restated individually.
280+
281+
#### Coding Style
193282

194283
The coding style of the MaterialX project is defined by a
195284
[clang-format](.clang-format) file in the repository, which is supported by
@@ -200,7 +289,18 @@ file to automatically align the code to MaterialX conventions. When modifying
200289
existing code, follow the surrounding formatting conventions so that new or
201290
modified code blends in with the current code.
202291

203-
### Unit Tests
292+
#### Documentation Standards
293+
294+
All classes and methods in the public API should be documented with Doxygen
295+
comments. Classes should be documented with the `@class` tag, and structs with
296+
the `@struct` tag, followed by a brief description and any detailed
297+
documentation. Method documentation should include `@param`, `@return`, and
298+
`@throws` tags where applicable. Related methods should be grouped together
299+
using `/// @name GroupName` sections to improve readability. File-level
300+
documentation should be placed immediately after the copyright header using
301+
the `/// @file` directive.
302+
303+
#### Unit Tests
204304

205305
Each MaterialX module has a companion folder within the
206306
[MaterialXTest](source/MaterialXTest) module, containing a set of unit tests

0 commit comments

Comments
 (0)