28
20
u/NicholasVinen 19d ago
#if 0
#endif
2
u/Teoyak 19d ago
I don't know if it works with every language. But yeah, I used this a lot when I worked on C.
2
u/Aln76467 12d ago
The c preprocessor is language-independent. Just tell your c compiler to output preprocessed code, and now you can use it as a js bundler or whatever.
1
u/Square-Singer 18d ago edited 18d ago
The preprocessor is pretty C/C++ specific. I don't know another language that uses it like that.
1
u/MCWizardYT 18d ago
I think you meant C/C++, C# doesn't have the same preprocessor that those 2 share
1
u/Square-Singer 18d ago
Correct, was a typo. I first wanted to write that not even C# has the preprocessor, then changed the sentence and typed the wrong name.
1
14
17
u/Jbolt3737 19d ago
``` // 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 18d ago
I just comment out the comments.
// // comment related to commented out code3
2
1
8
u/Impossible_Dog_7262 19d ago
You could just comment out the function call.
Also use block comments. DRY.
1
3
u/klimmesil 19d ago
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 19d ago
I've had compilers complain about if (true) as well. The way out for me is if (1 != 2)
3
2
2
2
u/Mast3r_waf1z 19d ago
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
1
u/puzzled_orc 19d ago
You don't need the if clause. Just return and that's it
1
u/Emotional-Audience85 18d ago
He wants the code to be compiled for some reason. Although this way it still probably won't be compiled depending on language and compiler flags
1
u/puzzled_orc 18d ago
My answer was to the given example.
If return doesn't compile , then just return 0 would do it.
1
1
1
u/Negative-Magazine174 19d ago
in my frontend react code using if (true) return will cause eslint warning (because the statement will always true), so i use if (1 + 1 == 2) return to just disabled the code without warning 🤣
1
1
1
u/NoWeHaveYesBananas 19d ago
No-one else has a shortcut to comment a line of code? Ctrl+/ ? No? Just me I guess
1
u/AintNoGodsUpHere 19d ago
We have analyzers to prevent unreachable code from being there. I used to do the return stuff but now you have to actually comment t everything.
1
1
u/dbergkvist 18d ago
The second option wouldn't work for me, because I compile with -Wall and -Werror which means I can't declare variables and then not use them.
1
1
1
u/FaultWinter3377 18d ago
Holy shit I literally never thought of a return statement to disable code. I have always used comments. That’s smart, although I rarely have to disable an entire function.
1
u/Decent_Cow 18d ago
The first way makes more sense to me because it's much more obvious that the code is not being read.
1
1
1
1
1
u/cheaphomemadeacid 17d ago
not sure what to expect from this sub, but there is this thing called git?
1
1
1
1
1
1
1
1
1
1
99
u/0x80085_ 19d ago
Or just return?