Narrow argument types anti-pattern

When designing functions in Julia, we have many options about whether and how to provide the type of arguments. The narrow argument types anti-pattern refers to the situation in which the types of the arguments are too narrowly specified, causing the function to be less useful unnecessarily.

Let's consider a simple example function that is used for computing the sum of the products of two vectors:

function sumprod(A::Vector{Float64}, B::Vector{Float64})
return sum(A .* B)
end

There is nothing wrong with this design, except that the function can only be used when the arguments are vectors of Float64 values. What are the other possible options? Let's take a look at that next.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.142.115