r/programminghumor • • Aug 22 '26

How do you disable your code

/img/ng4rgeq6kvkh1.jpeg
297 Upvotes

91 comments sorted by

View all comments

Show parent comment

56

u/RefrigeratorKey277 Aug 22 '26

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

7

u/Here_f0r_p0rn_ Aug 22 '26

Depending on compiler settings for optimizations it can happen in C++ as well

6

u/[deleted] Aug 22 '26

[removed] — view removed comment

1

u/_giga_sss_ Aug 23 '26

I'met a genius

3

u/Due-Consequence9579 Aug 22 '26

Ah yes, well in C# you make the function a method on a class FuncImpl. Then you define an interface IFunc that exposes the func() contract. Then you spin up a DI container and register FuncImplFactory that takes an IConfiguration in its constructor. Then you define a bool EnableFunc { get; } configuration value into your Configuration. Then you have FuncImplFactory look at EnableFunc to decide to return FuncImpl or FuncStub, which implements IFunc but just returns. Them main simply asks the DI container for an IFunc and executes the func() implementation.

Enterprise!

1

u/RefrigeratorKey277 Aug 22 '26

You are thinking of Java.

1

u/Due-Consequence9579 Aug 22 '26

Oh sorry, FuncFactory just returns a lambda that invokes the right behavior.