21

Is there a rationale, beyond historical accident, why some Mathematica option values are strings, while others are symbols?

It seems natural that some value spaces, e.g. named color schemes, are so numerous and only applicable to ColorData, e.g. ColorData["HTML"] and so should be strings.

On the other hand wouldn't it make more sense if "XAxis" in PairedHistogram[..., BarOrigin -> "XAxis"] were a built in symbol to be shared as an option value across composite graphics functions?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
alancalvitti
  • 15,143
  • 3
  • 27
  • 92

1 Answers1

20

In older versions (5 and before), most option names were symbols. It's since about version 6 that string option names have proliferated.

I think that the reason is to avoid cluttering the name space. Once you introduce a new name, it won't be available for package authors to use for other purposes (in particular, function names). At least not without shadowing the built-in one. Considering the huge number of options introduced since version 6, I think it was a good decision to use strings for most of them.

Every time a new symbol is introduced in a new version, there's a chance it will break some third party package. Using strings reduces the likelihood of this happening. Strings, unlike symbols, are not part of a namespace (so there's no shadowing issue) and can't have associated definitions (so breakage due to conflict is impossible).

Reb.Cabin
  • 8,661
  • 1
  • 34
  • 62
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • 5
    +1. I agree with your reasoning, I also think it is namespace-related. This does however come at a price - string options are much less discoverable in the documentation and otherwise. – Leonid Shifrin Mar 27 '13 at 21:41
  • 4
    @Leonid Yes, that is the disadvantage. Auto-completion doesn't work. Theoretically this could be remedied by improving auto-completion in the front end ... – Szabolcs Mar 27 '13 at 21:41
  • Szabolcs' answer makes sense. But also thanks for pointing out documentation - which is often a struggle. One would think keyword registration and search to be entirely feasible. – alancalvitti Mar 27 '13 at 21:43
  • Talking about documentation and options, I still couldn't figure out how to use the "EdgeLayout" suboption of GraphLayout ... see here – Szabolcs Mar 27 '13 at 21:44
  • I also get Graph[<<4>>,<<3>>] with EdgeLayout in MMA9. Have you filed a note w/ tech support? – alancalvitti Mar 27 '13 at 22:11
  • @alancalvitti I posted a question here to find out more first. Last time I wrote to them I realised I should have waited a bit for answers here ... but yes, I will do that eventually. – Szabolcs Mar 27 '13 at 22:12
  • There is a little bit of autocompletion going on in 10.2 and friends... it keeps getting better with each iteration it seems. – flip Jul 31 '15 at 15:42
  • @flip I haven't noticed that, but it's great news. Can you give an example? – Szabolcs Jul 31 '15 at 16:07
  • See http://i.stack.imgur.com/FcPUE.png for one example. There are more that I've come across with plotting/graphics. – flip Jul 31 '15 at 22:40