Steven,

Thanks. Is it then the recommended/usual practice to have one "main" 
function with every possible argument you might want, and then several 
methods that provide specific dispatch and pass just the arguments relevant 
to that method? That is,

function dijkstra_shortest_paths(graph, use_dists, edge_dists) ... # this 
is where the algorithm is implemented

dijkstra_shortest_paths(graph, edge_dists::AbstractArray{Float64,2}) = 
dijkstra_shortest_paths(graph, true, edge_dists)
dijkstra_shortest_paths(graph) = dijkstra_shortest_paths(graph, false, 
Array{Float64,2}())

?

On Friday, May 29, 2015 at 6:49:45 PM UTC-7, Steven G. Johnson wrote:
>
> *No!*  This is one of the most common misconceptions about Julia 
> programming.
>
> The type declarations in function arguments have *no impact* on 
> performance.  Zero.  Nada.  Zip.  You *don't have to declare a type at 
> all* in the function argument, and it *still* won't matter for 
> performance.
>
> The argument types are just a filter for when the function is applicable.
>
> The first time a function is called, a specialized version is compiled for 
> the types of the arguments that you pass it.  Subsequently, when you call 
> it with arguments of the same type, the specialized version is called.
>
> Note also that a default argument foo(x, y=false) is exactly equivalent to 
> defining
>
>     foo(x,y) = ...
>     foo(x) = foo(x, false)
>
> So, if you call foo(x, [1,2,3]), it calls a version of foo(x,y) 
> specialized for an Array{Int} in the second argument.  The existence of a 
> version of foo specialized for a boolean y is irrelevant.
>

Reply via email to