-
Notifications
You must be signed in to change notification settings - Fork 910
Revisit public vs private member variable access qualifiers #869
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
Comments
Yep. I think you're right |
Actually, it should be public, and we should remove the accessors. There's no reason to guard these members, as it's not possible to create an inconsistent state, so the encapsulation machinery provides only additional complexity for no real value. |
Note that in general we could do an encapsulation pass, as this is something we have scattered among our various classes. The way the code is structured, many of these are simple classes/structs with only helper methods, and no real state management to do. |
If we look at the v1.42.0, the original ray class was:
So I can see how today's kludge evolved. |
I added the additional We could convert such situations to use I do admit that the multiple public-public labels are unconventional. |
More and more (and this is a personal opinion), I chafe at the automatic getter-setter method for private member variables, when they are uniformly implemented in trivial fashion. It feels knee-jerk and a bit cargo-cultish to me, adds no additional real value or protection, and often adds a considerable about of useless glitter. For example, I'm now tempted to just do this:
Notes
|
Just found out that we need the |
Also, out of curiosity I tried just making all member variables |
We removed all structs from the codebase. We did it for good reason |
? The only thing |
I don't remember the specific conversation (and I don't really want to go looking for it), but we decided that we should unify as either all The c++-ism is pretty exclusive to that language. The specification differences between structs and classes are incredibly minor (and not a good interview question!), but they imply legions. For some reason I am feeling very strong about this one. |
I am perfectly content with:
|
Well, I look at that and see a |
I think it makes sense to revisit this across all of our classes/structs. My proposal:
|
So the One question here is whether the public member variables should be moved to the top of the class. I'm beginning to think they should be. |
Came back review our v4 issues, planning to argue for what we've already apparently agreed upon. Settable data at the top, followed by the public API. Private data and methods follow. Sweet. |
This includes a number of whole-codebase changes to tidy up some inconsistent aspects of our classes, and to firm up class interfaces. - If class clients are expected to write or read member variables, those variables must be public, and are listed at the top of the class, immediately after the leading `public:` specifier. Constructors follow, followed by other public methods. After this is the `private:` section, beginning with private member variables, and concluding with other private functions. - Some classes are effectively immutable. Such classes should generally not have a default constructor unless such an object has useful meaning or other utility. These are basically classes with useful constructors and a body of private resulting member variables. - Fix some indentation errors in the books in code listings. - Tweaked some blank line spacing. - Fixed some code listing highlighting. All code recompiled, all renders executed and validated. Resolves #869
This includes a number of whole-codebase changes to tidy up some inconsistent aspects of our classes, and to firm up class interfaces. - If class clients are expected to write or read member variables, those variables must be public, and are listed at the top of the class, immediately after the leading `public:` specifier. Constructors follow, followed by other public methods. After this is the `private:` section, beginning with private member variables, and concluding with other private functions. - Some classes are effectively immutable. Such classes should generally not have a default constructor unless such an object has useful meaning or other utility. These are basically classes with useful constructors and a body of private resulting member variables. - Fix some indentation errors in the books in code listings. - Tweaked some blank line spacing. - Fixed some code listing highlighting. All code recompiled, all renders executed and validated. Resolves #869
This includes a number of whole-codebase changes to tidy up some inconsistent aspects of our classes, and to firm up class interfaces. - If class clients are expected to write or read member variables, those variables must be public, and are listed at the top of the class, immediately after the leading `public:` specifier. Constructors follow, followed by other public methods. After this is the `private:` section, beginning with private member variables, and concluding with other private functions. - Some classes are effectively immutable. Such classes should generally not have a default constructor unless such an object has useful meaning or other utility. These are basically classes with useful constructors and a body of private resulting member variables. - Fix some indentation errors in the books in code listings. - Tweaked some blank line spacing. - Fixed some code listing highlighting. All code recompiled, all renders executed and validated. Resolves #869
This includes a number of whole-codebase changes to tidy up some inconsistent aspects of our classes, and to firm up class interfaces. - If class clients are expected to write or read member variables, those variables must be public, and are listed at the top of the class, immediately after the leading `public:` specifier. Constructors follow, followed by other public methods. After this is the `private:` section, beginning with private member variables, and concluding with other private functions. - Some classes are effectively immutable. Such classes should generally not have a default constructor unless such an object has useful meaning or other utility. These are basically classes with useful constructors and a body of private resulting member variables. - Fix some indentation errors in the books in code listings. - Tweaked some blank line spacing. - Fixed some code listing highlighting. All code recompiled, all renders executed and validated. Resolves #869
Looks like this line should be private rather than public for the ray class
raytracing.github.io/src/common/ray.h
Line 36 in 588b950
The text was updated successfully, but these errors were encountered: