Replies: 3 comments 1 reply
-
One mechanism for option 2 could be: Each function has a specially formatted comment above the function: ERC20.cairo:
Ownable.cairo:
When the contract is pieced together from two different files, this comment could be used to select only one of them. |
Beta Was this translation helpful? Give feedback.
-
The resulting
(The |
Beta Was this translation helpful? Give feedback.
-
I would really discourage anything resembling inheritance and overrides. Instead, I think the language should try to develop a composition-based approach. Importing works fine when you just need to "re-export" the external functions. It breaks down when you need to modify the behavior for some of those external functions, or to hide them. For those situations I would like to see a way to import modules for internal use, without re-exporting all of the external functions. Then using the internal interface you can define the functionality that you actualy want to export. |
Beta Was this translation helpful? Give feedback.
-
I am thinking there might be two ways to extend a contract, e.g., an ERC token to be Ownable.
myToken.cairo
with top-of-file import-style mechanism:from ozcc import ERC, Ownable
.ozcc generate ERC Ownable
that produces a populatedmyToken.cairo
.Option 1 would mimic existing Solidity experience, and would involve functions overriding others in a hierarchy.
Option 2 would involve the program fetching only non-overridden functions from the chosen combination and placing those in a file.
Both options are compatible with pre-generated common patterns (721, 721-ownable, 721-ownable-enumerable, 721-enumerable). Option 2 might result in a less-complex contract file, because there would be no override patterns for the developer to mentally manage.
Beta Was this translation helpful? Give feedback.
All reactions