Just to extend Tamas's note... Another reason you may add the type
annotation is to ensure your code errors when you pass it types that are
not valid (but may compile and dispatch without issue).

On Thursday, May 5, 2016, Tamas Papp <tkp...@gmail.com> wrote:

> Hard to say without the context, but since in this case the only purpose
> of a `nothing` seems to be to initialize with a default value, I would
> go with y=Dict(), which does it directly.
>
> (Note that unless you are dispatching on them, your type declarations
> are probably unnecessary, they won't make your code faster.)
>
> On Thu, May 05 2016, FANG Colin wrote:
>
> > For example,
> >
> > function f(x::Int; y::Union{Void, Dict})
> >     z = y == nothing ? Dict() : y
> >     ...
> > end
> >
> >
> > Or
> >
> > function f(x::Int; y::Dict=Dict())
> >     ...
> > end
> >
> > Which one should I use?
>

Reply via email to