DesignByContract.jl: DbC interface for Julia (feedback)

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

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). There is a pointer to the implementation of SortedSet.

1 Like