@@ -6,31 +6,31 @@ class: typo, typo-selection
66count: false
77class: nord-dark, middle, center
88
9- # Lecture 2b: Programming in the Age of AI 🤖
9+ # 📚 Lecture 2b: Programming in the Age of AI 🤖
1010
11- @luk036
11+ @luk036
1212
13- 2024-09-11
13+ 📅 2024-09-11
1414
1515---
1616
1717![ image] ( figs/the-earth-is-flat.png )
1818
1919---
2020
21- ## Coding Tips 💡
21+ ## 💻 Coding Tips 💡
2222
2323.pull-left[
2424
25- - Test, test, test!!!
26- - Write cleaner code
27- - Refactor repeat codes
28- - Object oriented programming
29- - Generic programming
30- - Design Pattern
31- - Coroutine is your friend
32- - Learn from good codes , not bad ones.
33- - The last rescue : Google search.
25+ - 🧪 Test, test, test!!!
26+ - ✨ Write cleaner code
27+ - 🔄 Refactor repeat codes
28+ - 🧩 Object- oriented programming
29+ - 🧠 Generic programming
30+ - 🏗️ Design Patterns
31+ - 🔄 Coroutines are your friends
32+ - 📚 Learn from good code , not bad ones
33+ - 🔍 The last resort : Google search
3434
3535] .pull-right[
3636
@@ -44,27 +44,31 @@ class: nord-dark, middle, center
4444
4545---
4646
47- ## Code generation
47+ ## 🤖 AI Code Generation Tools
4848
49- - AWS CodeWhisperer
50- - generate testing code
51- - Cody AI
49+ - ** AWS CodeWhisperer**
50+ - Automated test generation
51+ - ** Cody AI** (Sourcegraph)
5252
5353---
5454
55- ## Documentation generation
55+ ## 📝 Documentation Generation
5656
57- Mintlify (VSCode's extension)
57+ ** Mintlify** (VSCode extension)
5858
59- - Naming
60- - a, i, p, n ❌
61- - A x = b
62- - x: unknown, x_axis
63- - x, y, z
59+ ### Naming Best Practices:
60+ - Avoid single-letter names ❌
61+ ` a, i, p, n `
62+ - Example equation:
63+ ` A x = b `
64+ - Good names:
65+ ` x: unknown, x_axis `
66+ - Coordinate variables:
67+ ` x, y, z `
6468
6569---
6670
67- ## Use better variable names
71+ ## 📛 Better Naming Conventions
6872
6973- p: point, polygon, polynomial, prev
7074- t: time, target, temp
@@ -83,26 +87,26 @@ Mintlify (VSCode's extension)
8387
8488---
8589
86- ## 🚀 Performance Tips 💡
90+ ## 🚀 Performance Optimization Tips
8791
88- - Avoid string comparison
89- - Use sentinel
90- - Use cheaper measure, avoid ` sqrt() ` , ` sin() ` , ` cos() `
91- - Lazy evaluation
92- - Table lookup
93- - Avoid sequence search :
94- - Backward pointers
95- - Hash Table/Dictionary/Map
92+ - 🚫 Avoid string comparisons
93+ - 🛡️ Use sentinel values
94+ - ⚡ Use cheaper computations ( avoid ` sqrt() ` , ` sin() ` , ` cos() ` )
95+ - 🦥 Lazy evaluation
96+ - 📚 Table lookups
97+ - 🔍 Avoid sequence searches :
98+ - 🔙 Backward pointers
99+ - Hash Tables/Dictionaries/Maps
96100
97101---
98102
99- ## Avoid string comparison
103+ ## 🚫 Avoid String Comparisons
100104
101105.pull-left[
102106
103- Bad 👎:
107+ ### Bad Practice 👎
104108
105- ``` {. python}
109+ ``` python
106110if pin == " input" :
107111 # ...
108112elif pin == " output" :
@@ -119,39 +123,38 @@ else:
119123
120124.pull-right[
121125
122- Better ⚡:
126+ ### Better Practice ⚡
123127
124- ``` {.python}
125- pin_type = dict({"input":0},
126- {"output":1}, {"in_out":2},
127- {"dont_care":3})
128- ...
128+ ``` python
129+ pin_type = {
130+ " input" : 0 ,
131+ " output" : 1 ,
132+ " in_out" : 2 ,
133+ " dont_care" : 3
134+ }
129135id = pin_type.get(pin, - 1 )
136+
130137if id == 0 :
131138 # ...
132139elif id == 1 :
133140 # ...
134- elif id == 2:
135- # ...
136- elif id == 3:
137- # ...
138141else :
139- # ...
142+ # ... (rest of conditions)
140143```
141144
142145]
143146
144147---
145148
146- ## Use Sentinel
149+ ## 🛡️ Sentinel Pattern
147150
148151.pull-left[
149152
150- Bad 👎:
153+ ### Suboptimal 👎
151154
152155.font-sm.mb-xs[
153156
154- ``` {. python}
157+ ``` python
155158max = 0
156159bckt = [Dllist() for _ in range (high)]
157160# ...
@@ -166,37 +169,36 @@ def popleft():
166169
167170] .pull-right[
168171
169- Better ⚡:
172+ ### Optimized ⚡
170173
171174.font-sm.mb-xs[
172175
173- ``` {. python}
176+ ``` python
174177max = 0
175178sentinel = Dllink()
176179bckt = [Dllist() for _ in range (high+ 1 )]
177- bckt[0].append(sentinel) # sentinel
178- # ...
180+ bckt[0 ].append(sentinel) # Sentinel
181+
179182def popleft ():
180183 res = bckt[max ].popleft()
181184 while bckt[max ].empty():
182185 max -= 1
183186 return res
184- # Saved a boundary check `max >= 0`
187+ # Eliminated boundary check
185188```
186-
187189]
188190
189191]
190192
191193---
192194
193- ## Use cheaper measure
195+ ## ⚡ Cheaper Computations
194196
195197.pull-left[
196198
197- Bad 👎:
199+ ### Inefficient 👎
198200
199- ``` {. python}
201+ ``` python
200202mind = 10000
201203maxd = 0
202204for u, v in G.edges():
@@ -207,16 +209,18 @@ for u, v in G.edges():
207209return maxd - mind
208210```
209211
210- ] .pull-right [
212+ ]
211213
212- Better ⚡:
214+ .pull-right [
213215
214- ``` {.python}
216+ ### Optimized ⚡
217+
218+ ``` python
215219minq = 10000
216220maxq = 0
217221for u, v in G.edges():
218222 t = vec[u] - vec[v]
219- q = t.dot(t)
223+ q = t.dot(t) # Cheaper
220224 if minq > q: minq = q
221225 if maxq < q: maxq = q
222226return sqrt(maxq) - sqrt(minq)
@@ -226,51 +230,49 @@ return sqrt(maxq) - sqrt(minq)
226230
227231---
228232
229- ## Another Example
233+ ## ⚡ Another Optimization Example
230234
231235.pull-left[
232236
233- Bad 👎:
237+ ### Inefficient 👎
234238
235- ``` {. python}
239+ ``` python
236240mind = 10000
237241maxd = 0
238242for u, v in G.edges():
239243 t = 1 - vec[u].dot(vec[v])
240244 d = arcsin(sqrt(t))
241245 if mind > d: mind = d
242246 if maxd < d: maxd = d
243-
244247return maxd - mind
245248```
246249
247- ] .pull-right [
250+ ]
248251
249- Better ⚡:
252+ .pull-right [
250253
251- ``` {.python}
254+ ### Optimized ⚡
255+
256+ ``` python
252257minq = 10000
253258maxq = 0
254259for u, v in G.edges():
255260 q = 1 - vec[u].dot(vec[v])
256261 if minq > q: minq = q
257262 if maxq < q: maxq = q
258-
259263return arcsin(sqrt(maxq)) \
260- - arcsin(sqrt(minq))
264+ - arcsin(sqrt(minq))
261265```
262266
263267]
264268
265269---
266270
267- ## Optimization Tips 💡
268-
269- - Convex optimization
270-
271- - Network optimization
271+ ## 🧮 Advanced Optimization Techniques
272272
273- - Primal-dual paradigm
273+ - 🌰 Convex optimization
274+ - 🖧 Network optimization
275+ - ☯ Primal-dual paradigm
274276
275277---
276278
0 commit comments