The crystal formatter “ignores” the line continuation character ‘\’ by deleting the end-of-line character that follows.
Personally, I find the use of this line continuation character very convenient when a line of code exceeds the standard width of the editor, and when the context hardly allows to do otherwise.
So I wonder about this choice : is it a concern of standardization or a technical reason ?
Ahh so in actual code. Normally given the formatter actually does something already, i’d say it’s a standardization thing. I couldn’t find any previous discussion about it tho.
Is this example similar to your actual use case, or I’m assuming a contrived example just to show off the behavior?
No, this piece of code is taken from a real case: I simply reduced the code to the minimum and changed the variable names.
I have other examples, too.
Personally, I would think that the introduction by the programmer of a line continuation character in the source code should be respected. Hence my question!
Here is another example, this time unmodified, from my source code.
What I wrote and expected to be kept as is:
required_increase.times do
narrowest_column = expandable_columns.reduce(expandable_columns.first) \
do |narrowest, column|
column.width <= narrowest.width ? column : narrowest
end
narrowest_column.width += 1
end
what the formatter rendered:
required_increase.times do
narrowest_column = expandable_columns.reduce(expandable_columns.first) do |narrowest, column|
column.width <= narrowest.width ? column : narrowest
end
narrowest_column.width += 1
end
Strangely, the code below is rendered as is by the formatter!
I agree with this.
I usually would tell people that long lines are a sign of an opportunity to simplify and clarify, but there are legitimate cases and it’s not generally bad.