# My very first Julia package: Simpson.jl

**URL:** https://discourse.julialang.org/t/my-very-first-julia-package-simpson-jl/74257
**Category:** New to Julia
**Created:** [January 8, 2022, 9:18pm UTC](https://discourse.julialang.org/t/my-very-first-julia-package-simpson-jl/74257 "2022-01-08T21:18:48Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![AdamWysokinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamwysokinski/32/206422_2.png) [@AdamWysokinski](https://discourse.julialang.org/u/AdamWysokinski)
#### Post date: [January 8, 2022, 9:18pm UTC](https://discourse.julialang.org/t/my-very-first-julia-package-simpson-jl/74257/1 "2022-01-08T21:18:48Z")

</div>

Hi,  
Simpson.jl is a Julia package to integrate y(x) using samples and the composite Simpson’s rule. If x is None, spacing of dx is assumed. If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson’s rule requires an even number of intervals. The parameter ‘even’ controls how this is handled.

The code is based on [SciPy v1.7.1](https://github.com/scipy/scipy/blob/v1.7.1/scipy/integrate/_quadrature.py)

> **[AdamWysokinski/Simpson.jl](https://notabug.org/AdamWysokinski/Simpson.jl)**
>
> Integrate using samples and the composite Simpson's rule.

Comments and suggestions are welcome 🙂

ATB, Adam

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [January 8, 2022, 9:21pm UTC](https://discourse.julialang.org/t/my-very-first-julia-package-simpson-jl/74257/2 "2022-01-08T21:21:55Z")

</div>

One thing I would recomend is using `Symbol`s rather than `String`s for the options. There’s no reason to do string comparison for code like this.

---

<div class="post-metadata">

### Author: ![AdamWysokinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamwysokinski/32/206422_2.png) [@AdamWysokinski](https://discourse.julialang.org/u/AdamWysokinski)
#### Post date: [January 8, 2022, 9:26pm UTC](https://discourse.julialang.org/t/my-very-first-julia-package-simpson-jl/74257/3 "2022-01-08T21:26:48Z")

</div>

Thanks, I’ll learn about using `Symbols` and modify the code.

---

<div class="post-metadata">

### Author: ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)
#### Post date: [January 8, 2022, 10:04pm UTC](https://discourse.julialang.org/t/my-very-first-julia-package-simpson-jl/74257/4 "2022-01-08T22:04:21Z")

</div>

Looks great for a first package. I especially love the documentation, if only all smaller/obscure packages were this well documented 😉

One suggestion is that instead of using `error` you should be more specific with which _type_ of error is being thrown. For example, the first error says: `error("If given, length of x must be the same as y.")` which is a problem with the user’s input, so it’s an `ArgumentError`.

Some previous discussion on this can be found [here](https://discourse.julialang.org/t/error-vs-throw-argumenterror/18915).

---

<div class="post-metadata">

### Author: ![AdamWysokinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamwysokinski/32/206422_2.png) [@AdamWysokinski](https://discourse.julialang.org/u/AdamWysokinski)
#### Post date: [January 8, 2022, 10:23pm UTC](https://discourse.julialang.org/t/my-very-first-julia-package-simpson-jl/74257/5 "2022-01-08T22:23:08Z")

</div>

Thanks!  
I’ve corrected error handling as you suggested.

---

<div class="post-metadata">

### Author: ![eliascarv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eliascarv/32/22152_2.png) [@eliascarv](https://discourse.julialang.org/u/eliascarv)
#### Post date: [January 9, 2022, 1:27am UTC](https://discourse.julialang.org/t/my-very-first-julia-package-simpson-jl/74257/6 "2022-01-09T01:27:37Z")

</div>

Your code with `Symbol` instead of `String` looks like this:

```julia
function simpson(y, x=nothing, dx=1.0; even=:avg)
    #code
    if N % 2 == 0
        # code
        if even in (:avg, :first)
            # code
        end
        # Compute using Simpson's rule on last set of intervals
        if even in (:avg, :last)
            # code
        end
        if even === :avg
            # code
        end
        # code
    else
        # code
    end
    return result
end

```

I could do a PR, but I don’t have a NotABug account.

---

<div class="post-metadata">

### Author: ![AdamWysokinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamwysokinski/32/206422_2.png) [@AdamWysokinski](https://discourse.julialang.org/u/AdamWysokinski)
#### Post date: [January 9, 2022, 9:12am UTC](https://discourse.julialang.org/t/my-very-first-julia-package-simpson-jl/74257/7 "2022-01-09T09:12:15Z")

</div>

Done, thanks for the hint!
