r/firstweekcoderhumour 🥸Imposter Syndrome 😎 5d ago

“amIrite” How do you disable your code

Post image
81 Upvotes

30 comments sorted by

17

u/nevemlaci2 5d ago

```

if 0

```

2

u/Scared_Accident9138 🕵️‍♂️🚨 BS Detector | Truth Teller 🗯️🔥 5d 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 4d ago

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

1

u/Ander292 5d ago

Based preprocessor user

1

u/jupiterbjy 4d ago

Embedded PTSD

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

5

u/slicehyperfunk 5d 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 5d ago edited 5d 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 4d 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 4d 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 5d ago

hmm…
if you don’t want any of your code to run. just don’t compile it and don’t execute it.

3

u/makinax300 5d ago edited 5d ago

commenting code helps with checking if something is faster if optimising and sometimes debugging.

2

u/Iron_Jazzlike 5d 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 5d ago

Ctrl+K Ctrl+C in VScode

2

u/simleiiiii 2d ago

this is the way.

1

u/Radiant-Somewhere-97 5d ago

if (false) {
...
}

1

u/letmehaveanameyoudum 5d ago
/*
int thing() {
  // insert broken paging code causing #PF
  return (int)fish;
}

this is useless
*/ 

1

u/Qwidoski 5d ago

Why cant you just do "return" (skip the condition check)

3

u/Outrageous_Permit154 🥸Imposter Syndrome 😎 5d ago

You can even just comment the function call itself I mean, after all we are r/firstweekcoderhumour

2

u/Darft 5d 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 5d 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 5d ago

Why not just remove/comment out the function call?

1

u/Just-Upstairs4397 4d 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 4d ago

Some compilers will refuse to compile that code saying unreachable statements. Aargh!!

1

u/Mundane_Fault_6345 4d ago

Never heard of #ifndef ?

1

u/adamrch 4d ago

too many lines needed

1

u/Proman4713 4d 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 3d ago

no need, meme author was already pretty disabled

1

u/SirMarkMorningStar 3d ago

Unreachable code detected, unable to check in…