r/programming • • May 10 '18

Java: Executing code in comments?!

http://programming.guide/java/executing-code-in-comments.html
260 Upvotes

84 comments sorted by

View all comments

1

u/DynamicTextureModify May 11 '18

So I'm not a Java guy... can someone explain to me the rationale behind parsing unicode expressions in comments? This doesn't seem like it should reasonably exist.

3

u/drysart May 11 '18

Java effectively does a pre-pass over a source file to replace all \u0000 sequences with the actual character that the escape references to. That it's in a comment is irrelevant; the escape sequences are parsed through the entire source file independent of any other context.

It's pretty idiotic, but it's Java so some level of brain damage is to be expected.

0

u/DynamicTextureModify May 11 '18

That's ridiculous. Brain damage is right.

I don't care if it's a "pre-pass" or not, commented lines should always be ignored.1


  1. Don't get me started on nonsense like those PHP interpreting engines that use fucking docblocks programmatically for database definitions and shit. I almost had an anyuerism when I started reading about that.

-2

u/recursive May 11 '18

That's how it already works. What you probably object to is how java defines "lines".

1

u/DynamicTextureModify May 12 '18

// \u000d System.out.println("Hello World!"); Is a line. It only becomes 2 lines after Java parses the unicode in this line. The fact that it reaches the point where it could be considered 2 lines is the problem in the first place.

1

u/recursive May 12 '18

I think we're all in agreement on that.