On May 19, 2014, at 20:20, Jason Orendorff <jorendo...@mozilla.com> wrote:

>
> On 05/15/2014 10:58 AM, ajvinc...@gmail.com wrote:
>> Re: readability, that's something to think about, but when I write code like 
>> this:
>>
>>     if ((typeof num != "number") ||
>>         (Math.floor(num) != num) ||
>>         isNaN(num) ||
>>         (num < 0) ||
>>         Math.abs(num) == Infinity) {
>>       throw new Error("This need to be a non-negative whole number");
>>     }
>>
>> Well, it adds up.  :)  Even now I can replace the fifth condition with 
>> !Number.isFinite(num).
>
> FWIW, the newish function Number.isInteger covers every requirement here 
> except the fourth:
> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isinteger
>
> Also FWIW, I agree with your main point about boilerplate: even if you use 
> the nice standard library, you end up with
>    if (!Number.isInteger(num) || num < 0) {
>        throw new Error("handwritten error message");
>    }
> and I would rather see
>    checkArgIsNonNegativeInteger(num);
> But I'm not the one you have to convince.

Seems there should be existing JS libs for this if it is a common use-case.

--tobie
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to