# A playful competition: who can define a method that invalidates the most code?

**URL:** https://discourse.julialang.org/t/a-playful-competition-who-can-define-a-method-that-invalidates-the-most-code/47543
**Category:** Tooling
**Tags:** competition
**Created:** [September 30, 2020, 3:21pm UTC](https://discourse.julialang.org/t/a-playful-competition-who-can-define-a-method-that-invalidates-the-most-code/47543 "2020-09-30T15:21:54Z")
**Posts on this page:** 1
**Showing post:** 36

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [October 5, 2020, 12:18pm UTC](https://discourse.julialang.org/t/a-playful-competition-who-can-define-a-method-that-invalidates-the-most-code/47543/36 "2020-10-05T12:18:07Z")

</div>

Yikes, realized I forgot to announce the results on Friday. To evaluate the submissions, I tested each using a script that I executed from the linux prompt to ensure there weren’t differences in my typing at the REPL (since hitting certain keys can force the compilation of new methods). In a couple of cases, this led to a pretty different count than provided by the submitter, perhaps mostly because some REPL methods did not compile. (At least the rank order was consistent with the numbers provided by the applicants.)

Without further ado, here are the results of my analysis and the winners…

For the category of “pirating methods,” we had several submissions including a nail-biter for the win:

- **third place** variants of overloading +:
  - the original submission was `Base.:+(x::Int, y::Int) = Base.inferencebarrier(Base.add_int(x, y))` (the `inferencebarrier` isn’t required ) by @simeonschaub at 15782
  - an improved/more evil version `Base.:+(x::T, y::T) where {T<:Base.BitInteger} = Base.add_int(x, y)` by @StefanKarpinski at 15933

- **second place** : `Base.getproperty(x, s::Symbol) = getfield(x, s)` by @simonbyrne at 17035
- **first place** `Base.convert(::Type{T}, x::Number) where T<:Real = T(x)` by @tomerarnon at 17093

In the non-pirating category, we had:

- **second place** `struct DoNotCare<:Real end; Base.:(==)(x::DoNotCare, ::Any) = true` by @oxinabox at 58
- `convert` methods:
  - `struct X end; Base.convert(::Any, ::X) = nothing` by @oxinabox at 1666 was disqualified (sorry) because to be a valid `convert` method it should have been `Base.convert(::Type{Any}, ::X)` (which has 1152 and would have won), so the winner is…
  - **first place** `struct X end; Base.convert(::Union{}, ::X) = nothing` by @mbauman at 903

In case you’re curious, in the non-pirating category I believe that it’s not currently possible to do better than the following rather arcane submission:

```julia
struct X end
Base._str_sizehint(::X) = nothing

```

at 2622 invalidations. You can discover this and similar opportunities by installing MethodAnalysis and then running `demos/abstract.jl` and typing `mipriv` on the command line. (`mipriv` means “`MethodInstances` of private, a.k.a. non-exported, names”; the analog for exported names is `miexp`).

Congrats to the winners, and let the second phase commence! Announcement will likely be made on Saturday as I am reserving Friday afternoon for a family bike trip.

---

_[View the full topic](https://discourse.julialang.org/t/a-playful-competition-who-can-define-a-method-that-invalidates-the-most-code/47543)._
