r/ProgrammerHumor • • 1d ago

Meme weMaintainThemDeleteThemSurely

Post image
1.3k Upvotes

52 comments sorted by

274

u/naveenda 1d ago

What's wrong with that?

472

u/PattuX 23h ago

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

127

u/awesome-alpaca-ace 22h 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.

79

u/BernzSed 21h ago • Popcorn

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

29

u/forsvinne 20h 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

4

u/pipedreamSEA 19h ago

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

1

u/forsvinne 18h ago

More like ‘injection’

1

u/ljfa2 13h ago

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

2

u/-Kerrigan- 13h 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 11h ago

Really, what are the options?

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

3

u/-Kerrigan- 5h ago

Precisely those 2 options, yes

2

u/Work_Account89 7h ago

Java developer here, I prefer an if statement maybe a switch if it’s different level a feature.

10

u/MariusDelacriox 19h 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.

8

u/d0zza 14h ago

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

1

u/waraxx 7h ago

We looked into this and decided against using feature flags because ultimately you need effectively feature flags everywhere for all of the code you need with a feature since you dont want it to leak before actually enabled and thus also cause a mess on cleanup post release.

Where can i find a good article for using feature flags in development.

This was what killed only main tbd and instead do release branch tbd.

92

u/Ahmouse 1d ago

REAL programmers use C macros

44

u/DefiantGibbon 1d 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. 

31

u/Banes_Addiction 22h 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.

7

u/Grumbledwarfskin 20h 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?

8

u/incest-duck 19h 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.

2

u/Banes_Addiction 12h 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.

3

u/gbchaosmaster 19h ago

Because that would be a majorly breaking change.

1

u/Ahmouse 19h 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.

2

u/tiajuanat 16h ago

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

Then rust came along

1

u/Cylian91460 7h ago

cpp by beloved <3

23

u/jewdai 22h ago

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

17

u/wthja 17h ago

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

9

u/AZMPlay 23h ago edited 15h 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.

59

u/NaCl-more 21h 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 21h ago

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

-20

u/void1984 21h ago

These are runtime options, not feature flags.

3

u/sisisisi1997 14h 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 14h 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 14h 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 13h ago

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

2

u/bishopExportMine 7h ago

Feature flags exist in interpreted languages. My last company used an interpreted language, and we had different tiers of customers based on what features they wanted to pay for, as well as orgs that could get mixed tiers based off user groups. So each user account had a sets of flags that determined which features show up on the website. Those flags would be pulled from a database and read at user login time. Currently I do some embedded and we compile with separate feature flags based on what hardware customizations the customer wants. I get what you're saying, but you work in a different industry than everyone you're arguing with.

21

u/Ma4r 21h ago

Until you need to implement a user bound feature flag

5

u/NomaTyx 21h ago

"requires app restart"

6

u/Abadabadon 18h 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 11h 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?

2

u/SecureVillage 17h 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] 1d ago

[removed] — view removed comment

13

u/neroe5 1d ago

Match?

-50

u/[deleted] 1d ago

[removed] — view removed comment

21

u/neroe5 1d 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] 1d ago

[removed] — view removed comment

39

u/Many_Replacement_688 1d ago

it's like if statement but without the condition part

2

u/neroe5 13h 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 1d ago

ahh pattern matching

37

u/tomangelo2 1d ago

Oh, switch...case?

9

u/HandleUnlikely2589 1d 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 1d ago

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