-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid floating-point number for @version
#296
Comments
About version not being floating-point number: what happens after version |
@version
@version
It's unlikely that we'll never need to change the version number, although subsequent versions may choose to include it. The primary use for it is so that 1.0 processors will fail when they see it, as the context processing wasn't adequately constrictive in 1.0. It is in 1.1, so that if something changes in the future, a 1.1 processor would detect and fail. Note that JSON numbers may be represented as floating point internally after conversion to a native form, but the JSON spec doesn't require this. If an implementation had a problem with a floating point conversion, they could handle this as they see fit, and really simply check to see if it exists without parsing the number. IIRC, there are no test for numeric values other than |
There should be a FAQ somewhere for this. The question will come up often. Where do we put something like that? I've never liked the non-string version either, but the most succinct alternatives were not much better. I think It's much more likely we'll have @lo48576 Did you have a real situation where a simple |
Yes, but I think usual JSON-LD processors may use third-party library to parse JSON document into native structure, and the raw string representation might not be available after the parsing.
Tuple (
JSON-LD 1.1 is currently working draft and updated frequently, and I think it is the best if the spec for
Currently, no. From point of view of code quality, naive comparison are almost always discouraged.
|
I'm trying to develop JSON-LD processing library in Rust programming language, and I'm worried about situations below.
Binary internal representation and compatibility among future processorsString representation has some overhead (parsing, delimiters, whitespaces, etc.), so applications using JSON-LD may put binary representation of JSON-LD document (in CBOR or BSON, for example) to DB. Multiple way to parse or create floating point number in a programFloating point numbers can be created by different algorithm in a single program, typically by compiler and by JSON parser. It is discouraged to check equality of floating point numbers in naive wayComparison Complex comparison makes it hard to make justificationIf I use |
I should think that JSON-LD For most purposes, version values should be treated as strings (not as numbers), and only converted to numerics when necessary to order by version -- and as noted above, this must be done segment-by-segment, or the ordering will be incorrect (putting Any other handling of version values is fraught with peril, as the above discussion highlights. (It's probably not relevant to JSON-LD, per se, but the issues become clearer and potentially more problematic when you get to 3 and 4 segment versions, e.g., |
The choice of a numeric datatype for As I also mentioned, a particular numeric value should not be important, and I don't see that future JSON-LD specifications would need to lean on this mechanism, as the 1.1 spec now is very explicit on what keys can be in a term definition, and what values While We could consider that any numeric value could be used, which would accomplish the same objective. If 1.0 had been more prescriptive on what things can be in a context or a term definition, we wouldn't have need to introduce |
Well, that would put a future JSON-LD WG in the same uncomfortable situation as the one we started with: if they want to mark some strictly 1.2 or 2.0 data, and be sure that any 1.0 or 1.1 processor rejects it, they would need to introduce |
By locking down what can be in a context or term definition, and elsewhere in the expansion algorithm, we don’t need @Version announcement to detect these features. A 1.1 processor would reject things introduced in a future version. If we had done this in 1.0, we could have avoided |
@gkellogg Locking down contexts and term definitions does not entierly solve the problem. There might be situations were the only difference is in the data, not in the context. Imagine that JSON-LD 2.0 introduce a way to annotate triples with properties (alla Property Graph). This could be done this way:
Here, the new keyword Except for the 2.0 version, this data is accepted by a 1.1 processor, but the Of course, some new keywords might be safely ignored, that is why (I think) we decided to ignored unknown keywords rather than rejecting them systematically. But future versions should have a way to make their data unacceptable by prior processors. |
@pchampin Of course, you're correct. To be complete, we'd also need to make those keys illegal outside of the context, which would violate what we were trying to achieve in the first place. Living with Regarding semantic versioning (@TallTed), in principle, I agree, but this is the mechanism we're left with due to issues in 1.0. I don't see too much interest in changing to use an array form, such as |
This issue was discussed in a meeting.
View the transcript@version and floating point valuesRob Sanderson: #296 Rob Sanderson: #297 Ivan Herman: we have voted for a feature freeze a long time ago. … We shouldn’t change the version format now; … this is not a bug, this is a feature request. Rob Sanderson: as I understand, the argument against a floating point value is that … implementations might not do the right thing when comparing 1.1 to 1.1 . … So that could be considered as a bug. Gregg Kellogg: I don’t see this as a feature request; it raises a potential problem with the spec. … That said, I don’t think we should change it. David I. Lehn: I stand by my comment that we should add a FAQ for this Gregg Kellogg: The argument is described in details in the issue. … One argument is that CBOR internal representation may cause problem. … But I’m not for changing it. Benjamin Young: I think we should add a note, to warn implementers against a naive handling of this number. Rob Sanderson: +1 to gkellogg – we don’t put implementation considerations in the spec Gregg Kellogg: in JSON it is unambiguous. … The problem arises when it is converted to an internal representation, … which is an implementation problem. Benjamin Young: That’s why a note might be appropriate. Gregg Kellogg: agreed Rob Sanderson: I would suggest that such a note appear in the Best Practices document. … Adding implementation notes in the spec seems like a slippery slope. Ivan Herman: +1 to azaroth Action #1: add note on representation of @version not being semantic versioning, and noting issues with comparing floating point values (Gregg Kellogg)Gregg Kellogg: it seems a little trivial for BP. … And the BP document is more targeted at data publishers than implementers. Proposed resolution: Reject syntax#296 won’t fix as the spec isn’t broken, but add a note in the spec about implementation concerns (Rob Sanderson) Rob Sanderson: +1 Ivan Herman: +1 Pierre-Antoine Champin: +1 Dave Longley: +1 David I. Lehn: +1 Gregg Kellogg: +1 Benjamin Young: +1 Resolution #1: Reject syntax#296 won’t fix as the spec isn’t broken, but add a note in the spec about implementation concerns |
Closed by #301 |
JSON-LD processors are required to check
@version
value if it is found at appropriate place, but floating-point number comparison is unnecessarily complex for this purpose.IEEE 754 floating point number cannot represent exact
1.1
, and programs may use various (not same) representation very close to 1.1 (but not exact 1.1).This can make straightforward implementation (for example doing
if (version == 1.1) { ... }
) to fail checking version correctly.To deal with this problem, processors are forced to compare values in complex way (such as
if (version >= 1.1 - EPSILON && version <= 1.1 + EPSILON) { ... }
).JSON-LD version is neither a real number nor a floating-point number.
I think it should be string
"1.1"
or something exactly representable value, instead of floating-point number.The text was updated successfully, but these errors were encountered: