You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@greenwald What exactly is the purpose of IsValid? It is not called inside BCTH1Prior. This means the input histogram is not checked! I suggest to make the check mandatory in the constructors and raise an exception if not valid. Why would one ever let an invalid object be created? Is this needed for priors?
I can implement the changes as I"m working on the class right now
It's a virtual member function of BCPrior. It doesn't only check validity of code objects but of the parameters of the given prior as well. For example, BCGaussianPrior checks that the mean and std. dev. are finite and that the std. dev. is positive. Since these parameters can be changed after the prior is created, we can't simply check only once in the constructor. BCTH1DPrior checks, among other things, that the values in the histogram are all greater than or equal to zero. Since the histogram can be changed after creation, the check must be performed again when needed.
I don't like this at all. One of the basic premises of good object-oriented code is that objects are always valid. This saves the developer checks in any number of places, and the user benefits from a strong guarantee. Whenever a users set something via a setter, we have to check that the update leaves the object in a usable state. Else throw an exception. The same is of course true for construction. The way it's done now is that IsValid is called only in BCPrior::GetBCH1D. What happens if I call a method on a BCPrior other than that? Undefined results for invalid input...
These principles are violated in parts of the old code but we should introduce these errors again. I regret not having checked this before when @greenwald introduced the BCPrior classes but there still is time to fix this
One option is to make the objects in effect constant. You set everything for a prior when you create it. If you need to change the prior, you simply delete the old prior and add a new one with the different values. Validity checking occurs in the constructor.
Otherwise we simply take it on faith that every user-defined prior is always valid and obeys that principle.
Activity
greenwald commentedon Oct 20, 2016
It's a virtual member function of
BCPrior. It doesn't only check validity of code objects but of the parameters of the given prior as well. For example,BCGaussianPriorchecks that the mean and std. dev. are finite and that the std. dev. is positive. Since these parameters can be changed after the prior is created, we can't simply check only once in the constructor.BCTH1DPriorchecks, among other things, that the values in the histogram are all greater than or equal to zero. Since the histogram can be changed after creation, the check must be performed again when needed.And it is used: in
BCPriorfredRos commentedon Oct 25, 2016
I don't like this at all. One of the basic premises of good object-oriented code is that objects are always valid. This saves the developer checks in any number of places, and the user benefits from a strong guarantee. Whenever a users set something via a setter, we have to check that the update leaves the object in a usable state. Else throw an exception. The same is of course true for construction. The way it's done now is that
IsValidis called only inBCPrior::GetBCH1D. What happens if I call a method on aBCPriorother than that? Undefined results for invalid input...These principles are violated in parts of the old code but we should introduce these errors again. I regret not having checked this before when @greenwald introduced the
BCPriorclasses but there still is time to fix thisgreenwald commentedon Oct 25, 2016
One option is to make the objects in effect constant. You set everything for a prior when you create it. If you need to change the prior, you simply delete the old prior and add a new one with the different values. Validity checking occurs in the constructor.
Otherwise we simply take it on faith that every user-defined prior is always valid and obeys that principle.