Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Block comments ala Ray



On Fri, Feb 12, 2021 at 7:17 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Tue, Feb 9, 2021 at 10:16 PM Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
> >
> > On Wed, Feb 10, 2021 at 7:05 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > >
> > > !# This begins a block comment.
> > > This is merely rambling.
> > > This #! is the last line of the block
> >
> > This can be very surprising because it's not how block comments work
> > in other popular languages.
>
> I don't find that very compelling, because in shell the alternative is
> to prefix every line with "#", which is exactly what Ray wants to
> avoid.

I understand that Ray wants this but I don't know why.

What are the benefits of this:

  !#
  Lorem ipsum
  dolor sit amet
  #!

over this:

  # Lorem ipsum
  # dolor sit amet

?

Do these benefits justify adding new syntax that's unique to zsh?

> Do you have inline comments in the shell now?

No. I use zsh as my main shell and it doesn't support inline comments.

>  Do you only care about
> inline comments that don't contain newlines?

Yes.

I should say that I don't care that much about inline comments. My
point is that I would only ever use block comments as inline comments
with no embedded newlines.

> Do you disagree with me about how strangely this --
>
> print this <# part is a comment
> (lah-di-dah for perhaps hundreds of lines)
> but this part #> is the rest of the command
>
> -- implicitly behaves if the embedded newlines can be inlined?

If this were valid syntax, I would expect it to work like in C. In
other words, I would expect there to be two commands:

  print this
  is the rest of the command

> I think Ray at least disagrees with you, since he's willing to abuse
> here-documents for the purpose, which also can't be inlined.

Ray does many things that I wouldn't recommend ;-)

> Do you not use block comments to delimit expository paragraphs?

No. I mostly write C++ and I use single-line comments for everything
except inline comments (those that don't span until the end of the
line). This is standard practice at Google. I believe this is common
in many other languages that have C-like comments (Java, C#, etc.).
Whenever I worked on a code base that used block comments, they
usually looked like this:

  /*
   * Lorem ipsum
   * dolor sit amet
   */

And almost never like this:

  /*
  Lorem ipsum
  dolor sit amet
  */

So block comments in my experience are most often used as if they were
single-line comments.

Roman.




Messages sorted by: Reverse Date, Date, Thread, Author