Disclaimer

The content of this blog is my personal opinion only. Although I am an employee - currently of Nvidia, in the past of other companies such as Iagination Technologies, MIPS, Intellectual Ventures, Intel, AMD, Motorola, and Gould - I reveal this only so that the reader may account for any possible bias I may have towards my employer's products. The statements I make here in no way represent my employer's position, nor am I authorized to speak on behalf of my employer. In fact, this posting may not even represent my personal opinion, since occasionally I play devil's advocate.

See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.

Tuesday, May 01, 2012

Comments at beginning of line?

code; // we have comments at the end of a line
code /* and comments anywhere on a line, like in the middle */ code;
/* where "anywhere" can be at the beginning: */ code;

but it occurs to me that I often want comments at the beginning of a line, e.g.

foo(
     /* arg1= */ 111,
     /* arg2= */ 222,
)

and although /*...*/ can accomplish this, they are visually heavyweight.

I wonder if, in a hypothetical new language, we could have comments from the beginning of a line?

Now, ":" would be the most natural comment delimiter for this - if it were not already used for so much else:


foo(
     arg1:  111,
     arg2:  222,
)


Note that I have distinguished comments in a special color. One might say that such a special comment color is what we really want... I agree, and have discussed that elsewhere.  But it is certainly traditional to have program text read monocolor:


foo(
     arg1:  111,
     arg2:  222,
)


Now, you might also argue that keyword arguments subsume the example above.  Sure... but then I can create other examples that are not keyword arguments.

I can imagine comment from beginning of line delimiters other than colon, but none are quite so elegant:


foo(
     arg1>>>  111,
     arg2:>>> 222,
)



foo(
     arg1==>  111,
     arg2==> 222,
)



foo(
     arg1:::  111,
     arg2::: 222,
)


Again, we are limited by the ASCII, or UTF, character set.