Skip to content
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

Reversible (Un)Serialization #70

Merged
merged 14 commits into from
Jan 15, 2024
Merged

Reversible (Un)Serialization #70

merged 14 commits into from
Jan 15, 2024

Conversation

mfleader
Copy link
Member

@mfleader mfleader commented Jan 12, 2024

Changes introduced with this PR

logically reversibile operation is an operation that the output of the operation can be computed from the input (i.e. bijective)

inverse function := a function that undoes the operation of another function; this inverse only exists if the original function is bijective

Add or modify tests to demonstrate that serialize() and unserialize() are inverse functions to each other, in that they reverse each others mappings.

s := serialize()
u := unserialize()
x := unserialized data, X
y := serialized data, Y
s(x) = y
u(y) = x

s is invertible if, for each y in Y

s(u(y)) = y

and u is invertifible if, for each x in X

u(s(x)) = x

means

s = u^-1
u = s^-1

By contributing to this repository, I agree to the contribution guidelines.

@mfleader mfleader changed the title Idempotent Unserialization Idempotent Serialization Jan 12, 2024
@mfleader mfleader changed the title Idempotent Serialization Idempotent (Un)Serialization Jan 12, 2024
Copy link
Contributor

@jaredoconnell jaredoconnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems straightforward to me.

dbutenhof

This comment was marked as resolved.

webbnh

This comment was marked as resolved.

@mfleader mfleader changed the title Idempotent (Un)Serialization Reversible (Un)Serialization Jan 15, 2024
schema/list_test.go Outdated Show resolved Hide resolved
schema/map_test.go Outdated Show resolved Hide resolved
webbnh

This comment was marked as resolved.

@webbnh
Copy link
Contributor

webbnh commented Jan 15, 2024

logically reversibile operation is an operation that the output of the operation can be computed from the input (i.e. bijective)

You omitted the most important part of the sentence from your source: "or vice versa"! 🤣

s is invertible if, for each x in X

s(u(y)) = y

I think you meant y where you have x (or vice versa).

and u is invertifible if, for each y in Y

u(s(x)) = x

I think you meant x where you have y (or vice versa).

😁

@mfleader
Copy link
Member Author

mfleader commented Jan 15, 2024

I so love cookie-cuttered code. 😏

I have a couple of comments which apply more or less to all of the changes in this recent update:

  • I don't think we need to reserialize the doubly-unserialized value, because we've already done that, successfully. I think that all we have to do is check that the value of second unserialization is equal to the value of the first -- if that's true, then we don't need to re-serialize the value again, because we did already did that and, by this point, we already know that that works.
  • I think you should compare the result of the first reserialization to the the original, unserialized input. You've removed that comparison in a couple of the tests, replacing it with a comparison of the results of the two reserializations, which doesn't cover that ground.
  • While I know that we're sensitive to feature creep, it seems like the code in some of the tests should be updated to use the assert.NoError() and assert.Equals() functions, while you're here. (Aside from improving the code quality, it would make the result (more) directly comparable to to the changes from the other files.)

Alternatively, you might want to consider refactoring all these changes and collecting them together in a single test function, so that you only have to make the corrections in one place.

Also, while you're here, could you please confirm for me that we don't need that tc := tc fix applied to any of these tests? Thanks....

Of the code that I've touched, I have assigned the outer scope variable to a locally scoped variable for iterating with t.Run(). There is at least one other instance that needs to be changed in a refactor separate from this PR.

@mfleader mfleader requested a review from webbnh January 15, 2024 19:12
Copy link
Contributor

@webbnh webbnh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of the code that I've touched, I have assigned the outer scope variable to a locally scoped variable for iterating with t.Run().

Thanks!

There is at least one other instance that needs to be changed in a refactor separate from this PR.

If you're not going to address that immediately (e.g., in another PR), then you should open an issue for it.

logically reversibile operation is an operation that the output of the operation can be computed from the input (i.e. bijective)

You omitted the most important part of the sentence from your source: "or vice versa"! 🤣

The PR description is still missing the key "or vice versa" phrase.

Other than those nits, this looks good to go.

@mfleader
Copy link
Member Author

Of the code that I've touched, I have assigned the outer scope variable to a locally scoped variable for iterating with t.Run().

Thanks!

There is at least one other instance that needs to be changed in a refactor separate from this PR.

If you're not going to address that immediately (e.g., in another PR), then you should open an issue for it.

logically reversibile operation is an operation that the output of the operation can be computed from the input (i.e. bijective)

You omitted the most important part of the sentence from your source: "or vice versa"! 🤣

The PR description is still missing the key "or vice versa" phrase.

Other than those nits, this looks good to go.

The definition for an invertible function says both s(u(y)) = y and u(s(x)) = x need to be true.

@mfleader mfleader merged commit 870c2cf into main Jan 15, 2024
3 checks passed
@mfleader mfleader deleted the idempotent-unserialization branch January 15, 2024 21:07
@webbnh
Copy link
Contributor

webbnh commented Jan 16, 2024

Yes, but...the description for this PR claims that a "logically reversibile operation is an operation that the output of the operation can be computed from the input" which is not correct (i.e., that description is not sufficient).

It's pretty much axiomatic that an output can be computed from the input. What makes the function reversible is that the input can be computed from the output, hence the "vice versa" phrase which hyperlinked source includes but the PR description omits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants