# ANN: ArgCheck.jl

**URL:** https://discourse.julialang.org/t/ann-argcheck-jl/2392
**Category:** Community
**Tags:** package, announcement
**Created:** [March 1, 2017, 9:26pm UTC](https://discourse.julialang.org/t/ann-argcheck-jl/2392 "2017-03-01T21:26:35Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [March 1, 2017, 9:26pm UTC](https://discourse.julialang.org/t/ann-argcheck-jl/2392/1 "2017-03-01T21:26:35Z")

</div>

[ArgCheck.jl](https://github.com/jw3126/ArgCheck.jl) is a very small package that allows to replace

```julia
function f(A, B, k, n)
    (k > 0) && (n > 0) || throw(ArgumentError("k and n must be positive".))
    k > n || throw(ArgumentError("k > n must hold."))
    size(A) == size(B) || throw(DimensionMismatch("size(A) == size(B) must hold."))
    # doit    
end

```

by

```julia
function f(A, B, k, n)
    @argcheck k > 0 && n > 0
    @argcheck k > n
    @argcheck size(A) == size(B) DimensionMismatch
    # doit
end

```

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [March 1, 2017, 9:43pm UTC](https://discourse.julialang.org/t/ann-argcheck-jl/2392/2 "2017-03-01T21:43:47Z")

</div>

Simple and useful! Good work.

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [March 2, 2017, 9:49am UTC](https://discourse.julialang.org/t/ann-argcheck-jl/2392/3 "2017-03-02T09:49:06Z")

</div>

Nice. For reference, there’s been a discussion about including a similar feature in Julia itself, possibly with support for conditions on the returned value too:  
[https://github.com/JuliaLang/julia/pull/15495](https://github.com/JuliaLang/julia/pull/15495)

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [March 2, 2017, 5:21pm UTC](https://discourse.julialang.org/t/ann-argcheck-jl/2392/4 "2017-03-02T17:21:58Z")

</div>

Interesting. I think it would be good to have some standard macro for argument checking in Base.

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [March 3, 2017, 3:37pm UTC](https://discourse.julialang.org/t/ann-argcheck-jl/2392/5 "2017-03-03T15:37:08Z")

</div>

Looks useful. Will you register it?

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [March 3, 2017, 5:41pm UTC](https://discourse.julialang.org/t/ann-argcheck-jl/2392/6 "2017-03-03T17:41:32Z")

</div>

Nice!

I’ve been looking for this “design by contract” concept from Eiffel language (its only(?) major contribution) before.

I had a feeling macros would work, so didn’t complain it wasn’t built-in to the language.

In theory (and your implmentation, shouldn’t preclude) this could be an optimization opportunity for the compiler. Maybe it already helps it…?

The full idea is also invariants within loops and after loops. Then “argcheck” isn’t the best name…

---

<div class="post-metadata">

### Author: ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)
#### Post date: [March 3, 2017, 7:55pm UTC](https://discourse.julialang.org/t/ann-argcheck-jl/2392/7 "2017-03-03T19:55:37Z")

</div>

It is registered maybe you need to run `Pkg.update()`?

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [March 3, 2017, 11:02pm UTC](https://discourse.julialang.org/t/ann-argcheck-jl/2392/8 "2017-03-03T23:02:40Z")

</div>

@jw3126 I think `@assert` is well suited to check for invariants before/after loops.

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [March 3, 2017, 11:03pm UTC](https://discourse.julialang.org/t/ann-argcheck-jl/2392/9 "2017-03-03T23:03:45Z")

</div>

Had to run `Pkg.update()`, now I installed it. Thanks!
