-
Notifications
You must be signed in to change notification settings - Fork 4
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
Replace Some and None variants with the exact value and null accordingly #73
Comments
@dincho what do you think about this? |
In general I don't really like the variants public API, so I'm lean to simplify it. However I wonder can we do a general revamp of the interface? |
in the past |
I think it would be too expensive to integrate calldata library into SDK without breaking changes, so propose to introduce all reasonable changes that we have in mind
More correct to return |
At first I somehow missed the point of this request/issue, however after I clearly understand the request now - I strongly disagree with it the proposal. I would not argue on it but refer to the datatype description from https://en.wikipedia.org/wiki/Tagged_union
Also https://rescript-lang.org/docs/manual/latest/variant#design-decisions
While because of the lack of pattern matching in Javascript it is significantly verbose and "harder" to handle this it's not enough argument to introduce nullable data. In general my opinion is that Moreover I'm always for explicitly over implicitly thus handling special cases would be out of scope of this library. |
If we ever implicitly agreed on this premise: We need to keep Sophia types and its JS representations semantically as close as possible for delivering developers something that naturally makes sense. ..then the conclusion cannot can not be we reject using |
You're free to implement that mapping in the SDK then, just like it is right now this library prefers to work in a more reasonably way. |
exactly the same applies to |
I should stop replying to this one but, the library is a 1to1 encoder to Sophia data types, there is no "null" there, |
Splitting the implementation would make it more difficult to maintain. I don't want to do this recursive replacing by ACI on SDK side just because we can't agree here. Different interfaces in SDK and calldata would complicate switching between them (is calldata intended to be used separately?).
Actually, modern environments would throw a ReferenceError (something is not defined) in that case. I don't think that let foo; // undefined
contract.methods.bar(foo); should be forbidden. Also, in TS optional function parameters are defined as @dincho have you tried to find some third-party None/Some implementation for JS? This would make calldata compatible with them, otherwise, it may be like const t = libraryA.foo();
libraryB.bar(t === libraryA.None ? libraryB.None : t)
// instead of just
libraryB.bar(libraryA.foo()) or even recursive replacement may be needed if there are complex structure 😄 I agree that nulls are error-prone in JS, but TS compiler (with |
I don't really think so. it could be used separately but probably nobody will do it. fact is we need to decide as quickly as possible how to proceed here in general. seems like currently it's not easy to get aligned on that. I would like to have some feedback of @thepiwo and @mradkov about this again. personally I am a fan of typescript but I am more interested in moving the way the majority thinks we should go. this shouldn't block us from moving forward. |
for call-data lib I don't mind as long as in sdk we map it logically without need for additional libs |
@davidyuk what's the exact issue to do it on SDK side? I think we should move forward asap here 😅 |
actually yes in my master plan, this library could evolve to a general encoder/serializer and to be eventually used in a JS compiler, client-side only decoder etc. I definitely want to keep this library standalone, Vanilla JS in browser.
Isn't it already implemented like that in the SDK, I pointed to a source code above sorry if I misunderstood that
I don't like the idea to introduce additional lib for types interop, interfaces should be POJO of a given standalone lib or library provided datatype, that's general library (good) practice IMO |
FYI: I've clarified the library purpose and goals in 4a8baba |
While Rescript doesn't implement nullable types as a source of bugs they don't force JS to adopt that, e.g. the transpiled code uses If you have chosen Rescript instead of JavaScript then we would be able to transpile it to JS without this issue. But calldata is written in JavaScript so it should be consistent with decisions made in this language (even if they are wrong).
It should do most of the work that already calldata does to wrap and unwrap optional values in nested structures, more maintainable would be to do these changes on calldata side. |
OK @davidyuk, looks like it's something quite important to you, I'll reconsider it. |
However, the lib will keep accepting |
difficult topic for me as I don't have a strong opinion here. would be nice to get this sorted out. thanks @dincho, really appreciated! :-) |
Will it decode as |
I think if we aim to keep supporting both ways we probably should make this configurable in the lib. or how is this supposed to work otherwise? |
Null perhaps ? Does it break the current implementation somehow ? |
we are breaking lots of the current implementation anyway now, so we can also change it. Let just support one way in the lib for encoding/decoding for each type, otherwise it will just be confusing. |
I see that we want to solve this topic and somehow it seems feedback is required but I am struggling to understand what I can do in this case or how I can support here. the discussion in this PR #85 (comment) seems to be related.
@dincho so you would like to keep accepting both ways in the public interface - do I understand that correctly? sorry @davidyuk, I am somehow still struggling with this topic in general 😅 |
exactly, no less, no more |
so we have now multiple options:
my humble opinion right now is that I just want to take a decision here. maybe we should set up a call to sort this out. from what I heard from @davidyuk it would be quite an overhead (not sure how much right now) to tackle the SDK favored approach directly in the SDK instead of the lib and it would also increase maintenance costs in case we face changes in that area (probably unlikely, but you never know 😅) I know that we want to have a standalone lib in general. we can leave like is and cover the desired functionality in SDK. personally I am just wondering and thinking about what other tools & SDKs might make use of this library except our official javascript sdk. anyway, we need to take a decision here and I think will leave that up to you @dincho as you maintain this library. in the call today we agreed that we don't want to fork this library and maintain a separate version of it. fact is that the current state of the sdk that aims to include this calldata relies on the implementation included in #85. |
A JS compiler would use this as well. Also a JS blockchain explorer would benefit by decoding call results. This is just in the top of my head, but I'm sure it would find some more uses. Onse the lib gets i's full serialization support, it could be used in the blockchain explorer to show a FATE VM assembly as well, that of course needs an additional lib to traslate the binary to FASM, but still you get the idea. In future if we have FATE VM implemented in JS, this lib would be used there as well. In the call we agreed to support both undefined/null/T/canonical structure and decode to undefined. (option variant only) |
As I see
Some
andNone
are needed for Sophia's strict typing. JS is not so strict, so it can't be converted in a native way. For developer convenience, I propose to make it look native by omitting Sophia's variants in this case by replacingSome
andNone
variants with the exact value and null accordingly.123
null
The text was updated successfully, but these errors were encountered: