Skip to content

docs: Adding Code rules page#3915

Open
MelReyCG wants to merge 30 commits intodevelopfrom
docs/rey/code-rules
Open

docs: Adding Code rules page#3915
MelReyCG wants to merge 30 commits intodevelopfrom
docs/rey/code-rules

Conversation

@MelReyCG
Copy link
Contributor

@MelReyCG MelReyCG commented Nov 26, 2025

GEOS Code Rules

Aims at writing down the coding standards for GEOS, focusing on type safety, error handling, parallelism, and performance. Key principles include:

  • Type System
  • Memory Management
  • Error Handling
  • Parallelism
  • Performance
  • Memory / Safety
  • Architecture
  • Testing

These rules ensure code quality, consistency, and maintainability across the GEOS codebase.


This PR is before #3914

@MelReyCG MelReyCG self-assigned this Nov 28, 2025
@MelReyCG MelReyCG changed the title Docs/rey/code rules docs: Code rules Nov 28, 2025
@MelReyCG MelReyCG changed the title docs: Code rules docs: Adding Code rules page Nov 28, 2025
@MelReyCG MelReyCG marked this pull request as ready for review November 28, 2025 09:12
Copy link
Contributor

@jafranc jafranc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great ! Maybe there is the work of 2 docs there (or more 😄 )

Comment on lines 1013 to 1019
Additional Validation Guidelines
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Use ``setInputFlag()`` to mark parameters as ``REQUIRED`` or ``OPTIONAL``
- Use ``setApplyDefaultValue()`` to provide sensible defaults
- Use ``setRTTypeName()`` for runtime type validation (e.g., ``rtTypes::CustomTypes::positive``)
- Document valid ranges in ``setDescription()``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be in the Wrapper section ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels strange to me, as the wrapper section is for documentation requirement. My goal here is to precise validation rules. What do you think?

@MelReyCG
Copy link
Contributor Author

MelReyCG commented Dec 3, 2025

Thanks @jafranc for your feedback, I'll take them into account.

@MelReyCG MelReyCG modified the milestone: mmmmmmmmmç_ç7jk Dec 31, 2025
@MelReyCG
Copy link
Contributor Author

MelReyCG commented Jan 2, 2026

@jafranc @rrsettgast the rule page is now separated in two and correctly linked in the indexes

@MelReyCG MelReyCG added ci: run CUDA builds Allows to triggers (costly) CUDA jobs ci: run integrated tests Allows to run the integrated tests in GEOS CI labels Jan 5, 2026
Copy link
Contributor

@jafranc jafranc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great doc !!

**Avoid magic values**:

- **arbitrary values should not be written more than once**, define constants, consider using or extending ``PhysicsConstants.hpp`` / ``Units.hpp``,
- **Prefer to let appear the calculus of constants** rather than writing its value directly without explaination (constexpr has no runtime cost).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be tempted to include a smooth transition and link to the next page CodeGeosFeatures.rst

@MelReyCG MelReyCG added flag: no rebaseline Does not require rebaseline ci: run CUDA builds Allows to triggers (costly) CUDA jobs ci: run integrated tests Allows to run the integrated tests in GEOS CI and removed ci: run CUDA builds Allows to triggers (costly) CUDA jobs ci: run integrated tests Allows to run the integrated tests in GEOS CI labels Feb 2, 2026
- **Improves code safety,** preventing accidental modification for constant contexts,
- **Show code intention,** making code clearer.

Also, **mark methods const if the method is not designed to modify** the object state.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any recommendations on mutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice remark, I would feel like discouraging it but I see it is used at various locations (in favor of std::unique_ptrs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding a proposal:

Use of ``mutable``
------------------

``mutable`` **keyword usage is to avoid, excepted for specific patterns.**

Acceptable uses:

- **Thread synchronization primitives** (``std::mutex``, ``std::atomic`` for counters),
- **Caching** when it preserves logical constness, is thread-safe and clearly documented.

Avoid ``mutable`` for:

- Working around design issues (consider redesigning instead, i.e. splitting data structures),
- GPU-accessible data (creates host/device LvArray synchronization issues).

.. dropdown:: Why mutable is discouraged?
  :icon: info

  - **Breaks const methods contract:** Makes reasoning about code harder
  - **Thread-safety confusion:** ``const`` methods may not be thread-safe
  - **GPU incompatibility:** Can cause memory coherence issues with LvArray views


- **Hoist Loop Invariants**, move computations that don't change during iterations outside the loop.
- When it does not critically affect the code architecture and clarity, **fuse multiple related kernels to reduce memory traffic and launch overhead** (i.e., statistics kernels process all physics field at once).
- **Optimize Memory Access for Cache and Coalescing**. Access memory sequentially and ensure coalesced access, especially on GPUs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an example here would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a reference

Wrapper Documentation (User-Oriented)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

All data repository wrappers must be documented with ``setDescription()``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should encourage the specification of units where this makes sense.

Code Coverage
^^^^^^^^^^^^^

**Code coverage should never decrease.** New code contributions must maintain or improve overall code coverage.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think code coverage is based only on unit tests. Sometimes you ma add lines to fix a bug deep in a physics solver kernel that is only exercised by integrated tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, code cov should include integrated tests for this rule, I'll look how to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a remark in the meanwhile, and will proceed to do some tests in that way:

**Code coverage should never decrease.** New code contributions must maintain or improve overall code coverage.
Use Codecov to report untested code paths.

Currently, Codecov does not cover integrated tests execution but they should be taken into account, especially for minor physical kernel changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: run CUDA builds Allows to triggers (costly) CUDA jobs ci: run integrated tests Allows to run the integrated tests in GEOS CI flag: no rebaseline Does not require rebaseline flag: ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants