Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Feature request: Block comment

dboggs
New Contributor I
585 Views

I know this has come up before but not for some time so I'll suggest it again.

I comment my code heavily, and often with multi-line and even paragraph-long comment blocks. Unfortunately the comment tool provided by Fortran is a real impediment to doing this, because (1) I must put a hard new line at the end of each line, and the VS editor does not usually return the cursor to the previous "!"; and (2) worse yet, editing an existing comment to increase the length of a line is so difficult that I am tempted to forget it, or reword and abbreviate awkwardly to avoid extending past my favorite length limit (I don't like to go past line 80).

Why can't the standards committee introduce a block comment syntax? I would suggest something like ![ to begin, and ]! to end, or !{ and }! (for C die-hards). This would make comments much easier to enter and more readable as well.

In addition, the VS editor should be able to handle line wrap to a user-defined right margin. Or even in the absence of an official Fortran syntax, the VS editor should be able to reformat block comments, using line wrapping to a pre-defined right margin while maintaining the leading ! on each new line.

Is there any reason why this shouldn't be done? Seems like a no-brainer to me.

0 Kudos
8 Replies
Steven_L_Intel1
Employee
585 Views

I don't recall a proposal for block comments coming up at meetings I have attended - it must have been proposed at some point. The syntax you suggest would never be accepted as it could make existing valid comments ambiguous. Off the top of my head, The C-style /* */ could work. I'll poke around to see if it came up before.

0 Kudos
mecej4
Honored Contributor III
585 Views

This topic has been gone over several times in several places. See, for example, https://software.intel.com/en-us/forums/topic/313488 (posted in 2001).

While you are awaiting changes in the Fortran standard and/or the VS editor to cover your desired features, you can use VBA macros as described in that thread (I don't know if they still work with newer versions of VS), or use the Fortran preprocessor or the C preprocessor:

#if 0

 <...block of comment lines...>

#endif

Note that you should use the /fpp option to process the C processor directives.

0 Kudos
andrew_4619
Honored Contributor III
585 Views

It doesn't fully answer the points but helps a bit.... In VS you can highlight a block of text and CTRL+KC (hold control then press/release K then  press/release C) to add ! at the start of each line. CTRL+KU  uncomments in the same way

There is also a word wrap feature CTR +EW but I do not know how that one works, never tried it...

0 Kudos
dboggs
New Contributor I
585 Views

Thanks for these responses.

To Steve: I could live with /* */, but it's too bad it can't be a simple & logical extension of the ! one-line comment. I do however recognize the backwards compatibility problem. Too bad they couldn't have foreseen the need for this when they introduced the ! comment line syntax in f90, so that a combination such as !{ or ![ could have been reserved for the start of a block!

How about !{{, or !{[cr/lf] (i.e. !{ on a line by itself)? Surely there can't be many occurrences of this in old code.

To mecej4: I was aware of this (or something similar) from a previous thread, but I will not use a workaround unless it is exceedingly simple and portable; another party looking at the code cannot be left wondering what those extra strange lines are for.

To app4619:  I was aware of CTRL+KU though not by the keyboard shortcut; there is a toolbar button that does this and is present by default, also a button to undo it. I was not aware of the word wrap feature. This is helpful but will not fill the bill. It will wrap an extended line to a new line but does nothing with the hard returns at the end. Merits more experimenting though.  

0 Kudos
IanH
Honored Contributor II
585 Views

Visual Studio is reasonably extensible.  Some years ago I wrote some macros to help reformat comment blocks in some existing code (this was associated with a switch from fixed to free form), which, after the initial up-front learning curve and time investment, worked reasonably well.  Depending on your needs something like this might be appropriate.

I only permit myself to be exposed to the trauma of a Visual Studio version change twice a decade or so, so I'm still on VS2010.  I understand that my macros are not supported in newer versions of VS - you now have to write an add-in.  I haven't gone there yet.

0 Kudos
Steven_L_Intel1
Employee
585 Views

! as a comment introducer was already widespread in F77 implementations. If the committee was going to take this on, Using an already well-known syntax (/* */) would be more attractive than trying to come up with an extension of ! (no matter what you do there the potential to break existing code is a show-stopper.)

0 Kudos
rorban
Beginner
585 Views

I use UltraEdit to do stuff like this. By using a combination of the column mode, auto-wrap, and the features Format>Convert CR/LF to Wrap and Format>Convert Wrap to CR/LF, it is fairly straightforward to (1) remove the leading ! in each line of a block comment, (2) remove the CR/LF from each line, converting all comments to one long line, (3) adjust the wrap by adjusting the width of the editor window, (4) edit the comment as desired, (5) restore CR/LF at the end of each displayed line (which are auto-wrapped at the right window boundary), and (6) insert new ! symbols at the beginning of each line. This could probably be done in two macros, one to convert the comments to one long line that is editable, and one to restore the line breaks and comment symbols.

I certainly agree that it would be convenient to be able to have more word-processor-like features in VS to handle block comments. 

0 Kudos
Steven_L_Intel1
Employee
585 Views

I did some research on this and found a 1994 proposal, one of a number of feature requests from the Canadian standards body, to add block comments with a suggested syntax of (! and !) as delimiters. I could find no other references to this, so I have to assume it was not accepted as a "work item" by WG5. I then sent an inquiry to the J3 mailing list, which has a number of "emeritus" members, and got some responses.

The general sentiment was that, as suggested above, modern text editors tend to include block comment operations so that there was less need for it. It was also suggested that it was possible to construct a valid source where use of the block comment delimiters would be ambiguous, though no examples were provided. Mainly it seemed that block comments were considered less important than other things being developed for the standard at the time, and I did not see any enthusiasm for trying again for the next standard after F2015.

0 Kudos
Reply