Re: Argument validation as a JSM?

2014-05-19 Thread Jason Orendorff
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) {

Re: Argument validation as a JSM?

2014-05-19 Thread Tobie Langel
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) ||

Re: Argument validation as a JSM?

2014-05-19 Thread ajvincent
On Monday, May 19, 2014 11:19:33 AM UTC-7, Jason Orendorff wrote: But I'm not the one you have to convince. Who is? :-) ___ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform

Argument validation as a JSM?

2014-05-15 Thread ajvincent
I've been thinking a bit about writing a JSM for validating arguments coming into a function. The first part would be the set of assertion functions: * a non-empty string * a whole number * a positive number * a non-negative number * a function * instanceof * typeof * member

Re: Argument validation as a JSM?

2014-05-15 Thread David Rajchenbach-Teller
I remember opening a bug for this ~2.5 years ago. The answer was that most of these assertions are so trivial to write that putting them in a module would actually make reading the code harder than simpler. I don't think the situation has changed since then. Cheers, David On 15/05/14 08:04,

Re: Argument validation as a JSM?

2014-05-15 Thread Mike de Boer
I agree with what David said; it usually makes the code harder to read, but that also greatly depends on the exposed API of the library. Assertions are a widely-known, commonly accepted way to do in-method validation. I quite recently wrote Assert.jsm

Re: Argument validation as a JSM?

2014-05-15 Thread ajvincent
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

Re: Argument validation as a JSM?

2014-05-15 Thread Ms2ger
On 05/15/2014 05:58 PM, 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) {