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

Syntax/scope of interface definitions and implementations #9

Closed
2 tasks done
stemann opened this issue May 14, 2023 · 7 comments
Closed
2 tasks done

Syntax/scope of interface definitions and implementations #9

stemann opened this issue May 14, 2023 · 7 comments

Comments

@stemann
Copy link
Contributor

stemann commented May 14, 2023

Any thoughts on the syntax proposed in (the prior) https://github.com/quinnj/Interfaces.jl ?

E.g.,

abstract type Indexable end

@interface Indexable begin
    getindex(::Indexable, i)
    setindex!(::Indexable, v, i)
    firstindex(::Indexable)
    lastindex(::Indexable)
end

@test Interfaces.implements(Array, Indexable, [Base])

It is clear that the mandatory/optional tests in your interface definitions goes further than just ensuring that proper methods are defined - with the proper argument/return types.

Updated: Also:

@rafaqz
Copy link
Owner

rafaqz commented May 24, 2023

It doesn't even have a readme so not really.

The reason for mandatory/optional is that interfaces are often complicated. A widely used package like StaticArrays.jl could not use Indexible in your example on SArray, because it has no setindex!. So there is no point putting setindex! and getindex in the same flat interface like that. But they do belong together somehow or other, and we don't want to define an interface for all possible combinations of method definitions. So we need to be able to specify what we implement and what we skip.

But, I can't even remember why Duck() is needed. If you can reorganise things so it isn't, go for it. This was just an idea over a weekend that got a bunch of stars but no feedback or users as far as I known, so I kind of moved on to more pressing concerns.

@stemann
Copy link
Contributor Author

stemann commented May 29, 2023

OK.

Good points.

Regarding the Duck()'s, it seems - after a first glance at the code - that the test_objects could be dropped from the @implements definitions - and instead be required for the implements method calls (as in Interfaces.implements(Animals.AnimalInterface, Chicken()))

@rafaqz
Copy link
Owner

rafaqz commented May 29, 2023

Sure, that does seem cleaner. A PR would be nice :)

@rafaqz
Copy link
Owner

rafaqz commented May 29, 2023

Hm actually maybe put them in the test method call? implements really needs to work on types.

@stemann
Copy link
Contributor Author

stemann commented May 30, 2023

OK - from here on, let this issue be solely about the first question - the merits of the quinnj syntax, cf. #10 (comment)

What do you think of the idea about having two ways of defining an interface? One with the "method signatures" syntax from quinnj, and one with the predicate syntax in v0.1.0 of this package?

Obviously, having two ways of doing one thing sounds alarming, but perhaps the method signatures syntax is more natural/appealing for people used to, e.g., a C# interface.

I'm thinking the macro could reasonably easy figure out which syntax is used and just define the predicates that correspond to testing the method signatures.

@rafaqz
Copy link
Owner

rafaqz commented May 30, 2023

Yeah... its a little complicated to do both!

I used the function predicate approach because it can do pretty much anything, but that does come at the expense of style.

So this idea is about making the syntax slick? That is of course a valid goal.

If you can actually define a macro that does both, we can asses if it feels right to use it?

@rafaqz
Copy link
Owner

rafaqz commented Mar 1, 2024

Closing this, from extensive use it doesn't look like the syntax needs to be any simpler

@rafaqz rafaqz closed this as completed Mar 1, 2024
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

No branches or pull requests

2 participants