Convert from higher order functions to classes in tools.codegen.gen#47008
Closed
ezyang wants to merge 2 commits intogh/ezyang/862/basefrom
Closed
Convert from higher order functions to classes in tools.codegen.gen#47008ezyang wants to merge 2 commits intogh/ezyang/862/basefrom
ezyang wants to merge 2 commits intogh/ezyang/862/basefrom
Conversation
bhosmer has been complaining about how it is difficult to distinguish between local variables and closed over variables in the higher order functions. Well, closures and objects do basically the same thing, so just convert all these HOFs into objects. The decoder ring: - Higher order function => Constructor for object - Access to closed over variable => Access to member variable on object - with_native_function => method_with_native_function (because it's hard writing decorators that work for both functions and methods) I didn't even have to change indentation (much). When there is no need for closed over variables (a few functions), I kept them as plain old functions, no need for an object with no members. While I was at it, I also deleted the kwargs, since the types are enough to prevent mistakes. Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
This was referenced Oct 28, 2020
ezyang
added a commit
that referenced
this pull request
Oct 28, 2020
bhosmer has been complaining about how it is difficult to distinguish between local variables and closed over variables in the higher order functions. Well, closures and objects do basically the same thing, so just convert all these HOFs into objects. The decoder ring: - Higher order function => Constructor for object - Access to closed over variable => Access to member variable on object - with_native_function => method_with_native_function (because it's hard writing decorators that work for both functions and methods) I didn't even have to change indentation (much). When there is no need for closed over variables (a few functions), I kept them as plain old functions, no need for an object with no members. While I was at it, I also deleted the kwargs, since the types are enough to prevent mistakes. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 71c6ac9 Pull Request resolved: #47008
bhosmer
approved these changes
Oct 28, 2020
bhosmer
left a comment
There was a problem hiding this comment.
Excellent! I do think restating the closures this way is a real readability improvement. And nice touch moving the invariant checking into __post_init__ 😁
💊 CI failures summary and remediationsAs of commit 3136294 (more details on the Dr. CI page): ✅ None of the CI failures appear to be your fault 💚
🚧 2 ongoing upstream failures:These were probably caused by upstream breakages that are not fixed yet:
This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 5 times. |
This was referenced Oct 28, 2020
…degen.gen" bhosmer has been complaining about how it is difficult to distinguish between local variables and closed over variables in the higher order functions. Well, closures and objects do basically the same thing, so just convert all these HOFs into objects. The decoder ring: - Higher order function => Constructor for object - Access to closed over variable => Access to member variable on object - with_native_function => method_with_native_function (because it's hard writing decorators that work for both functions and methods) I didn't even have to change indentation (much). When there is no need for closed over variables (a few functions), I kept them as plain old functions, no need for an object with no members. While I was at it, I also deleted the kwargs, since the types are enough to prevent mistakes. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D24600805](https://our.internmc.facebook.com/intern/diff/D24600805) [ghstack-poisoned]
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack:
bhosmer has been complaining about how it is difficult to distinguish
between local variables and closed over variables in the higher order
functions. Well, closures and objects do basically the same thing, so
just convert all these HOFs into objects.
The decoder ring:
hard writing decorators that work for both functions and methods)
I didn't even have to change indentation (much).
When there is no need for closed over variables (a few functions), I
kept them as plain old functions, no need for an object with no
members.
While I was at it, I also deleted the kwargs, since the types are
enough to prevent mistakes.
Signed-off-by: Edward Z. Yang ezyang@fb.com
Differential Revision: D24600805