Skip to content

Commit 1643fd1

Browse files
committed
add note
1 parent 9555d9e commit 1643fd1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

_code/CppCon/2023/thinking_functionally _in_c++.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,46 @@ Creating an object wrapper using a lambda.
7474
- Filter: take a list of item of one and eliminate to create a list of the same number or fewer items of the same type. `std::copy_if`
7575
- Map: Take a list of items of one type and create a list of the same size with all items converted to a new type. `std::transform`
7676
- Reduce: Take a list of items and create a single value.`std::accumulate` `std::reduce`
77+
78+
std::ranges
79+
80+
## Lazy Evaluation
81+
82+
Delay actions or calculations until they are needed
83+
84+
Allocation
85+
86+
Fetch data lazily
87+
88+
Efficient Iteration
89+
90+
## Your Mileage may vary
91+
92+
`std::remove_if`
93+
94+
Calculations need unchanging data:
95+
96+
- If the contained type is cheap to copy, copy it
97+
- Guarantee that the data won't change, which requires some type of synchronization
98+
- Create data structure that can create copies lazily or log changes: bitmapped vector trie
99+
100+
## Thinking Functionally
101+
102+
- Leverage that C++ is a multiparadigm language.
103+
- Separate code into Actions, Calculations and Data
104+
- Isolate Actions
105+
- Reuse Calculations
106+
- Treat functions as Data
107+
- Functions can work together
108+
- Be lazy
109+
- Don't be too smart
110+
111+
> Debugging is twice as hard as writing the code in the first place. Therefore if you write code as cleverly as possible, you are, by definition, not smart enough to debug it.
112+
113+
ref: Grokking Simplicity by Eric Normand(book)
114+
115+
ref: Functional Programming in C++(book)
116+
117+
ref: Ranges for the Standard Library by Eric Niebler
118+
119+
ref: C++ Weekly - EP 126 - Lambdas with Destructors

0 commit comments

Comments
 (0)