Live data from Hacker News

Block Comments Are a Bad Idea

futhark-lang.org

11–20 of 84 posts

Re: Block Comments Are a Bad Idea

#11
post #8
post #7

This is my personal preference, but from experience I prefer languages that don't shun concepts because they're bad programming practice. I can understand if something is difficult to implement or prevents other features from being added, but if a feature is possible, I say add it---it might come in handy sometimes. There's a reason languages like C, C++, Ruby, and Javascript are immensely popular. It's because progr…

See also GOTO which is a wart 99.9% of the time but really useful for writing e.g. parsers.

Error handling.

Re: Block Comments Are a Bad Idea

#12
post #5

Surely the solution is heredocs? You effectively define your own comment closing string at the comment opening point.

Yes, heredocs (or "here-comments", since you want them ignored, not just stored in a string variable) would likely be a solution for all but the most pedantic. The final recourse of the pedant would be to point out that no single closing string would be appropriate in all cases, and you are in principle required to read the code you want to comment out, in order to find a closing string that is not already contained within it.

Re: Block Comments Are a Bad Idea

#13
OCaml actually has correct block comments by his definition (and no line comments). This does lead to the odd fact that you can't have an unterminated string literal in a comment, which usually isn't a problem, but can be surprising.

Re: Block Comments Are a Bad Idea

#14
This is one of the signs that we're doing it wrong with programming languages.

We're dealing with text. A program can be expressed in text, actually every piece of information can be converted to text some way or another. The question is if it's the right way to do it. It's not.

I know why we chose text at the time. It doesn't make sense today.

In this case, we should be using a tool that would let us write comments without worrying about delimiters or escaped characters. That's so 20th century.

Re: Block Comments Are a Bad Idea

#15
One thing which isn't mentioned here (which i've encountered before) is when conflict tags from source control get thrown into the middle of block comments, and then committed - which leads to all kinds of headaches. This wouldn't happen with line comments.

Additionally..

> This is perfectly cromulent Haskell.

I'm still impressed whenever someone can correctly use this word to embiggen the subject under discussion.

Re: Block Comments Are a Bad Idea

#16

Commenting out whole sections of code incredibly useful for debugging and rapid prototyping.

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

Exactly. In java, block comments are used at the beginning of a class or method for javadoc generation. If I want to comment out big portions of code, I use line-comment thanks to eclipse. With this working practice, the problem does not exist. Never use block comments for commenting out big portions of code.

Re: Block Comments Are a Bad Idea

#17
post #11
post #8

Earlier quoted context omitted.

See also GOTO which is a wart 99.9% of the time but really useful for writing e.g. parsers.

Error handling.

In most languages there are better way to do this than goto. Among them - extracting code into smaller functions (yes, state has to passed around) - exceptions (yeah yeah, hate them or love them, but if used in your environment it makes sense not to avoid them) - RAII pattern or handling cleanup, which allows simple return and "automatic" resource handling - etc.

True, in a language like C these don't apply necessarily and goto still has some use -

Re: Block Comments Are a Bad Idea

#18
"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.

Re: Block Comments Are a Bad Idea

#19
post #9

The D Programming language has a neat trick to block commenting out code for debugging purposes. Wrapping code in a version(none) {} block will exclude the block from compilation. The code inside the block must still be syntactically valid so it avoids the problem mentioned in the linked post. The D Programming Language - Conditional Compilation: https://dlang.org/spec/version.html

Ditto for Common Lisp, where conditional compilation (with #+ and #- reader macros) is widely used to comment out s-expressions.

EDIT: I only now noticed it was mentioned in the article. I'll therefore add that the example from the article, of using #+nil, is actually not recommended, because it's technically possible that somebody adds a feature flag called "nil". Therefore, it's preferred to use #+(or) or #-(and) for comments (they're degenerate forms of conditional compilation expressions like #+(or flag1 flag2 flag3)).

Post reply on HN