Block close check

Chris Nicholson-Sauls ibisbasenji at gmail.com
Mon Dec 11 18:01:10 PST 2006


Brad Roberts wrote:
> Chris Nicholson-Sauls wrote:
>> BCS wrote:
>>> What might be the most useful would be for the compiler to check for 
>>> a comment at the end of a block and if it clams to close a block that 
>>> it doesn't, emit a warning.
>>>
>>>
>>> //////these pass
>>>
>>>
>>> for(int i=0;i<10;i++){
>>>     ...
>>> }//CLOSE for i
>>>
>>> while(j<k){
>>>     ...
>>> }/*CLOSE while j < k this block has more comments */
>>>
>>> outer: switch(n){
>>>     ...
>>> }/+CLOSE outer: +/
>>>
>>>
>>> //////these fail
>>>
>>>
>>> inner: switch(n){
>>>     ...
>>> }//CLOSE outer:
>>>
>>> for(int i=0;i<10;i++){
>>>     ...
>>> }//CLOSE for j
>>
>> Now that's actually not a bad idea.  Keeps it "green" when editing, 
>> remains optional, and provides more than just the visual cue (if the 
>> compiler in use supports it).  Might've been useful in some of the 
>> more convoluted things I've written (like a few parsers/lexers with 
>> insane nesting).
>>
>> -- Chris Nicholson-Sauls
> 
> Having the compiler care about contents of a comment is a dangerous 
> slippery slope.  If you want to do this in some sort of a lint-esque 
> tool, then go for it, I guess.
> 
> Later,
> Brad

Generally true...  And probably would be the better way to go.  We do, however, have some 
minor precedant in DMD's DDoc feature which is based entirely in comments.  ;)  Granted 
that's already proven a little dangerous, but useful.

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list