Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

...I kind of wish compilers supported nested block comments. So if there's a /* inside of a /*, it would take two */'s to end it.

Idk, maybe that would be a terrible idea in practice. But there are lots of instances where it would have saved me time.



You're probably looking for "#if 0" / "#endif".


Yeah it took me a while to adopt this common practice when I need to "comment out" a large block of code. Just use the preprocessor, it's much simpler.


FWIW, replacing comments with whitespace is also done by the preprocessor.


The fact that you can't do this with new fangled languages is one of the reasons I don't use new fangled languages


That and other things I dislike about many of the new fangled languages.


I prefer using completely unfangled languages, thank you very much.


the D Language supports /+ and +/ as a variant of /* which supports nesting. So you can pick which you need for a given comment.


Not terrible at all.

It's super-useful to temporarily comment out a bit of code, and then to comment out a larger block surrounding it. Especially when debugging.

Sadly I've never used a language that supported that.


Common Lisp has nested comments with the #| reader macro.

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node191.html


How about explicit depth levels, specified by asterisk count?

e.g. '/*' and '*/' would match each other, '/**' and '**/' would match, and so on.

That way, you would have full control of the depth of the comments, removing other comments wouldn't break the inner comments, etc.

I do run into the same issue you're describing, so I think there's value in the idea.


The core idea here is that when I'm commenting out a block of code for testing, I don't really want to think about what is inside of it. So while I think this might help, I'd rather just have /* with one asterisk nest.

What I'm not sure of is whether there's an edge case I haven't thought of which would make this problematic.


Like Lua, where comments can be delimited by `--[==[`..`]==]`, where the number of equals signs can be anything but has to match in order for the comment to actually close?


FYI, Rust and many other modern languages do this.


Already an option on Borland compilers for MS-DOS.


I believe OCaml does this




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: