Polymorphism support (Must implement function if included an interface) #307
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Created by: VitalJeevanjot
Greetings,
I was wondering if there is a way to implement interfaces in Sophia so we can work on standards in a more appropriate way. As discussed here https://forum.aeternity.com/t/how-to-write-interfaces-in-sophia/8236/6 .
Best,
Created by: radrow
I see it as something like
or even
or evener
The question is how deep do we want to dive into it:
Created by: VitalJeevanjot
Thank you for looking into it, My view on your questions:
-> I was not sure about this but could be helpful in the case of extended standards (Including a function that was not in the original interface, for e.g. adding
safeTransfer
if not in default ERC721) so should result in a cleaner code & better understanding.-> This might be helpful in writing cleaner modules (classes) and not deriving every class before moving on (Since you asked so I assume that currently, Sophia does not support multiple inheritance).
-> Whatever you prefer I can adapt to it.
Best,
Created by: marc0olo
I personally like this kind of style better:
whereas the compilation should fail if the implementation of
stroke()
is missing in the contract.I might be biased, but what about:
As for the questions:
I think this will lead to many layered interfaces. Probably keeping it flat enforces better callback design.
It would be nice if the compiler warns on missing entrypoints, specially if I plan to expand on a set of contracts/interfaces/behaviours/etc.
Created by: radrow
This is going to be extremely helpful with the upcoming contract factories
Created by: marc0olo
is there a plan to address this issue? @hanssv @ghallak
I think it would be good to address this along with #198
Created by: hanssv
I don't know of any plans. It is two rather big pieces of work and I'm not sure it is the best bang for the buck but it would be nice to have for sure ;-)
Created by: marc0olo
at least there were requests from the community in that regards in the past. what are more important issues in your opinion right now? just wondering :-)
would definitely be good to have these features
Created by: radrow
Note that you can hack it out by making unsafe contract coercions. Just deploy an identity contract and declare it as desired cast in your main contract. Then you can remote call it whenever you need dynamic casting.
This is dirty, but could serve as a polymorphism replacement until it is done.
Created by: marc0olo
That sounds interesting, but I guess we can wait for the final solution here. We should stop working around everything IMO :)
But definitely good to know if somebody wants to try it like you described.
Proposal 1: Write the implementations along other functions, but precede implementations with
@impl
and declare that the contract implements the interface.Please react with 👍 to this comment if you support this proposal.
Proposal 1.1: If we decide to go with Proposal 1, should we use
@impl
orimpl
Please react with ❤️ to this comment if you support
@impl
or with 🎉 if you supportimpl
.Proposal 1.2: If we decide to go with Proposal 1, should we use
contract Cat is Strokable
orcontract Cat : Strokable
Please react with ❤️ to this comment if you support
contract Cat is Strokable
or with 🎉 if you supportcontract Cat : Strokable
.Proposal 2: Write the implementations in a separate block inside the contract
Please react with 👍 to this comment if you support this proposal.
Proposal 3: Write the implementations separately outside the contract
Please react with 👍 to this comment if you support this proposal.
Created by: UlfNorell
Why do you want special syntax for the interface entrypoints? The most natural thing (looking at Java for instance), would be to just write
Created by: marc0olo
actually I agree on that and I see Proposal 1 is fitting this mostly but additionally has the
@impl
annotation. actually I thought of@impl
to be the same like@Override
annotation in Java where you could also have the reverse check if it really implements an interface or not.already commented here:
Created by: thepiwo
I think @ annotations shouldn't be part of logic, just information for other systems, e.g. as pragma.
The proposal of Ulf sounds fine, also Proposal 2 (with full implementation, instead of impl) sound good.
Created by: UlfNorell
If I'm not mistaken, the
@override
annotation in java is there to prevent errors where you misspell the name of a method in a super class and the compiler can't know if you meant to override it or just declare a new method. In this case, that's not an issue because if you define thestrokke
entrypoint instead ofstroke
you'd get an error from not having defined all the methods of the interface.Created by: marc0olo
I think it's used for both, superclasses and interfaces. but I am sometimes mixing things up and you might be correct 😅
generally see this topic also closely related to contract inheritance but that's another kind of story.
Created by: VitalJeevanjot
Proposals 2 and 3 introduce a scaled approach to implement multiple interfaces without confusion.
Voted for 2nd because 3rd seems very separate from other basic languages (harder for traditional people to catch) but a much cleaner approach.
It will be great if you can also share the examples If the interfaces are declared in a separate file.
Created by: hanssv
I agree with Ulf, no need to introduce extra keywords - keep it simple 🙏
Created by: the-icarus
Also agree with @UlfNorell but would suggest to drop the
contract
prior tointerface
. Other languages also just use the singleinterface
keyword to define an interface (e.g. Java,C#,Solidity). Why should we havecontract interface
?Created by: nikita-fuchs
Absolutely agree with this one and the rest vouching for simplicity and no @ decorators.
One thing is an interface, the other thing is a contract. The contract uses the interface, that's it. Can we keep it simple please ? 🙏
Edit: After some thinking, I changed my mind.
contract interface
is a bit more clear, as it states more precisely the nature of the interface. This is the way it is currently implemented for inter contract calls, so let's stick with the current syntax please ? :)Created by: omar-saadoun
@ghallak can we add @UlfNorell proposal to vote?
Created by: marc0olo
I think we already voted for it 😛
personally I also agree with @the-icarus to just use the single keyword
interface
. not sure whycontract
should be put in frontCreated by: nikita-fuchs
The idea is:
Let's use
contract interface
for both inter contract calls and the "interfacing". Else if I want to create a contract equivalent to Strokable and call it, I need to do:So why not just reuse
contract interface
?Created by: marc0olo
if inter contract calls require the keywords
contract interface
for a specific reason this makes sense. if inter contract calls can also be established by just providinginterface
keyword I would prefer removing the need forcontract
keyword there.but I am generally happy to have the feature at all :-) ... just personal opinion