friedmud / MOOSE.jl

Multiphysics Object Oriented Simulation Environment In Julia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use Symbol for syntactic elements?

ChrisRackauckas opened this issue · 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.

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.

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

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]).

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