I am starting to develop multi-machine vagrant setups. I have noticed two methods of naming conventions in vagrant files for defining the machine name. The first method is with a "colon" before the name of the machine. The second is with the machine name in double-quotes. This comes on the line such as
config.vm.define :boxname .....
or
config.vm.define "boxname" .....
I have seen it both ways in github. is there a prescribed method/reason or is this just preference?
The different "conventions" have to do with the fact that Vagrant files actually are Ruby snippets. In Ruby
"foo"
is a string object similar to strings in other languages. However, in contrast to most other languages Ruby string objects are mutable.:foo
is a symbol object. Symbols provide an efficient way of referring to something with a human-readable name without dragging this often lengthy name around behind the scenes. Symbols with the same name always refer to the same symbol object - even if they are referred to in different places of the code.Vagrant supports using one or the other but to me using a symbol feels more natural in this use case. Also, if you use strings the Ruby interpreter has to compare the whole string character by character to decide if they are identical whereas comparing symbols boils down to comparing pointers.