This guide defines documentation standards for the Entropy Engine project. Our goal is clear, practical documentation that helps developers understand and use the code effectively.
- Be Concise - Aim for 3-5 lines of documentation for most methods
- Be Practical - Focus on what users need to know to use the code
- Include Examples - Show real usage with compilable code snippets
- Avoid Redundancy - Don't repeat what the code already makes clear
/**
* @brief One-line summary of what this does
*
* 2-3 lines explaining when/why to use this. Focus on practical usage,
* not implementation details.
*
* @param paramName What this parameter controls
* @return What you get back and when it might be invalid/empty
*
* If this code is non-obvious in its usage, provide an example.
* @code
* // Practical usage example
* auto result = someFunction(value);
* if (result.valid()) {
* processResult(result);
* }
* @endcode
*/- @brief explaining internal purpose
- Why it's private (only if non-obvious)
- Key assumptions about object state
- Invariants it maintains
- Constructors/Destructors - Resource allocation and cleanup behavior
- Complex algorithms - Step-by-step explanation if non-trivial
- Thread safety - For example: "Can be called from any thread"
- Code examples - Always include for non-trivial functionality (worth the space!)
- Simple getters/setters - One line is enough. Perhaps even consider if you need to document these if it's extremely obvious what they do.
- Internal methods - Focus on purpose, not implementation
- Parameter descriptions - One line unless special behavior
- Member variables - One-line inline comments
- Performance claims without measurements ("fast", "efficient", "optimal")
- Assumptions about typical usage without data
- Teaching comments about general concepts
- Redundant explanations of why something is const/static/private
- Implementation trivia that doesn't affect usage
- Implementation comments (// comments) - These are for maintainers, not API docs
- Code examples - Never remove these, they're essential for understanding
- Critical details - Keep constructor/destructor behavior, thread safety notes
/**
* @brief Gets the count of active items in the container
*
* This method returns the number of items that are currently active
* in the container. It's very efficient with O(1) complexity because
* we maintain a counter. This is const because it doesn't modify state,
* which is important for const-correctness. The counter is atomic for
* thread-safety. This method is commonly used in high-performance scenarios
* where you need to quickly check how many items are active.
*
* @return The number of active items (typically 1000-5000 in production)
*/
size_t getActiveCount() const { return _activeCount; }/**
* @brief Gets the count of active items
* @return Number of items currently marked as active
*/
size_t getActiveCount() const { return _activeCount; }/**
* @brief Schedules a contract for execution
* @param handle Contract to schedule
* @return Success or failure reason
* @note Called internally by WorkContractHandle::schedule()
*//**
* @brief Checks if the container is empty
* @return true if no elements are present
*//**
* @brief Creates a work contract with the given function
*
* The returned handle controls when the work runs. Work functions
* should capture any needed data in the lambda.
*
* @param work Function to execute (must be thread-safe)
* @return Handle to the contract, or invalid if at capacity
*
* @code
* auto handle = group.createContract([data]() {
* processData(data);
* });
* @endcode
*//**
* @brief Lock-free work contract pool for task scheduling
*
* Manages work contracts that can be scheduled and executed by worker threads.
* Supports thousands of concurrent tasks without locks. Use with WorkService
* for multi-threaded execution or executeAll() for single-threaded.
*
* @code
* WorkContractGroup group(1024);
* auto handle = group.createContract([]() { doWork(); });
* handle.schedule();
* group.wait();
* @endcode
*/Each header should start with:
/**
* @file Filename.h
* @brief One-line description of this component
*
* This file contains [main class/functionality]. It provides [key capability]
* for [what part of the system].
*/private:
std::atomic<size_t> _activeCount{0}; ///< Currently active items
std::vector<Item> _items; ///< Main storage container
mutable std::mutex _mutex; ///< Protects item modificationsGood documentation answers three questions:
- What does this do? (brief)
- When should I use it? (explanation)
- How do I use it? (example)
Keep it concise. If you can't explain it in 3-5 lines, consider whether the API itself is too complex.