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.
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.
See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.
Subscribe to:
Post Comments (Atom)
3 comments:
VHDL (and I guess ADA) has some of that in that function calls and instantiations can have their arguments mapped in any order, but named:
fn(
arg2 => 1,
arg1 => 100,
arg3 => "Hello");
I like keyword arguments, but comments from beginning of line are a separate issue. Similar, since comments often make up for the lack of keyword arguments, but separate, since comments can be used for many other purposes.
Although I suppose that one could say that all human readable names in programs - anything other than register numbers and numeric memory locations - are just comments. Comments that have semantic effect.
One interesting syntax that you did not consider:
comment_content \\ code;
This has a symmetry with C99/C++ "//" comments. Everything in the leaning-to direction from the comment marker until the edge of the line is a comment. One problem with "\\" is that "\" is often used as an escape character and "\\" as a non-escaping "\".
A "code // comment \\ code;" syntax might have been worth considering if "\\" comments were practical.
I do not know if "\\" meets the not "visually heavyweight" requirement. It seems a little visually lighter than "/* */" (not having a preceding mark and the two simple lines kind of elide into a single line), and it would be slightly easier to type (I think--key repeat versus two separate keys--perhaps especially on QWERTY where the "*" requires a shift and the same hand is used for somewhat widely separated keys).
Post a Comment