4 ms·
I quite like the option of being able to program in a more functional style in C++. If you have the cycles to spare, or a sufficiently smart compiler and it all
by naruhodo 3y ago
I quite like the option of being able to program in a more functional style in C++. If you have the cycles to spare, or a sufficiently smart compiler and it allows you to say more with fewer keystrokes and better readability then why not?
I haven't used it yet, but C++ Streams[1] is a header-only library that appears to have great ergonomics and an API that will feel familiar for those who know Java Streams. Since I haven't had the luxury of being able to use C++20 yet, I was unfamiliar with the ranges library. Starting at 1:06:00 you can see some motivating examples for those and they look great to me. Much easier to read than the equivalent STL.
The libraries mentioned in the video TartanLlama/optional[2] and TartanLlama/expected[3] clearly demonstrate the value proposition (brevity and clarity) on their github pages.
[1] http://jscheiny.github.io/Streams/ http://jscheiny.github.io/Streams/
[2] https://github.com/TartanLlama/optional https://github.com/TartanLlama/optional
[3] https://github.com/TartanLlama/expected https://github.com/TartanLlama/expected
- 59nadir 3y agoIn practice a lot of the supposed "more readable" code in FP style isn't actually more readable, it's mostly leaky abstractions you'll most likely want to get rid of if you want to know what code is actually doing or you need to change it.
- qayxc 3y agoI concur. The most funny part to me is always when an elegant and succinct one or two-liner in Haskell turns into a mess once proper error-handling is added. Complexity doesn't magically go away by choosing a different programming paradigm - problems are just shifted into another direction.