[swift-evolution] Optional "endfor", "endif", etc after closing "}"

Jérôme Duquennoy jerome+swift at duquennoy.fr
Sat Dec 12 14:51:04 CST 2015


> What about this syntax?
> 
> for … {
>  if … {
>>  } /if
> } /for
> 

I have the feeling we are double defining the blocs here :
for ... /for is enough to have the beginning and the end if the bloc, and so is { ... }.

So I think that syntax is redundant.

I also think that such a solution would only solve half of the readability problem in a complex code.

Consider for exemple this piece of pseudo code : 
------------------------------------------------------
if (...) {
  if (...) {
    for (...) {
      // insert here a big number of lines
    }
  }
  
  if (...) {
    for (...) {
      // insert here a big number of lines
    }
  }
}
------------------------------------------------------
This thing end up with 3 closing block in the end, and if you have enough lines of code instead of the two comments, you don't see the beginning of those any more.
Considering the proposed syntax, you end up with that :

------------------------------------------------------
if (...) {
  if (...) {
    for (...) {
      // insert here a big number of lines
    } /for
  } /if
  
  if (...) {
    for (...) {
      // insert here a big number of lines
    } /for
  } / if
} /if
------------------------------------------------------

You have a bit more info, for sure. But not yet enough to clearly identify what bloc is being closed by a given line. To have it all, you would have to copy the whole condition ... but that would be copy / past.

In the end I have the feeling the advantage of the proposal is not huge, whatever the syntax. Not enough to add new keywords.
I agree with Marc that refactoring seems a good solution when it becomes hard to know what block ends where.

Jerome

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151212/77637774/attachment.html>


More information about the swift-evolution mailing list