r/ProgrammerHumor • • 21h ago

Meme weMaintainThemDeleteThemSurely

Post image
1.1k Upvotes

47 comments sorted by

250

u/naveenda 17h ago

What's wrong with that?

416

u/PattuX 15h ago

OP ist active in Java communities. They probably prefer an AbstractFeatureFlagResolutionStrategyFactoryBean or some shit.

112

u/awesome-alpaca-ace 14h ago

No shit. I found a factory of factories that creates objects with their own factories in the C++ codebase I work in. Triple factory. I was impressed.

72

u/BernzSed 13h ago

Well where else would factory factories come from? The factory factory fairy?

26

u/forsvinne 12h ago

After the third layer, the programmer falls into the limbo, an unconstructed pointerless plane. Factories become their reality. Only a garbage collection can bring them back to reality

3

u/pipedreamSEA 11h ago

Ooh I've seen this one before, I think it was called "Indirection"

1

u/forsvinne 10h ago

More like ‘injection’

1

u/ljfa2 5h ago

template<typename... T> constexpr decltype(auto) foo(T&&... args) { return bar(std::forward<T...>(args...)); }

2

u/-Kerrigan- 5h ago

I got a decade of working with JVM. if statements for feature flags are fine, all that matters is where you put them so you don't have 300 statements for a flag

1

u/hiromasaki 3h ago

Really, what are the options?

It's either if statements in the logic or if statements when binding implementations in the injection framework.

8

u/MariusDelacriox 11h ago

It can be a mess to cleanup and opens the door to untested or incomplete code to be active in production if simply misconfigured.

7

u/d0zza 6h ago

If it's a mess to clean up you've done feature flags wrong

81

u/Ahmouse 16h ago

REAL programmers use C macros

40

u/DefiantGibbon 16h ago

I actually love macros. My company has them everywhere, and we set up a compile flag to create a "preprocess" file that's basically what the code looks like after all the macros and aliases have the real values subbed in if you care to look at that. 

28

u/Banes_Addiction 13h ago

Macros are legitimately good for systems programming. Haven't got the dependency for a specific feature? Just don't build it. Need a piece of code to run balls to the wall? Compile in only exactly which code branches will be used in execution. Etc etc.

5

u/Grumbledwarfskin 12h ago

I always feel weird about macros.

C used to have a feature for telling the compiler whether to inline a function or not, but they deprecated that feature because it was decided that programmers were terrible at determining whether it was beneficial to inline a function or not, and inlining should be left up to the compiler alone.

Meanwhile, function macros are mostly just inline functions with serious flaws that regularly lead to problems...plus, due to implementation details, they can only be inlined, even if the person who wrote them was wrong about inlining the function everywhere it's used being optimal.

If the compiler is so much better at figuring out when it's optimal to inline a piece of code, why didn't we deprecate function macros alongside the 'inline' flag?

7

u/incest-duck 11h ago

This is not a good take. "function" macros, if you wish to call them that, have totally different semantic than functions. The still do just a text replacement, and are really useful for generic code blocks. Want some code that works for multiple types? Use a parameterized macro.

3

u/gbchaosmaster 11h ago

Because that would be a majorly breaking change.

1

u/Ahmouse 11h ago

C is used a lot in bare metal programming/embedded systems, where there are actual use cases for stuff like that. There's no harm to keeping it available in the language, just only use it if you need it.

1

u/Banes_Addiction 4h ago

A function macro is just a text replacement.

Actual functions have types etc.

One of the textbook examples is a square. You #define SQR(x) x*x

Compare this to say: double sqr(double x) return x*x;

That carries a tonne more meaning. It implicitly converts our types to a double precision floating point number. Maybe we copy x into a new variable, maybe the compiler optimises that out. Now, we could write a hundred different overloads of this to safely handle any possible types we might want to square, but they all run into the simple problem: we didn't want a function. We wanted a text shorthand.

1

u/tiajuanat 8h ago

This was why I liked C++ templates for embedded for so long - basically typechecked macros.

Then rust came along

20

u/jewdai 14h ago

I think they might be referring to runtime feature flags managed by a third party provider.

12

u/wthja 9h ago

How else should I implement it? Feature flag is turned on/off remotely, hence a simple if statement after reading from remote.

6

u/AZMPlay 15h ago edited 7h ago

Any compiler/preprocessor worth its salt will implement feature flags by including/excluding code wholesale.

Any optimizer worth its salt will optimize away the constant condition in an if statement away otherwise.

Edit: Egg on my face, I had forgotten about runtime feature flags. Damn.

56

u/NaCl-more 13h ago

Service feature flags cannot be compiled out because the whole point of them is to be able to dynamically turn them on and off without a whole deployment

23

u/BernzSed 13h ago

There are many use cases where you can't know at compile time which features will be enabled.

-19

u/void1984 13h ago

These are runtime options, not feature flags.

3

u/sisisisi1997 6h ago

We can argue about the name, but "this frature has to go live on the 15th at midnight, noone wants to be here, and the deploy is too long anyways to turn it on precisely at midnight" requires you to put an if(now() > getActivationDate()) somewhere.

-3

u/void1984 6h ago

Yup, that's an option. Flags are used to never compile the excluded portion of the code. I think some voters got confused.

3

u/sisisisi1997 6h ago

If you exclude the code at compile time, how do you plan to turn it on without another deploy? Of course there are cases where another deploy is an option, I tried to provide one where it isn't, or it isn't a good option.

0

u/void1984 5h ago

I don't plan for that customer at all. That's why we use flags - to adjust functionality for each customer.

20

u/Ma4r 13h ago

Until you need to implement a user bound feature flag

5

u/NomaTyx 13h ago

"requires app restart"

5

u/Abadabadon 10h ago

Why would you want that at compile time and not runtime? Like if you deploy to prod, see your festure is buggy/not working/isnt allowed to be active until 3 days post prod release, you can toggle it instantly

1

u/cheezballs 3h ago

The feature flags we're all talkin about don't come in at compile time. Also, your app sucks if you have to recompile to enable a feature. How do you do A/B testing?

1

u/SecureVillage 9h ago

We've recently baked all this in to our harness and automated processes so flags get created automatically, we have a ceremony around turning them on, then they soak in prod, while we're monitoring, before a PR for flag removal gets created by an agent.

You do need some kind of flag process otherwise they litter the codebase, or you forget to turn them on in prod, or whatever.

7

u/[deleted] 21h ago

[removed] — view removed comment

13

u/neroe5 20h ago

Match?

-50

u/[deleted] 19h ago

[removed] — view removed comment

21

u/neroe5 19h ago

I'm going to need some kind of context, are we talking regex, some feature in some programming language or what?

-43

u/[deleted] 19h ago

[removed] — view removed comment

39

u/Many_Replacement_688 18h ago

it's like if statement but without the condition part

2

u/neroe5 5h ago

Kinda, though behind the scenes pattern matching (if implemented correctly) is closer to a dictionary, so it's constant speed instead of having to go through each case

25

u/neroe5 18h ago

ahh pattern matching

37

u/tomangelo2 18h ago

Oh, switch...case?

9

u/HandleUnlikely2589 16h ago

It has a lot more power in terms of full pattern matching and object deconstruction, but yes, the simplest forms are glorified switch statements from C (except they're actually expressions, they can return a value; Rust is nearly purely expressions, even for conditional-like code structures).

49

u/Sermuns 17h ago

what's the matter vagueposting king? afraid to say something?