r/programmingcirclejerk • u/lednakashim now 4x faster than C++ • Aug 07 '23
Should we stop writing functions?
https://www.foonathan.net/2023/08/stop-writing-functions/49
u/muntaxitome in open defiance of the Gopher Values Aug 07 '23 edited Aug 07 '23
Functions are an abstraction to make things easier to understand. Many 1X developers only have the mind space to have a couple of dozens of lines in their mind at any time. Writing your code without functions but as a 'single sheet' leads to more efficient code, and it has less nonsense. However just like you don't give Dostoevsky in kindergarten, you don't give functionless code to 1X'ers. When I work in a team with 1X'ers like at Google or Microsoft I always write my code kindergarten style, with functions, comments, unit tests, documentation, but in my open source projects where we only take in 10x'ers, we write it like Dostoevsky.
Dostoevsky didn't provide an ELI5 about what he meant when he wrote "Go, and come no more... Come not at all, never, never!" and neither will I.
11
6
u/0x564A00 Aug 07 '23
True. You can maximize the efficiency of any arbitrary computation by reformulating it as a loop controlled by a single conditional branch.
35
u/disciplite Aug 07 '23
The symbol names of functions becomes ugly: It is now a call operator of some lambda with a compiler synthesized name, and no longer a named function.
I think that invoking lambdas through an implicitly defined operator()() that behaves slightly differently than a class' operator()() was one of C++'s better decisions.
7
u/m50d Zygohistomorphic prepromorphism Aug 07 '23
I can't tell if you're being sarcastic - not about whether that's how lambdas are invoked but about whether that's better or worse than typical C++ design decisions.
20
u/reflexive-polytope Aug 07 '23
Look, buddy, this is C++ we're talking about. It would be inconsistent if it suddenly added a feature that's actually consistent with previously existing features.
10
28
20
u/cheater00 High Value Specialist Aug 07 '23
Should we stop writing functions?
there's too many already. fucking stop it. how many do you need
8
9
17
u/F54280 Considered Harmful Aug 07 '23
/uj. where’s the jerk? that’s pretty low quality content if just posting random C++ blogs are considered jerk now.
/j Start by stopping writing functions first, then stop writing any code. And shave, for the love of Gödel!
5
u/Arcticcu WRITE 'FORTRAN is not dead' Aug 07 '23
jerker didn't type implicit none; the jerk is of course using c++ instead of rust.
12
6
Aug 07 '23
I find the second approach a lot cleaner than an overload set anyway: You have full control over the priority and conversions of the overloads, don’t need to keep complicated resolution rules in mind, and can give better error messages if something does not match.
Mmmmmh delicious compile-time only errors. Inline errors in your editor are something only IDE plebs use, neovim doesn't need it
5
6
u/not_a_novel_account memcpy is a web development framework Aug 07 '23
Where's the jerk?
Everyone knows ADL is from Bjarne's time experimenting with peyote
3
1
Aug 08 '23
Aww closures in C++ that's adorable. Capture everything by value because it's safer and you too can have shitty memory performance just like Javascript! Laughs in webshit the plan is working.
0
Aug 07 '23
[deleted]
8
u/tgbugs lisp does it better Aug 07 '23
I prefer my continuations undelimited.
(let* ((yin ((lambda (foo) (newline) foo) (call/cc (lambda (bar) bar)))) (yang ((lambda (foo) (write-char #\*) foo) (call/cc (lambda (bar) bar))))) (yin yang))Wait, is a function with no name still a function?
\uj Wait, wait, wait. Wait. Am I reading this correctly? c++ lambdas are just as second class as Python's? I mean, in that case I don't blame them.
19
u/[deleted] Aug 07 '23
And so the "C++ Is A Great Language, Just Avoid All These Legacy Features" list gets another entry