I have just had an eye at the json-schema github repo and saw this change.
I disagree with this for two reasons, one practical, and the other logical:
* the practical one: integers are used very often in JSON, as much as,
if not more, than decimal numbers;
* the logical one: ANY number, be it decimal or integer, is divisible
by 1, which means you cannot tell apart integers from numbers this
way! Or this means you make { "divisibleBy": 1 } a special case!
I'm sorry to put it so bluntly, but... Not a smart choice, to my eyes.
--
Francis Galiegue, fgal...@gmail.com
"It seems obvious [...] that at least some 'business intelligence'
tools invest so much intelligence on the business side that they have
nothing left for generating SQL queries" (Stéphane Faroult, in "The
Art of SQL", ISBN 0-596-00894-5)
Hello,
I have just had an eye at the json-schema github repo and saw this change.
I disagree with this for two reasons, one practical, and the other logical:
* the practical one: integers are used very often in JSON, as much as,
if not more, than decimal numbers;
* the logical one: ANY number, be it decimal or integer, is divisible
by 1, which means you cannot tell apart integers from numbers this
way! Or this means you make { "divisibleBy": 1 } a special case!
I have some other definition of "awesome"...
OK, tell me, with this new scheme, how would you define even numbers?
Short answer: you can't.
OK, tell me, with this new scheme, how would you define even numbers?
Short answer: you can't.
I had the same feeling about the divisibleBy(1) 'function.' All
numbers are divisible by one and this doesn't logically lead to an
integer value. I have a feeling that decimal *precision* may be the
better term for this. The divisibleBy(1) thing just feels wrong.
My point is simple: integer is a nice, simple way, of telling that the
entity is a number without any decimal digit. This allows JSON Schema
implementations to process numeric data efficiently. And computers are
much faster at dealing with integers than they are with decimals. And
having to specify disivibleBy to constrain the number type is not only
counterproductive, it is unnatural, illogical _and_ ineffective. The
fact that JSON itself does not distinct between integers and numbers
is not relevant. This is JSON Schema, not the JSON specification.
>>
>> OK, tell me, with this new scheme, how would you define even numbers?
>> Short answer: you can't.
>
>
> Are you kidding? divisibleBy: 2, of course. This narrows the numeric value
> space just as minimum or maximum does. Now, if you'd said "there's no way to
> define odd numbers" you'd be right. But presumably you find this acceptable
> as this is how it is today.
>
4.4 is divisible by 2. 4.4 is not an even number.
> But you didn't actually address any of the points I made. So I repeat
> myself: 1 is already inescapably special with regard to divisibleBy, as is
> 0. Why do you think otherwise? And why do you assume first class integer
> support should be automatic when JSON itself eschews integers?
>
See above as to why JSON not defining integers or numbers is
irrelevant to my eyes. And again, 1 is special since for any real
number n, 1 divides n. Any REAL number. Everybody knows that. Why
going against the common logic? XSD has done enough damage, let's not
go this way. As to 0, it is not allowed for divisibleBy, so the point
is moot.
Just for "fun", I have implemented it this way for a project of mine
which deals with tens of megabytes of data: since I have to process
one keyword more, I lose 10% in performance. Far from being
negligible. And this is in spite of the fact that I cache validators.
Actually there is:
{
"type": "integer",
"disallow": [ { "divisibleBy": 2 } ]
> Now, if you'd said "there's no way toActually there is:
> define odd numbers" you'd be right.
>
{
"type": "integer",
"disallow": [ { "divisibleBy": 2 } ]
}
Using totalDigits and fractionDigits, I would guess the simplest way
to define the desire for an integer number would be to set
fractionDigits to zero. Is this correct?
I like the idea of fractionDigits more than divisibleBy. What benefit
is there to having totalDigits? Would minimum/maximum cover that
functionality?
What would be their default value? -1 to say "I don't care"?
On Thu, Dec 29, 2011 at 16:31, Chris Grant <cdgo...@gmail.com> wrote:What would be their default value? -1 to say "I don't care"?
> Using totalDigits and fractionDigits, I would guess the simplest way
> to define the desire for an integer number would be to set
> fractionDigits to zero. Is this correct?
>
> I like the idea of fractionDigits more than divisibleBy. What benefit
> is there to having totalDigits? Would minimum/maximum cover that
> functionality?
>
(I'm not sure I understand "metaschema", can you elaborate?)
Well, I can see the interest for fractionDigits: setting it to 0 would
indeed define an "integer" as it is currently defined.
As the draft currently stands anyway, integer is gone. I am reluctant
to make it completely gone from my implementation (for draftv4 and up
only, obviously) until this matter is settled...
Also, I see that "format" is gone. This is another tricky one... I
actually like format a lot, since it defines precisely the contents of
an item (maybe I say this because I fully implement them all, except
for "style" -- yes, I even have "color" covered fully). Is it
scheduled that it will be reintroduced in some other separate
specification?
(I'm not sure I understand "metaschema", can you elaborate?)On Thu, Dec 29, 2011 at 18:27, Dean Landolt <de...@deanlandolt.com> wrote:
>
>
> On Thu, Dec 29, 2011 at 11:42 AM, Francis Galiegue <fgal...@gmail.com>
> wrote:
>>
>> On Thu, Dec 29, 2011 at 16:31, Chris Grant <cdgo...@gmail.com> wrote:
>> > Using totalDigits and fractionDigits, I would guess the simplest way
>> > to define the desire for an integer number would be to set
>> > fractionDigits to zero. Is this correct?
>> >
>> > I like the idea of fractionDigits more than divisibleBy. What benefit
>> > is there to having totalDigits? Would minimum/maximum cover that
>> > functionality?
>> >
>>
>> What would be their default value? -1 to say "I don't care"?
>
>
> Perhaps, though -1 would really just be a sigil, no different than if their
> domain was defined as nullable. Amusingly you'd still want type: "integer"
> or something like it to define their domain in the metaschema :)
>
> Again, integers and reals are different beasts, sibling types perhaps (they
> have a different algebra). I never said I don't want integer just that
> integer can't be defined in a vacuum, and defining it is a bit of a slippery
> slope.
>
Well, I can see the interest for fractionDigits: setting it to 0 would
indeed define an "integer" as it is currently defined.
As the draft currently stands anyway, integer is gone. I am reluctant
to make it completely gone from my implementation (for draftv4 and up
only, obviously) until this matter is settled...
Also, I see that "format" is gone. This is another tricky one... I
actually like format a lot, since it defines precisely the contents of
an item (maybe I say this because I fully implement them all, except
for "style" -- yes, I even have "color" covered fully). Is it
scheduled that it will be reintroduced in some other separate
specification?
--
Francis Galiegue, fgal...@gmail.com
"It seems obvious [...] that at least some 'business intelligence'
tools invest so much intelligence on the business side that they have
nothing left for generating SQL queries" (Stéphane Faroult, in "The
Art of SQL", ISBN 0-596-00894-5)
--
You received this message because you are subscribed to the Google Groups "JSON Schema" group.
To post to this group, send email to json-...@googlegroups.com.
To unsubscribe from this group, send email to json-schema...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-schema?hl=en.
Which is itself a JSON schema ;)
I can see it defined with fractionDigits, not with "divisibleBy": 1. I
can even cook it up if you are interested.
So if practically is the goal (and I don't know if it is), the question still remains: is it more practical to spec "integer" in terms of other primitives (divisibleBy) or in its own terms entirely (perhaps also specifying "real")? Or would it be more practical to specify type: "integer" as an alias for type: "number", "divisibleBy": 1? This smells an awful lot like a macro expansion -- which would be awesome but probably not too practical :)
I'm sorry to put it so bluntly, but... Not a smart choice, to my eyes.
(instanceValue % divisibleBy) == 0
The value of 1 for the "divisibleBy" attributes represents the entire
set of all integers.
Attributes like "totalDigits", "fractionDigits", "precision",
"maxDecimal" have been removed/ignored in the past for they assume the
number is in base 10 format. The "divisibleBy" attribute is much more
powerful/flexible than these.
However, being that there is some confusion over the naming of this
attribute, and that it will now be used more frequently, perhaps a
more simple name such as "mod" might be more appropriate.
{"type":"number", "mod":1}
--Gary
This is very counterintuitive, especially since JSON defines numbers, and...
> Attributes like "totalDigits", "fractionDigits", "precision",
> "maxDecimal" have been removed/ignored in the past for they assume the
> number is in base 10 format.
it defines numbers as a sequence of digits between 0 and 9, with an
optional fractional part, which is also composed of digits between 0
and 9.
What are these if not base 10 numbers?
So, where is the problem?
"precision", as proposed, is much more sensible imho. But defining
integer doesn't cost much and is more powerful than divisibleBy alone,
not to mention more intuitive.
--
Francis Galiegue, fgal...@gmail.com
I'd tend to agree if we were working with fixed-point numbers here, but for all intents and purposes, they're floats. Precision doesn't make much sense (to me) because this assumes that all decimal numbers can be represented, which they can't.
Disagree. They are floats _for JavaScript_.
I do server side validation and can validate (nearly) any decimal
number, even with divisibleBy, in the "natural sense" (any real number
is divisible by another if the remainder of the division is 0) because
I use a language which doesn't have to make do with IEEE 754
limitatons like JavaScript (even a 64bit float cannot represent such a
simple number as 0.1).
And nothing in the spec restrict JSON Schema to JavaScript. In fact,
the closest mention to JavaScript in all the spec is the use of ECMA
262 for regexes -- which I also happen to do.
I'm strongly in favour of leaving the type 'integer' intact.
{"type":"number", "divisibleBy":1} is excessively verbose, ugly and
ambiguous.
In practice, real world JSON documents contain a lot of integers.
Browse the API docs for a some of the high profile, publicly
accessible APIs and you'll see that integers are commonplace. We use
integers heavily in our internal services (no surprise I'm sure),
hence we use {"type":"integer} regularly in almost all our JSON
schemas.
Having to define these properties using {"type":"number",
"divisibleBy":1} is downright tedious and doesn't feel right when
we're working with a format that is famously terse for good reason.
JSON Schema is already losing the brevity war when compared to
alternatives like JSchema. Integer may technically be a redundant type
but the practical implications of removing it are downright awful.
Omitting 'integer' from draft 04 would be a mistake. Can we have it
back in please?
Mathematically, 0.35 is divisible by 1. It's also devisable by 2, 3, 4, 4.35, ...
Integer is a proper mathematical set. Divisible by seems like an operator on that set.
http://en.wikipedia.org/wiki/Integer
So +1 to integer
Just to toss in my opinion: "type": "integer" should stay; "divisibleBy": 1 is weird.
In practical terms, WJElement (my JSON/JSON-schema library) doesn't even support floating-point values right now, since the need has yet to come up in any of our data. So, we treat "number" and "integer" the same. But come the day we do support floats, looking specifically for "divisibleBy": 1 instead of just looking at "type" to tell them apart would seem very hackish and weird.
--
Hello,I have just had an eye at the json-schema github repo and saw this change.
I disagree with this for two reasons, one practical, and the other logical:
* the practical one: integers are used very often in JSON, as much as,
if not more, than decimal numbers;
* the logical one: ANY number, be it decimal or integer, is divisible
by 1, which means you cannot tell apart integers from numbers this
way! Or this means you make { "divisibleBy": 1 } a special case!
I'm sorry to put it so bluntly, but... Not a smart choice, to my eyes.
--
Francis Galiegue, fgal...@gmail.com