-
-
Notifications
You must be signed in to change notification settings - Fork 46
[Work in progress] Cpanel::JSON::XS: use Data::Bool #109
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
Conversation
Why Types::Bool and not JSON::Types::Bool? EDIT: I see. Well, what do the other serializers say? |
Please be aware of existing efforts in this area. It would be counterproductive to introduce multiple solutions to the problem of having too many solutions :) http://blogs.perl.org/users/tinita/2018/05/my-report-of-the-perl-toolchain-summit-2018-in-oslo.html (scroll to "bool.pm draft") |
@Grinnz Tina's report inspired me to put this together. See https://metacpan.org/pod/release/FERREIRA/Types-Bool-2.98003-TRIAL/lib/Types/Bool.pm#DESCRIPTION and perlpunk/bool-p5#2 @rurban I contacted JSON::PP and JSON::XS maintainers and I am waiting on their feedback. I think the extra overloads used by Cpanel::JSON::XS are mostly harmless (as far as I can see) though not ideal. |
I'm fine with this generalization, as long as most JSON modules do this. But I'm only the second in the chain, please persuade the core module maintainer first, I'll follow then. Don't know about schmorp, but he was the first to come up with it. The biggest problem is only if we can trust the core maintainers to do the right thing. They don't do in p5p, JSON::PP should be different. Let them discuss this first. |
f194092
to
59d83e9
Compare
That is meant to fix the CI tests
Alternatively all problems with booleans can be handled by https://metacpan.org/pod/Cpanel::JSON::XS::Type. Moreover it solves also string/int problems. use Cpanel::JSON::XS;
use Cpanel::JSON::XS::Type;
encode_json([1], [JSON_TYPE_BOOL]);
# '[true]'
encode_json([0], [JSON_TYPE_BOOL]);
# '[false]' |
because only new operators are being overloaded.
Anyway, what is purpose of |
I think he wants a common interfaces for other Perl modules which need booleans as objects and which are interested in interoperability. Good goal indeed. I'm only worried about the particular bad implementation, and the need to add one more package to check against at runtime. I'm with Lehmann on this. His effort is enough. |
Exactly, same there. There are already more bool types/objects and some of them area already supported by other JSON* modules. So why new? And also it targets again only booleans. And not integers, floats and other types. Cpanel::JSON::XS::Type already supports all JSON types. |
Update: changing the issue title to reflect that @rurban The only thing new here is delegating the code to handle to boolean objects to @pali This is compatible with the convention of @pali I am having enough trouble for anyone to consider this bite-sized change. I am thinking "Small is better" and "Complex proposals get rejected faster" (like your makamaka/JSON-PP#32). See makamaka/JSON-PP#36 (comment) and makamaka/JSON-PP#36 (comment) |
And this is the reason why we have there 4 different JSON boolean objects... This is exactly same situation as in https://xkcd.com/927/ Look, in makamaka/JSON-PP#32 (comment) is just Based on current status, that So what Types::Bool brings? Or which problem it fixes? |
@pali I don't know what you mean by "4 different JSON boolean objects" – the current JSON modules out there all use The purpose here is simple. It consists of two steps. The first is to "relieve" JSON modules from their boolean-related code – that is why these pull requests are mainly deletions: https://github.com/rurban/Cpanel-JSON-XS/pull/109/files, https://github.com/makamaka/JSON-PP/pull/36/files, https://github.com/aferreira/cpan-Types-Serialiser/pull/1/files After that, the second step is a consequence of the first: to have a good answer when someone asks: "What boolean objects should I use in my Perl code?" That is meant to reduce interoperability issues among modules that need booleans – those are recurrent requests, like msgpack/msgpack-perl#37 |
Boolean objects currently supported by Cpanel::JSON::XS. They are: Plus also it support references to 0 and 1. And now you want that Cpanel::JSON::XS would support also Types::Bool::true. Why are not 4 types of booleans (+references) enough?? This is really https://xkcd.com/927/.
In Perl code use Perl logic. Standard Perl logic is simple. False is undef, 0 and ''. And values 0 and 1 are used for booleans in most perl/cpan code. Exception is just this JSON hell and invention of fifth boolean does not make JSON hell better. Plus it does not solve problem with serializing JSON numbers... Guys, sit down and think about it again. This invention of new Types::Bool::true does not help anything. People just start asking, what to use for JSON? Why not JSON::PP::true (which work now for every JSON module)? Or why not Types::Serialiser::true? How it would work with Moose Bool attributes? And why internal perl functions (like exists, defined, ...) which returns boolean value returns something different as Types::Bool? Why not to use standard Perl logic for booleans? And why not Perl model where operators (and functions) itself decide how to interpret variable -- and not variable decide how operators/functions evaluate them? @rurban: I agree with you:
I do not see any value for adding new dependency... and Lehmann's solution is really enough. |
It does not need to. Because it already does. There is no new stash – it is just "JSON::PP::Boolean". Notice that with the changes in this PR, all (unchanged) tests still pass. As I put it before, the benefit is more like a social collaboration – (1) it works with the past code, (2) no need for every one to repeat the same boolean-related mambo jambo, (3) anyone that does not want to reinvent the wheel is invited to adopt a single module for their booleans.
|
This is just an implementation detail which is irrelevant when talking, describing or documenting public API. Also, most of users are interested in API, not implementation details (like optimization for converting C char* to int and etc...). In fact your proposed API change for Cpanel::JSON::XS is adding support also Types::Bool::true object. Therefore it is adding fifth boolean type. @rurban may decide at any time to fully or partially rewrite Cpanel::JSON::XS (without changing API.) E.g. to optimize that module or for any other reason. And when that happen all those boolean types need to be supported for backward compatibility.
How it differs from JSON::PP::Boolean or Types::Serialiser modules, which are already widely used?
For data serialization, basically every current solution just cause problems. You should look @choroba's YAPC talk about it: https://youtu.be/E70b73KlP6E How is your module solving those serialization problems with scalars returned by perl functions or by any random cpan module (which obviously do not use Types::Bool) or module which use Moose/Moo/... Bool attribute? |
Closing since it hasn't attracted the necessary interest. |
I am opening a discussion for moving the boolean support of JSON modules (like JSON::PP, JSON::XS, and Cpanel::JSON::XS) to other module, which can be used as the common interfaces for other Perl modules which need booleans as objects and which are interested in interoperability.
I am working on trial version of Types::Bool and the latest release on CPAN is: https://metacpan.org/release/FERREIRA/Types-Bool-2.98005-TRIAL
Let me know what you think of that.