On Sunday, 4 December 2016 at 15:30:22 UTC, vladdeSV wrote:

I have a question not directly related to D as it is with coding standards.

My issue at hand is if I have one variable for a class, which I want to be directly accessible for anything else, should it be
 1. public, or
 2. private, with @property get/setters?

From what I have been told is that variables should be private. But if I do not want to make any checks whatsoever when setting a variable, I see no benefit to the private approach.

Are there any other reasons to use get/setters?

Make the member variable public, if it serves your purpose.
If (and when) you feel like taking some control over setting and getting its value, you will upgrade it to @property setter/getter, making the actual member variable private. For most reasonable use cases the upgrade should pass with no problems.
If you envision such an upgrade possibility, try to keep away from taking your member variable address, and other not method-friendly operations, that might hold the upgrade back.

Reply via email to