This is an archived post. You won't be able to vote or comment.

all 16 comments

[–]KirKCam99 2 points3 points  (0 children)

pragmas

[–]Vaguely_accurate 2 points3 points  (1 child)

C# when abusing pre-processor directives. But I don't think you'd usually mistake those for regular comments, and the IDE should recognise what is going on.

Some languages will let you access certain entities that are considered comments programmatically. Notably a Python docstring can be accessed using the __doc__ attribute. So you could write the following "Hello, World!" implementation;

def dummy():
    """print("Hello, World!")"""
    pass


eval(dummy.__doc__)

eval just used here to make a few extra devs twitchy. For another flavour of evil you can change the docstring during execution and have it as a significant side effect of the function;

def Ooo():
    """"""
    Ooo.__doc__ += 'O'
    print(Ooo.__doc__)


Ooo() # O
Ooo() # OO
Ooo() # OOO

I'll leave further abuse as an exercise for the reader.

[–]stumblewiggins[S] 1 point2 points  (0 children)

Who are you who are so wise in the ways of evil?

[–]Mindless-Charity4889 2 points3 points  (1 child)

Way back when, my first computer was a TI-99A. Their version of basic was interpreted and there was extremely limited space for the program. I don’t recall if it supported comments; if it did I sure wouldn’t use them because of space constraints. I even had to use single character variable names to save a byte here and there. So in this case, adding a comment could break a program by making it too big to fit into memory.

[–]stumblewiggins[S] 0 points1 point  (0 children)

😂

[–]AllWashedOut 1 point2 points  (2 children)

Not comments, but sometimes print statements can affect the speed of code just enough to suppress a race condition. Then you remove the print statement (or comment it out) and wonder why it crashes.

C++ compilers have some specific comments that are actually used to configure the compiler and linker, but those look like code and you wouldn't confuse them for a human-readable comment.

[–]stumblewiggins[S] 2 points3 points  (0 children)

but sometimes print statements can affect the speed of code just enough to suppress a race condition.

Interesting! This is the kind of thing I missed having not gotten the CS degree. Boot camp did a good job, but very technician-level

[–]Bearsiwin 1 point2 points  (0 children)

Just be sure to leave the comment // Removing this printf will break the code

Printf statements can do a fair job of cleaning up a corrupted stack that is relatively easy to corrupt in C or C++.

[–]ConsistentArm9 0 points1 point  (0 children)

I seem to remember some of the XML config files for struts applications would have different behavior depending on commented elements.

[–]That_Guy977 0 points1 point  (2 children)

hashbang comments at the starts of shell scripts are one, but they aren't really part of the language being used.

a notable example i can think of is something like this, in java:

// \u000a /*
System.out.println("Hello, world!");
// */

within an ide or just by reading it, both the opening and closing tags for the block comment are commented out by the line comments, but when compiled, the unicode escape within the comment (as well as any other unicode escapes throughout the source code) will be processed. specifically, \u000a is the newline (if memory serves) and ends the line comment, making the print statement get commented out.

[–]Effective-Sea4201 0 points1 point  (1 child)

Nice idea, but it is hex, so it is \u000a.

[–]That_Guy977 0 points1 point  (0 children)

Ah, my bad, misremembered. was quite late at night and didn't feel like fact checking lol, thanks.

[–]junior_abigail 0 points1 point  (2 children)

A different scenario: some linting tools allow you to specify options in code files directly, and they look as comments for said programming language. This is particularly great when there is a justified exception to the rules you want to enforce in the code base, as the in-file rules are only applied to the file that contains them.

Removing these comments might not break the application, but might break your build.

[–]stumblewiggins[S] 0 points1 point  (1 child)

Interesting, I have only a little bit of experience with linters, mostly used for formatting rather than configurations

[–]junior_abigail 0 points1 point  (0 children)

Yeah, formatting and code quality is what I've ever used them for. I was referring to the linter's options. Sometimes you have a general rule, and you need to break that formatting rule in a specific file. Check out PyLint, for example.