# Even more clarification on Type piracy

**URL:** <https://discourse.julialang.org/t/even-more-clarification-on-type-piracy/9079>\
**Category:** New to Julia\
**Tags:** package, type, type-piracy\
**Created:** [February 15, 2018, 11:14am UTC](https://discourse.julialang.org/t/even-more-clarification-on-type-piracy/9079 "2018-02-15T11:14:42Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [February 16, 2018, 9:30am UTC](https://discourse.julialang.org/t/even-more-clarification-on-type-piracy/9079/7 "2018-02-16T09:30:36Z")

</div>

As @Tamas_Papp mentioned and also in the [second comment](https://discourse.julialang.org/t/clarification-on-type-piracy/5926/3) of the previous thread (and maybe elsewhere), `dimension(integ::DEIntegrator) = length(integ.u)` is not type piracy because you are not extending the function. In the document:

> “Type piracy” refers to the practice of **extending or redefining** methods in Base or other packages on types that you have not defined.
> 
> — [https://docs.julialang.org/en/stable/manual/style-guide.html#Avoid-type-piracy-1](https://docs.julialang.org/en/stable/manual/style-guide.html#Avoid-type-piracy-1)

So, if you define a function from scratch, it is not type piracy.

There are two kinds of the ways you extend functions defined in other packages. (1) At least one of the argument is dispatched on type you defined. (2) None of the type are defined within your package (as in the case of `step!`).

From the definition of the document, category (1) is _not_ type piracy. In fact, it is often the part of the interface: [http://docs.juliadiffeq.org/latest/basics/integrator.html](http://docs.juliadiffeq.org/latest/basics/integrator.html) For example, defining iterator in Julia is done by extending `Base.iteratoreltype` etc.

The example `*(x::Symbol, y::Symbol) = Symbol(x,y)` in [the document](https://docs.julialang.org/en/stable/manual/style-guide.html#Avoid-type-piracy-1) falls in category (2). I believe extending functions from other packages (not just Base) this way should be avoided unless there are very good reasons as mentioned in the document. For example, consider those four packages

- A
- B: uses A, extend functions in A via type piracy = category (2)
- C: uses A, extend functions in A via type piracy = category (2)
- D: uses B and C

Library B and C relies on the type piracy function internally and don’t know about other’s implementation. Now, package D author come in and think that B and C are useful so that B and C are imported into the package D. At this point, I imagine that B or C may break, depending on the order they are loaded. This is exactly the same as the reason why monkey patch has to be avoided.

---

_[View the full topic](https://discourse.julialang.org/t/even-more-clarification-on-type-piracy/9079)._
