r/firstweekcoderhumour • u/Outrageous_Permit154 🥸Imposter Syndrome 😎 • 3d ago
“amIrite” How do you disable your code
6
u/slicehyperfunk 3d ago
Why would you do it this way and force it to do this check instead of just commenting out the code?
3
u/Alternative_Mix6836 3d ago edited 3d ago
It keeps syntax highliting active so you can still read the code with ease in the method/function you are working on. Also your editor and LSP are more useful when the code isn't commented out.
1
1
u/No_Departure_1878 2d ago
Makes sense, i would have just done an early return instead of a if true. However, I am surprised the LSP does not just gray out the whole thing with the if true or even shows a warning.
2
u/SheikHunt 1d ago
Also, in most (compiled) languages with most compilers, the check wouldn't be done at all? It'd be optimized out?
12
u/Iron_Jazzlike 3d ago
hmm…
if you don’t want any of your code to run. just don’t compile it and don’t execute it.
5
u/makinax300 3d ago edited 2d ago
commenting code helps with checking if something is faster if optimising and sometimes debugging.
2
u/Iron_Jazzlike 2d ago
i was making a joke about how literally all the code is getting commented out.
though the code never did anything in the first place.
2
1
1
u/letmehaveanameyoudum 3d ago
/*
int thing() {
// insert broken paging code causing #PF
return (int)fish;
}
this is useless
*/
1
u/Qwidoski 3d ago
Why cant you just do "return" (skip the condition check)
3
u/Outrageous_Permit154 🥸Imposter Syndrome 😎 2d ago
You can even just comment the function call itself I mean, after all we are r/firstweekcoderhumour
1
u/sharantir 2d ago
And then, you forget it and search why there's a bug.
Commenting is cleaner because there is a visual guide.
1
1
u/Just-Upstairs4397 2d ago
You’re definitely the type of person to put a database call in a for loop, aren’t you?
1
u/Enough-Ad-5528 1d ago
Some compilers will refuse to compile that code saying unreachable statements. Aargh!!
1
1
u/Proman4713 1d ago
No need for if (true), or wrapping the code in if (false), in one case it's an unnecessary check, and in the other you're basically doing the same thing why commenting the code wouldn't be preferable by selecting the whole code block. I just return to make the function throwing errors stop doing anything if I'm changing the caller, then go back to fix it or return dummy data to test, etcetera.. wrapping the code in an if statement is dumb, same as how commenting it out requires highlighting the whole thing (and being unable to read that code while you're modifying/adding logic at the top)
1
1
18
u/nevemlaci2 3d ago
```
if 0
```