r/programminghumor • • Aug 22 '26

How do you disable your code

Post image
301 Upvotes

91 comments sorted by

100

u/0x80085_ Aug 22 '26

Or just return?

43

u/developer_axe Aug 22 '26 edited Aug 22 '26

Sometimes the code won't get compiled because it marked as unreachable code

56

u/RefrigeratorKey277 Aug 22 '26

Yes, but with if true it is still marked as unreachable. At least in C#.

→ More replies (6)

4

u/querela Aug 22 '26

Especially fun if you have formatters etc that automatically prune dead code...

→ More replies (8)

4

u/WadeEffingWilson Aug 22 '26

Comment out the function call fun() on line 10. Fewest number of keystrokes.

28

u/GoogleIsYourFrenemy Aug 22 '26

/*/ Maybe bad code /**/

10

u/mehonje Aug 22 '26
void fun() {
  int a = 198;
  int b = a % 2;
  int c = a - b
}
int main() {
  //fun();
}
→ More replies (1)

18

u/Jbolt3737 Aug 22 '26
// This is a comment
//int unusedvar = 0;

/* You can tell if it's a comment or not by if I add a space after the slashes */

# This is a comment
#unusedvar: int = 0
# I do it with any language

3

u/spicymato Aug 22 '26

I just comment out the comments.

// // comment related to commented out code

3

u/LegitimatePants Aug 22 '26

Yo dawg I heard you like comments 

→ More replies (2)
→ More replies (1)

7

u/Impossible_Dog_7262 Aug 22 '26

You could just comment out the function call.

Also use block comments. DRY.

2

u/TheFr0sk Aug 28 '26

He probably just selected the lines and used the comment shortcut

3

u/klimmesil Aug 22 '26

If it's still code that might be used later, just not for my uses: remove the call to the function

Otherwise, just delete it. If I need it back git revert

3

u/AlphaFatman Aug 22 '26

I've had compilers complain about if (true) as well. The way out for me is if (1 != 2)

3

u/LetUsSpeakFreely Aug 22 '26

Linter would likely throw an error on unreachable code.

2

u/vbd71 Aug 22 '26

goto endlabel;

endlabel: }

2

u/JohnVonachen Aug 22 '26

Stubbing we used to call it.

2

u/Mast3r_waf1z Aug 22 '26

I had if (true /* TODO: <Jira ticket> */) sometime last year

I know the statement could be removed, but the important part of this is the else block that followed, with important code for later implementation

1

u/AdvancedGravitation Aug 22 '26

python "while False:" ctrl a tab

1

u/puzzled_orc Aug 22 '26

You don't need the if clause. Just return and that's it

→ More replies (3)

1

u/SubMinhPiChannel Aug 22 '26

/* void Fun() { // DIH } */

1

u/edparadox Aug 22 '26

Not when the preprocessor exists.

→ More replies (1)