String Interpolation
shyiko opened this issue · comments
Should ${property}
be always used instead of $property
?
Some of the reasons in favor of the former:
- no need to add
{..}
wheneverproperty
becomesproperty.value
(or some other expression containing.
(in this particular case IDE can help)) (and vice versa, no need to remove{}
when going fromproperty.value
topropperty
) - no need to add
{...}
just to prevent a clash with the text that follows the expression in the same string template (e.g.$property/0
->${property}0
) more visually distinguishable from the rest of the text(matter of personal taste)- one rule = no need to switch between two different styles that accomplish the same thing (except that
${...}
is a proper superset of$property
)
NOTE: Redundant curly braces in string template
is set to "Weak Warning" by default in Intellij IDEA.
EDIT: crossed out 3rd item (based on #39 (comment)) & added a comment about IDE to the 1st.
Everything else still stands.
I think, for consistency's sake, we should always use the curly braces. How would one go about muting the warning that intellij shows for redundant curly braces?
The current draft of the style guide explicitly says that curly braces in string interpolation should not be used when not required. Code without extra curly braces is easier to read, and all the arguments you have provided apply to code modifications, not code reading.