Hacker News new | ask | show | jobs
by clusmore 3535 days ago
I agree that setter properties are often a code smell, but getter properties are nice for calculated fields. As a very simple example, consider the following (C#):

  class Circle
  {
    public Circle(int radius) { Radius = radius; }
    public int Radius { get; }
    public int Diameter => Radius * 2;
  }
1 comments

Diameter is a nice example of a getter property. However you could change radius to simply

    public int Radius;
I think you mean

    public final int radius;