-
Notifications
You must be signed in to change notification settings - Fork 14
vertical formatting #23
Comments
I think that at least (1) can be implemented as an option in the formatter, but I don't think the default style guide should give any guidance for or against it. I think that trying to align anything other than the assignment statements automatically would be far more surprising than useful, but at least we can ensure that the formatter doesn't ruin the alignment done manually. |
Another case is function headers. Since the syntax is so complex, vertical alignment really improves readability. What case of alignment below would you prefer provided that it is done with the formatter?
|
@voddan maybe there should be different types in (2)? All these String-s looks too perfect |
|
The problem with any kind of vertical alignment is that, while it's easy to implement in a batch code formatting tool, it's much more difficult to maintain during regular code editing, both when you initially type a declaration and when you change something. I want it to be easy to write style-guide-compliant code without the use of batch formatting tools or super-smart IDEs. Because of that, vertical alignment will not be a requirement in the style guide. |
Citing the above rationale, I would propose to put a recommendation not to use vertical alignment into the style guide. One should try to design and layout code so that vertical alignment is not needed to make code readable. |
@stepango ,ktlint would throw waning like
on the first line of class declaration |
I was wondering what are the views on vertical formatting, e.i. putting similar code one under another:
The example above demonstrates vertical formatting for:
a. The assignments (
=
)b. The operators (
+
)c. The pair operators (
+
and-
)d. Brackets
()
or[]
e. The function parameters on invocations
I think it is popular in Haskel and Scala. This practice does make code more readable, and more importantly, prevents typos, e.i in situations like that one:
This code snippet utilises vertical formatting for (b) the
+
operators, (d) brackets[]
and (e) function parametersj
.The down side is that currently InteliJ Idea has no support for it in the Kotlin plugin. That means that the IJ auto-formatter ruins any vertical-aligned code. Also this is very time consuming when done by hands.
I separated the use cases into 5 categories (a, b, c d, e) because their may be considered useful or unuseful independently of each other. The categories are sorted from the most useful IMHO.
The text was updated successfully, but these errors were encountered: