MOOSE.jl icon indicating copy to clipboard operation
MOOSE.jl copied to clipboard

Use Symbol for syntactic elements?

Open ChrisRackauckas opened this issue 9 years ago • 4 comments

From the documentation I see you do:

u = addVariable!(diffusion_system, "u");

Shouldn't u really be a symbol here? It would make everything more amenable to metaprogramming.

ChrisRackauckas avatar Jan 06 '17 20:01 ChrisRackauckas

I'm not following... but I don't have much experience with Symbols. Are you suggesting the return type of addVariable! be a Symbol? Or are you suggesting that the name for the variable (the "u" here) be changed to be a Symbol?

u (on the LHS) here is a Variable... it holds quite a lot of state. I can't see how it could be a Symbol.

But, like I say: I'm probably just not following because of my lack of expertise.

friedmud avatar Jan 06 '17 21:01 friedmud

BTW: I definitely appreciate the feedback! Still a lot to learn!

friedmud avatar Jan 06 '17 21:01 friedmud

u = addVariable!(diffusion_system, :u)

Symbols are "instantiations of Julia syntax", so if one was to metaprogram with a variable u, one would work with its symbol. Also, Symbols have O(1) comparison as opposed to strings (probably doesn't matter in this context). So usually in Julia when you're naming things symbols are used because they are then easier to work with in other ways. Things like IDs or choices of methods are usually done via types or symbols for this reason. Seeing a string here is rather odd if one isn't looking to "index on the string" (str[1:5]).

ChrisRackauckas avatar Jan 06 '17 21:01 ChrisRackauckas

Gotcha - thanks for the explanation! It sounds reasonable to switch it.

friedmud avatar Jan 06 '17 21:01 friedmud