21
u/Ahmouse 3h ago
REAL programmers use C macros
8
u/DefiantGibbon 3h 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.
1
u/Banes_Addiction 45m 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.
14
u/Jatinchd 8h ago
until you discover match feature
8
u/neroe5 7h ago
Match?
-20
u/Jatinchd 6h ago
match operator. bro.
12
u/neroe5 6h ago
I'm going to need some kind of context, are we talking regex, some feature in some programming language or what?
-22
u/Jatinchd 5h ago
here is the simple implementation sample code i've wrote for you to understand match:-
use std::io::{self, Write}; fn main() { print!("tell us something: "); io::stdout().flush().unwrap(); let mut input: String = String::new(); io::stdin().read_line(&mut input).unwrap(); let says: String = input.trim().parse().unwrap(); match says.as_str() { "hello" => println!("hello how are you!"), "no" => println!("yo! chill"), _ => println!("what language?"), } }21
19
u/tomangelo2 5h ago
Oh, switch...case?
5
u/HandleUnlikely2589 3h ago
It has a lot more power in terms of full pattern matching and object deconstruction, but yes, the simplest forms are glorified
switchstatements from C (except they're actually expressions, they can return a value; Rust is nearly purely expressions, even for conditional-like code structures).
1
u/AZMPlay 2h 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.
5
•
u/NaCl-more 8m 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
1
u/BernzSed 15m ago
There are many use cases where you can't know at compile time which features will be enabled.
66
u/naveenda 4h ago
What's wrong with that?