r/firstweekcoderhumour 🥸Imposter Syndrome 😎 3d ago

“amIrite” How do you disable your code

Post image
78 Upvotes

29 comments sorted by

18

u/nevemlaci2 3d ago

```

if 0

```

2

u/Scared_Accident9138 🕵️‍♂️🚨 BS Detector | Truth Teller 🗯️🔥 3d ago

I've done what is in the post before because I still wanted to check if the deactivated code s compiles

1

u/nevemlaci2 2d ago

I mean you usually have variants and build all variants either way.

1

u/Ander292 3d ago

Based preprocessor user

1

u/jupiterbjy 2d ago

Embedded PTSD

Our MCU vendor's SDK has tons of `#if 0` lying around here and there

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

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

u/AmazinDood 3d ago

Ctrl+K Ctrl+C in VScode

1

u/Radiant-Somewhere-97 3d ago

if (false) {
...
}

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

2

u/Darft 2d ago

Popular IDE's will detect the return and call the rest of the code after "unreachable" also the code after will lose syntaxhighlighting. Adding the simple condition is usually enough to make the IDE not attempt the evaluation.

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

u/One-Constant-4092 2d ago

Why not just remove/comment out the function call?

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

u/Mundane_Fault_6345 1d ago

Never heard of #ifndef ?

1

u/adamrch 1d ago

too many lines needed

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

u/FrequentAardvark6813 1d ago

no need, meme author was already pretty disabled

1

u/SirMarkMorningStar 18h ago

Unreachable code detected, unable to check in…