Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a modified JB #200

Open
9 of 12 tasks
Tracked by #146
tiawl opened this issue Apr 28, 2024 · 0 comments
Open
9 of 12 tasks
Tracked by #146

Use a modified JB #200

tiawl opened this issue Apr 28, 2024 · 0 comments
Assignees
Labels
generator Related to the generator
Milestone

Comments

@tiawl
Copy link
Owner

tiawl commented Apr 28, 2024

Most of the time, JB is described as an anti-pattern. Getters and Setters kills the encapsulation by making private attributes public. In the case of a OOP language, this is something we have to think twice when considering JB. However, in the case of Zig, there no OOP and there are (and will be) no private attributes for structs.
With this state of the art in mind, we consider that using JB should improve maintainability.
Here the accepted proposal of a modified JB:

  • A struct should have:
    • mandatory getters: NEVER use attributes outside of getters
    • prefixed attributes (with __): to make an easy distinction between attrbutes and methods: NEVER use attributes outside of getters and init ()
    • mandatory init: NEVER use a struct constructor outside of init function
    • immutable setters: NEVER mutate the value of an attribute (outside or inside the struct), ALWAYS build & return a new object from the struct

[TODOLIST] Make those changes in:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Related to the generator
Projects
None yet
Development

No branches or pull requests

1 participant