When should a function accept a symbol as an argument?

One possible advantage of passing symbols instead of strings is that it somewhat reduces the space of possible values, at least if you stick to the quote notation with :. For example, you can pass the string "hello world", but :hello world won’t work. Of course you can do Symbol("hello world"), but users are less likely to try that.

So, I think using symbols might help to conceptually clarify that a one word (or one identifier) input is expected.

1 Like