Skip to content

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.

@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 126 to 139
Use GEOS tensor types for geometric and mechanical calculations:

.. list-table:: GEOS Tensor Types
:header-rows: 1
:widths: 30 70

* - Type
- Description
* - ``R1Tensor``
- 3D vector (real64)
* - ``R1Tensor32``
- 3D vector (real32)
* - ``R2SymTensor``
- Symmetric 6-component tensor (Voigt notation)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we can expand a bit on why tensor are in use and not their vector counter part

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have a suggestion? I have an idea but I think not precise enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a reference to wikipedia article, as we discussed of it in person, I suppose it is resolved.

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?

Comment on lines 1088 to 1108
Memory Management Rules
---------------------------------

Generalities
^^^^^^^^^^^^^^^^^^^^

- **Minimize dynamic memory allocation** as much as possible, particularly in performance-critical code,
- For frequently allocated/deallocated objects, **consider memory pools**,
- For containers with known size, **reserve capacity upfront**.

Be Const / Constexpr
^^^^^^^^^^^^^^^^^^^^

**Use ``const`` and ``constexpr`` when possible**, enabling:

- **Compiler optimization,** enables better code generation by giving constraints to the code,
- **Code safety,** prevents accidental modification for constant contexts,
- **Show code intention,** make code more readable.

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.

Same as above, it sounds like very high level advises, maybe better to relocate in another doc ?

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 understand your feeling, and I think the same, strictly forbid useless mutability is a choice, thus a rule.
As it is a rule, it can give strict guidelines when reviewing code.
It is indeed a quite common one, but not enforced in all C++ applications.

I could put the reasons of rules in a foldable block to improve document readability.

I stay open to your feedback, do still you think that it should be moved?

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 the document could be two documents or main parts.

  • One high level C++ do/don't we choose and want to enforce (not sure it is doable).
  • One other that is more Domain Specific because GEOS's is using RAJA+CHAI and macros, and this is design/interface

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think of restructuring as follow:

  • Code Rules
    • Coding Practices
      • memory
      • perf
      • validation / precision
      • ⁠architecture
    • GEOS Features
      • typing
      • documentation
      • testing
      • logging
      • error managment
      • parallelism
      • perf
      • physics-specific

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree this'd be a good splitting 👍

@MelReyCG
Copy link
Contributor Author

MelReyCG commented Dec 3, 2025

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


The rule is generalizable to ``string_view`` for strings, but not applicable in GPU context.

Why Use Views?
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Why Use Views?
**Rationale:**

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't that less meaningful?

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not love "Rationale" but it has been used before in the document. I just put it here again for consistency. Feel free to revert, but then keep it consistent throughout.

Copy link
Contributor Author

@MelReyCG MelReyCG Dec 30, 2025

Choose a reason for hiding this comment

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

I added "Why?" dropdown sections for all of those, it is now consistent.

@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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants