# Enforce interface implementation

**URL:** <https://discourse.julialang.org/t/enforce-interface-implementation/52872>\
**Category:** General Usage\
**Created:** [January 5, 2021, 9:36am UTC](https://discourse.julialang.org/t/enforce-interface-implementation/52872 "2021-01-05T09:36:00Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 15, 2022, 8:18pm UTC](https://discourse.julialang.org/t/enforce-interface-implementation/52872/21 "2022-02-15T20:18:26Z")

</div>

Well, this kinda depends on how they work, I am not sure how you would get errors before runtime as, in Julia, compile and runtime are interleaved, and there is not a global static check before the code starts running.

I am also kinda skeptical that projects that do not document informal interfaces will adopt formal interfaces. A poorly documented project will probably be the same that will not adopt formal interfaces, or that will adopt them in such a negligent way that will just create new problems.

Unless formal interfaces do bring some benefit for the compiler, I do not see a reason to implement them, they do not replace the need for documentation.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 16, 2022, 8:53am UTC](https://discourse.julialang.org/t/enforce-interface-implementation/52872/22 "2022-02-16T08:53:06Z")

</div>

> [@Dustin\_Hess](#):
>
> It should be immediately clear what to implement in order to adhere to the interface.

_Documentation_ should be place to do that that.

Formal specifications to “define” interfaces are an illusion: at most they capture methods and types, but do not really handle what the interface is supposed to _do_. Unit tests are much better for that.

I think the best practical way to deal with this in Julia _as is_ is for packages that define an interface to _expose_ (but not export) a `ThatPackage.test_something_interface(...)` function, possibly in a related mini-package for larger projects. Then everyone implementing and interface can just call this in unit tests and be done with it.

---

<div class="post-metadata">

**Author:** ![Dustin\_Hess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dustin_hess/32/11957_2.png) [@Dustin\_Hess](https://discourse.julialang.org/u/Dustin_Hess)\
**Post date:** [March 3, 2022, 5:42pm UTC](https://discourse.julialang.org/t/enforce-interface-implementation/52872/23 "2022-03-03T17:42:05Z")

</div>

DataFrames for example is very hard to extent without reading lost of code. The interface if very poorly documented. Don’t get me wrong DataFrames is great but for something that is widely used the package it is very poorly organized. Extending for the average user is difficult.

Any way I don’t want to go down a rabbit hole @Tamas_Papp 's point is well taken. Just an example of something I ran into.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 4, 2022, 1:22pm UTC](https://discourse.julialang.org/t/enforce-interface-implementation/52872/24 "2022-03-04T13:22:40Z")

</div>

> [@Dustin\_Hess](#):
>
> DataFrames for example is very hard to extent without reading lost of code. The interface if very poorly documented.

I think there may be a misunderstanding here — AFAICT DataFrames.jl does not define a generic interface distinct from the package _per se_. So if you are extending it, you are of course dealing with internals.

That said, it _implements_ the excellent

> **[GitHub - JuliaData/Tables.jl: An interface for tables in Julia](https://github.com/JuliaData/Tables.jl)**
>
> An interface for tables in Julia. Contribute to JuliaData/Tables.jl development by creating an account on GitHub.

interface which is well-documented (probably the most exhaustively documented interface outside Base).

---

<div class="post-metadata">

**Author:** ![Dustin\_Hess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dustin_hess/32/11957_2.png) [@Dustin\_Hess](https://discourse.julialang.org/u/Dustin_Hess)\
**Post date:** [March 4, 2022, 1:54pm UTC](https://discourse.julialang.org/t/enforce-interface-implementation/52872/25 "2022-03-04T13:54:55Z")

</div>

Yes the I agree the user interface is well documented. My point is that formal interfaces make it easy modularization the internal code ( other devs being the users) and let other devs work with your portion mostly concentrating on his or her own piece. This is how my group operate using C#. The added benefit here is when some wants to extend it even if the internals are not documented there are clear interfaces between independent pieces of code. In Julia you would need to come with a standard with your group for doing since there is no way to have a formal interface. The flexibly of multiple dispatch is awesome but it can easily messy and disorganized. There are pluses an minus to both approaches. I like both languages. I just prefer to have the interfaces clearly defined rather than scatter around such in the above. Any way

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 4, 2022, 2:54pm UTC](https://discourse.julialang.org/t/enforce-interface-implementation/52872/26 "2022-03-04T14:54:14Z")

</div>

> [@Dustin\_Hess](#):
>
> In Julia you would need to come with a standard with your group for doing since there is no way to have a formal interface. The flexibly of multiple dispatch is awesome but it can easily messy and disorganized.

I am wondering if you have tried it in practice though, or you are just assuming this.

In particular, just documenting your interface, and providing a test suite.

If you tried it, please tell us how you found it to be “messy and disorganized”, because I would find it really surprising. In particular, I cannot imagine anything more disciplined than incorporating interface tests in CI and getting red flags whenever they fail.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 4, 2022, 3:01pm UTC](https://discourse.julialang.org/t/enforce-interface-implementation/52872/27 "2022-03-04T15:01:22Z")

</div>

> [@Tamas\_Papp](#):
>
> AFAICT DataFrames.jl does not define a generic interface distinct from the package _per se_ .

this is true, except they do have an abstract dataframe type, but it’s not “used properly” (i.e. there are too many functions defined only for dataframe

[Previous page](https://discourse.julialang.org/t/enforce-interface-implementation/52872.md?page=1)
