On Sat, Aug 29, 2015 at 11:48 AM, Yichao Yu <yyc1...@gmail.com> wrote: > On Sat, Aug 29, 2015 at 11:17 AM, Diego Javier Zea <diego...@gmail.com> wrote: >> Hi! >> >> I'm confused with this... >> >> When do I need to use Symbol instead of ASCIIString on function arguments? >> >> Which of the following is the best and Julian definition? > > Apart from their indented use (symbol in code/expression) symbols are > more or less like enums (or at least in your use case). I would > suggest using enums instead of either symbols or string.
In another word, if there's only a few possible values, use enum unless it is somehow not possible (because it's not in 0.3 maybe?) Otherwise, if it can take arbitrary values and is not a symbol in the code, use string (not necessarily ASCIIString either). > >> >> >> julia> myfunstr{T}(x::T; method::ASCIIString="one") = method=="one" ? >> one(T)+x : x >> myfunstr (generic function with 1 method) >> >> >> julia> myfunsym{T}(x::T; method::Symbol=:one) = method==:one ? one(T)+x : x >> myfunsym (generic function with 1 method) >> >> >> julia> myfunstr(10) >> 11 >> >> >> julia> myfunsym(10) >> 11 >> >> >> Thanks in advance, >> Best