Skip to content

BCTH1Prior::IsValid #191

Open
Open

Description

@fredRos

@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

Activity

  1. greenwald commented on Oct 20, 2016

    @greenwald
    Contributor

    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.

    And it is used: in BCPrior

  2. added this to the 1.1 milestone on Oct 25, 2016
  3. fredRos commented on Oct 25, 2016

    @fredRos
    ContributorAuthor

    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

  4. greenwald commented on Oct 25, 2016

    @greenwald
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions