r/C_Programming • u/mttd • 6d ago
Fluent Interface in C - Look ma, no this!
https://opensource.googleblog.com/2026/11/fluent-interface-in-c-look-ma-no-this.html
67
Upvotes
r/C_Programming • u/mttd • 6d ago
26
u/looneysquash 6d ago
One of the reasons to prefer C over some other languages is that there is less magic in C.
In most cases there's no hidden arguments, and no hidden function calls, and usually it is clearer which function you are calling.
Everything is a trade off of course. There are pros and cons to this.
IMO this fluent pattern adds too much magic.
26
u/Cats_and_Shit 6d ago
Thanks, I hate it.
13
u/drivingagermanwhip 6d ago
I love whenever web developers are like 'but wouldn't it be more understandable if there were way more arrows and shit in the code?'
9
u/mtlcrusher 6d ago
OOP in C? it works, but at what cost
4
u/Snarwin 6d ago
Maybe the next C standard should add the
|>operator, just so nobody is tempted to actually use this in a real project.7
u/Rararror 6d ago
As kids we used this:
LOL
2
u/lhuemill 5d ago
Before doing this, I'd setup a guard variable through the use of __attribute__((cleanup(func)))). This will call func with a pointer to the guard variable, no matter how the guard variable goes out of scope. Non-portable, but it is available with gcc, and may be available in other C compilers.
2
u/kinchkun 6d ago
Sorry I am new to c. Is this not just returning a self pointer?
1
u/Zectbumo 2d ago
Look ma no this ... Step 1: self :-[