# DesignByContract.jl: DbC interface for Julia (feedback)

**URL:** https://discourse.julialang.org/t/designbycontract-jl-dbc-interface-for-julia-feedback/49079
**Category:** Community
**Tags:** package
**Created:** [October 26, 2020, 10:05pm UTC](https://discourse.julialang.org/t/designbycontract-jl-dbc-interface-for-julia-feedback/49079 "2020-10-26T22:05:20Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)
#### Post date: [January 14, 2021, 12:14pm UTC](https://discourse.julialang.org/t/designbycontract-jl-dbc-interface-for-julia-feedback/49079/6 "2021-01-14T12:14:39Z")

</div>

On second thought, why not leverage Julia’s typesystem? In essence, pre- and postconditions are just types. For example, consider Julia’s `Vector` type. If we want to define a precondition on this vector that it is sorted, then that could basically be expressed as a `SortedVector` type. So, in code

```julia
min(x::SortedVector) = first(x)

```

The difficulty here is to make a datastructure that enforces the conditions. Probably, this should be some kind of immutable datastructure.

I’m not very familiar with Julia’s typesystem, so maybe these things are impossible. In types, your example dictionary type could be something like `BoundedDict{1, maxDictSize)`. A neat package would allow the user to easily define combinations of types like `ComposedType{NonEmptyDict, UpperBoundedDict{maxDictSize}`.

EDIT: Note that via types, you can actually **improve** performance like with the `min` function defined above. An earlier discussion here about sorted lists ([Sorted Array implementation? - #2 by garrison](https://discourse.julialang.org/t/sorted-array-implementation/5897/2)). There is a pointer to the implementation of `SortedSet`.

---

_[View the full topic](https://discourse.julialang.org/t/designbycontract-jl-dbc-interface-for-julia-feedback/49079)._
