Skip to content

ifs, lambdas, type declarations, etc. #5744

@giedriusbruzas

Description

@giedriusbruzas

A few notes that I have regarding this great piece of work. Hopefully not too late and not too pretentious.

if

  • I think there's more to expressions than just small expressions and large expressions. Could this be clarified a bit? How about differentiating between multi-line, single-line short (simple values) and single-line long (function evaluations) expressions?
  • When e1 and e2 are both single-line (short or long) expressions, I almost always choose this:
    if cond
    then e1
    else e2
    I like the way it looks like a match. then and else are same length - great coincidence (or design!) IMHO. I guess one drawback is that you kind of need IDE to highlight the relevant bits to look really nice.
  • I would personally avoid this even if expressions are of different size:
    if cond then e1
    else
        e2
    I prefer e1 and e2 to be at the same distance from the left side of the window (on the same level). The example above breaks the logical structure of the construct.

Lambdas

Why not like this:

let printListWithOffset a list1 =
    List.iter
        (fun elem ->
            c1) // When c1 is multi-line
        list1

Or:

let printListWithOffset a list1 =
    List.iter
        (fun elem -> c1) // When c1 is single-line
        list1

This matches nicely with the function parameter application formatting guidelines. No dangling parentheses.

Other notes

  • One-liner match example looks complicated. Is there a good reason not to break that into three lines?
  • I'm missing guidelines on how to format explicit type declarations. Especially of interest are the more complicated cases - multiple parameters, generics, functions.
  • I see value in the multi-line comments. When changing the content of the comment I often need to break the lines in different places than previously. In those cases the // are in the way.
  • And finally, perhaps all of my questions could have been avoided :) I think it's very valuable with controversial topics such as style guides to have argumentation close at hand to justify the choices taken in more detail. Not necessarily in the guide itself, but perhaps in a separate article, or footnotes?

Again, thanks for the lovely work.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions