Should associate span across multiple lines?

Limiting associate to a single line, is not good for readability.

associate (rho => csv(1), urho => csv(2), vrho => csv(3), wrho => csv(4), erho => csv(5))
    ! code
end associate

We can use & to split this into multiple lines, but that feels awkward, and is error prone.

Often I find that I missed a comma , or &, and as a result, the code fails.

In my opinion, associate would have been easier to use, if it spanned across multiple lines, and did not depend on commas , or & for separating the expressions.

associate
rho => csv(1)
urho => csv(2)
vrho => csv(3)
wrho => csv(4)
erho => csv(5)
cells => mesh%cells
nodes => mesh%nodes
nc => mesh%num_cells
nn => mesh%num_nodes
begin
    ! code
end associate

I think this is easier to use because,

  • This follows the fortran convention of each statement being separated on each line, thus it is both easier to read, write, and edit.
    • If I want to delete an expression, I can delete the whole line easily.
    • If I want to add a new expression, I can add a new line easily
    • If I want to change the indices of csv(i), I can change them easily, by moving the cursor down one line at a time.
    • Reading this code is easier, and if I make a mistake, it’s easier to find in this form.
  • Since we don’t need commas , between the expressions, it is easier to use
  • Since we don’t need ampersands & to extend the lines, it is easier to use
  • This allows and encourages the users to use associate more, since it is easier to use, and we can assign as many expressions as we want in each associate block.
  • We can create complex expressions on each line
  • Nesting these associate blocks would be easier
  • Automatic code formatting would be easier

Thanks

There are several places where that sounds appealing. Perhaps when three colons are encountered from that point forward contigious whitespace and newlines are equivalent to a comma until the last newline before a line composed of nothing but spaces and three colons. So in addition to ASSOCIATE you could do numeric values, PUBLIC names, and some form of block text and comments. Block text and block comments are way past due.

associate :::
a =>b ! in-line comments are an issue to think about
::::

1 Like

This is a very nice idea!