Don't you the following as disadvantages of the Preconditions way ? * It forces you to write "p >= 0 && p <= 1" anytime. even it is a trivial condition, you might mistake and get the inequality sign in the wrong way, or forget the equals sign. * You are depended on guava, and I guess you can't do that on functions inside the CM.
On Tue, Jul 17, 2012 at 4:15 PM, Gilles Sadowski <gil...@harfang.homelinux.org> wrote: > On Mon, Jul 16, 2012 at 05:16:30PM -0700, Ted Dunning wrote: >> I ask about trivial routines like isProbability(). Why is that any better >> than just saying >> >> Preconditions.checkArgument(p >= 0 && p <= 1); >> >> or checkState if it isn't an argument? >> >> I would argue that checkArgument is more transparent. > > I'd say that it's not better or worse; it's different. :-) > > If the purpose is to throw a basic exception, I agree that Preconditions is > an elegant way, and is more concise (in vertical space) than an "if" block. > > However, we need to throw a specific exception and create a customized > and localizable error message. This already exists in CM and should be > modified. I don't think that it's worth it just to look like > "Preconditions". > In some place the effect and the look are already quite similar: E.g. line 55 > of > src/main/java/org/apache/commons/math3/analysis/integration/gauss/GaussIntegrator > > --- > MathArrays.checkOrder(points, MathArrays.OrderDirection.INCREASING, true, > true); > --- > > > Regards, > Gilles > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org