Live data from Hacker News

Block Comments Are a Bad Idea

futhark-lang.org

71–80 of 84 posts

Re: Block Comments Are a Bad Idea

#71
post #27

Earlier quoted context omitted.

Many editors allow you to select the section and line-comment it as a whole.

Even vim has a visual block selection mode. at the top of the block, then move down (j or down arrow) to the bottom. That marks the block. Then type the I character (insert in front of cursor), type the comment character, and press . Once you press , the inserted comment character action is repeated for the whole block. Or non-visual block select...V% with cursor on the opening {.

Oh, my

  :vmap  :s|^|//|
  :vmap  :s|^//||
(writing from memory, may need tuning)

Re: Block Comments Are a Bad Idea

#72
post #68

Earlier quoted context omitted.

It's kind of surprising to me that anyone past junior-level development doesn't already have it hammered into them that "code is how you did something, code is why you did it". Also, if you can't possibly be any less clever in your code, then leave a comment explaining the "how", and apologize that you couldn't make it any simpler.

s/code is why/comment is why/, I think?

Doh, sorry, you are correct. I can't edit the comment any more, unfortunately.

Re: Block Comments Are a Bad Idea

#73

I like how Lua handles the problem, with multi-level open and close comment strings (and string strings). From Programming in Lua [1]: > A comment starts anywhere with a double hyphen (--) and runs until the end of the line. Lua also offers block comments, which start with --[[ and run until the corresponding ]]. A common trick, when we want to comment out a piece of code, is to write the following: --[[ print(10) --…

>local singleLineString = """...

Is it new syntax of 5.3?

Re: Block Comments Are a Bad Idea

#74

"I don't like something, therefore it is BAD " I've never had an issue with a block comment that couldn't be fixed in a couple seconds. The usefulness and readability of a well formatted block comment, especially for documentation generation, far outweighs any inconveniences in fixing a broken implementation.

"I don't have these problems, therefore they are not real problems" The author makes almost exactly your point regarding the (non)importance of these issues in practice. What would the author have to write in order to be able to discuss the consequences of this language design choice, and be spared the barb of your wit.

> "I don't have these problems, therefore they are not real problems"

What a major mischaracterization. It was the author that implied things were objectively bad. I stated that the subject is subjective, in that there are use cases where block comments are good.

Re: Block Comments Are a Bad Idea

#75
post #10

You don't have to solve all edge cases for a feature to be useful. At least not all the time. I, am not too unhappy with the behaviour of C/C++/Java/... - That the block comment will end at the first occurence of " * / ". If I accidentally close a comment too early (because there already was another block comment inside the code I want to comment), then... * The syntax highlighting of my IDE will tell me. * The compi…

This problem does fall under the umbrella of issues that have the obvious solution of "don't do that"

Re: Block Comments Are a Bad Idea

#76

Earlier quoted context omitted.

"I don't have these problems, therefore they are not real problems" The author makes almost exactly your point regarding the (non)importance of these issues in practice. What would the author have to write in order to be able to discuss the consequences of this language design choice, and be spared the barb of your wit.

> "I don't have these problems, therefore they are not real problems" What a major mischaracterization. It was the author that implied things were objectively bad . I stated that the subject is subjective , in that there are use cases where block comments are good.

What the author stated was:

> I will argue that block comments are unnecessary, and in fact near-impossible to design and implement correctly (for my own pedantic notion of correctness)

You might argue, subjectively or objectively, about the utility of the "notion of correctness" used here, but the author warns at the outset that this is the basis for the rest of the analysis.

I ask again, what preface would the author need to write to satisfy your criticism? I think that it's worthwhile for the author to point out that you cannot create a block comment scheme without having some un-intuitive edge cases, and I'm curious what gave you the impression that the author was claiming an unwarranted degree of objectivity.

Re: Block Comments Are a Bad Idea

#77
post #34

Commenting and uncommenting blocks in lua: --[[ commented = 123 --]] ---[[ uncommented = 456 --]] Commenting and uncommenting blocks by adding or removing a '-'. Pretty handy for trying stuff out. https://www.lua.org/pil/1.3.html

lua also allows you to define blocks like [=[ ... ]=] but with arbitrary, matching counts of '=' inside.

Using this style with your comment syntax handles having nested and/or dangling comment delimiters in the body.

It's probably the most comprehensive approach I've used. In practice, I've never actually needed more than one level of nesting or dangling but it's not particularly onerous to the parser to include the arbitrary levels.

Re: Block Comments Are a Bad Idea

#78

I will second this from bitter experience. Was translating a very old Pascal program. My editor didn't have syntax highlighting for it. Spent a couple hours translating a very large function. Wasn't until I finished that I realized it was wrapped in a very large block comment. That, and most decent editors have a "comment current selection" feature that makes single-line comments easy enough.

Why do you fault multiline comments and not your code editor?

Colors don't feel as robust to me as syntax.

   * color blindness
   * broken syntax above typically throws-off subsequent highlighting
   * touch a lot of embedded stuff where having any kind of editor at all (even without highlighting) is a luxury

Re: Block Comments Are a Bad Idea

#79
post #48

Earlier quoted context omitted.

"Visual programming" seems to have too many meanings. "Rich text" too. I meant code editors that "know" that you are writing code and make things easier for you. In other words, exactly the opposite to one that prompts absurd debates about if multiline comments are a good or a bad idea.

> make things easier for you This sounds a lot like "do what I mean." You have to tell the editor in some way that you want to write a block comment or not, and that you want to end it. My editor does make somethings easier for me - if I start a block comment, it automatically inserts the block comment closing character after my cursor. It does syntax highlighting of the block comments, so it's obvious at a glance wh…

I find it hard to imagine an editor with an interface which is easier and faster than entering simple text

So you call "entering simple text" to the automatic managing of comments that you just described? I can't honestly agree with that ;)

Re: Block Comments Are a Bad Idea

#80
post #52

Earlier quoted context omitted.

I don't know what you refer to. But anyway, be careful with discarding ideas that didn't work in the 80's. What was unpractical then could be very convenient today. Edit: actually I'm curious how much time it will take for my gp comment to go from "downvoted eccentricity" to obvious. More edit: I'm not only thinking in more computing power. We know a little more on usability and user experience now than then.

Like Light Table? In the 80s, it would be unimaginable that you could re-compile and run code with every keystroke, or watch the values of variables updating in real time. The demo ( http://lighttable.com/#see ) would be inconceivable.

That seems too complex. In the 80's there was TurboPascal, an IDE sold for $50 with step-by-step execution and variable inspection. Compilation was extremely fast.

I dislike doing things with every keystroke. I hate when I start typing something in an IDE and it rushes to underline the word with a disapproving red line.

Post reply on HN