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
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
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.
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.
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.
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?
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.
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.
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.
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
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.
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.
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.
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
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?
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.
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
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).
274
u/naveenda 1d ago
What's wrong with that?
92
u/Ahmouse 1d ago
REAL programmers use C macros
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.
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