|
|
|
|
|
by kibibu
4578 days ago
|
|
> instead of using setters/getters because it "gets in the way" In my opinion it genuinely does get in the way. I want to add a member variable to an object - in many languages (JS, C#, Python for example) you can just declare it and move along, knowing that you can switch it to a property later if you need special handling. In Java, however, for future maintenance I have to write a `public int getPaula()`, `public void setPaula(int brillant)`. This not only violates YAGNI, it slows things down in the physical "I have to type more" sense. |
|
Thankfully C# makes declaring getters and setters easy from the start, so it's not an issue to use them:
public int SomeField { get; private set; }
That gives you a public property called SomeField which can be retrieved, but which can only be set privately by the class. I'd hate having to write GetBlah and SetBlah; it's damn ugly.