-
Notifications
You must be signed in to change notification settings - Fork 244
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
Discussion on supporting mathematical operations in values #106
Comments
At first I was opposed to this, but I've written plenty of code like What's better? {
ms: 86400000, // one day
} or {
ms: 24*60*60*1000, // one day
} The first example appears like it doesn't require the parser to do any math, but the parser already has to do math to parse the number as base 10. The second example is easier to modify if you want to change it to e.g. 12 hours or 3 days. |
If this was done (and I feel divided about it too.. yet it would be really cool to have), should it also support parenthesis? I could imagine someone wanting to encode some sort of offset like |
This would need (or lead) to have support for constants or at least get that variables from the context... This will break compatibility with |
I think @amulware, correct me if I'm wrong, was just using variables to represent numeric literals. For example, you could have: { offset: (10 + 3) * 2 } but not the literal string: { offset: (base + increment) * stride } But it is an interesting concept to declare variables in a JSON5 file. Maybe we should start a new discussion on that. Also, see #91 for a discussion on why regular expressions have not been included in JSON5. |
Yes, I indeed only meant using literals, like @jordanbtucker says. Using variables like that would make things a lot more complicated and would have to be discussed in a lot of detail I imagine. |
@amulware you meaning is like { offset: (base + increment) * stride } not { offset: (10 + 3) * 2 } |
You confuse me. :D I was only asking about adding parenthesis to the list of supported operators, so I only care about:
The other things is a much bigger feature that needs to be designed very carefully, if it is a good idea at all. |
I've open an issue for discussion about the variables at #112. |
I too have been pretty hesitant about this feature request, because it's hard to know if it's gone just a bit too far beyond the line of "minimal but useful"... but I also agree with @jordanbtucker that I too have written I'd be okay with adding basic math operators. I would discourage adding |
I think the limit will be when people want to use functions or |
@aseemk Yes, I agree with |
@piranna: I totally agree that functions are beyond the line. A core tenet of JSON(5) is "it's just data", not executable code. @XGHeaven: agreed, thank you. Even with these basic operators, though, it does e.g. make supporting JSON5 in other languages harder. E.g. what is |
You said |
I consider RegExp data, too... ;-) They are the same as function declarations as far as they are not executed, but function declaration would be beyond the line too not only because they are language specific but also could be dangerous if executed (RegExp are not dangerous in that way).
Infinity is a valid float value in all languajes, including C/C++... |
I'm glad we're getting some great discussions around this. That's what I was hoping for 😄
I totally agree here. Let's keep things ES5 compliant.
I'd alter that statement by saying that
Oh no. Now the RegExp discussion is bleeding into this one. 😉 I do see the parallels, though.
Most languages have a way to check for |
Great discussion indeed! Very good food for thought. =) I'll keep chewing on it... |
This operations will not be executed on runtime but when parsed, so there's no problem the implementation wrap the operations on a try-catch block to capture these exceptions and set the value to infinite "by hand". Python support both Infinite and NaN, so...
Lol :-P Yes, there are parallels because it depends on the concepts of "what is data" and "what is executable code". After parsing we would get respectively a number or a RegExp object that both are not executables by themselves (a RegExp is a description that can be used to find some data, the same way a number can be used as an index on an array), so I would accept both. I would not accept functions because if they get parsed they are executables "as is", and there's almost no way to sanitize them and know they are secure (a RegExp could be bad written, but it's not a security thread or could erase data by itself...).
PHP sucks, but not so much... ;-) |
No one was saying that it can't be done in those languages. @aseemk's point was that more work would need to be done in those languages to support JSON5 with math features. In Python, you can't just parse a The more complex you make a specification, the more work that needs to be done to implement it, and the less it actually gets implemented.
I know PHP supports |
Supporting functions is not just about security. You would have to expect the JSON5 parser be able to parse functions and implementations to be able to represent those functions on their native platforms. If someone wants to implement functions in JSON or JSON5, they might as well write a transpiler for ES5 into every other programming language. Regarding regular expressions, I wrote a little more about the subject. |
And also, adding functions support would deviates from being a data format to became a programming languaje...
Your last solution (map |
I'm open for discussions on serializing |
👍 let's keep the issues focused :-) |
Hey, everyone. I'm going to close this issue because it is incompatible with the official specification. If you would like to continue this discussion, please open an issue on the official specification repository. Please see the new issues template for more information. Thanks. |
demo follow
the result is
the follow operator should be supported:
*
/
+
-
%
others I hope also:
**
>>
<<
<<<
>>>
//
? divisible operator or///
What think about yours??
The text was updated successfully, but these errors were encountered: