[julia-users] When to use !
A question regarding the use of `!` came up a few days ago (https://github.com/tbreloff/Plots.jl/issues/30#issuecomment-142995667), and I wanted to quickly poll the users to get opinions. When a module maintains some sort of global state, and a method mutates that global state, is it appropriate to add `!` to the end of the method name? The example referenced asks why I named the method `immerse!()` instead of `immerse()`, even though it doesn't have any arguments to mutate (it changes the default plotting backend, which is part of the module state). Which method name should it be? (and is it better or worse to provide both options which would do the same thing?)
Re: [julia-users] When to use Symbol instead of ASCIIString on function arguments?
Thanks! I didn't know about enum types!
Re: [julia-users] When to use Symbol instead of ASCIIString on function arguments?
There is no difference. identity is defined as identity(x) = x, and this gets inlined by the compiler. You can also check, for example, the output of @code_native f(1) and compare it with g. Am 30.08.2015 um 16:06 schrieb Diego Javier Zea diego...@gmail.com: Thanks! One more question, what is the difference between this two definitions: julia f(x) = x f (generic function with 1 method) julia g(x) = identity(x) g (generic function with 1 method) julia f(10) 10 julia g(10) 10
Re: [julia-users] When to use Symbol instead of ASCIIString on function arguments?
Thank René!
Re: [julia-users] When to use Symbol instead of ASCIIString on function arguments?
Thanks! One more question, what is the difference between this two definitions: julia f(x) = x f (generic function with 1 method) julia g(x) = identity(x) g (generic function with 1 method) julia f(10) 10 julia g(10) 10
[julia-users] When to use Symbol instead of ASCIIString on function arguments?
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? 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
Re: [julia-users] When to use Symbol instead of ASCIIString on function arguments?
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. 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
Re: [julia-users] When to use Symbol instead of ASCIIString on function arguments?
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
Re: [julia-users] When to use Symbol instead of ASCIIString on function arguments?
Since functions are first class objects, my answer would be neither, just use a function: methoda = x - one(typeof(x)) + x methodb = identity 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? 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