-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
644 lines (593 loc) · 21.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<title>Pairing with the Future</title>
<link rel="stylesheet" href="dist/reset.css" />
<link rel="stylesheet" href="dist/reveal.css" />
<link rel="stylesheet" href="dist/theme/league.css" />
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/tomorrow-night-eighties.css" />
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans|Open+Sans+Condensed:300&display=swap" rel="stylesheet">
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h4 class="subtitle left">Maximizing the collaborative potential of your software</h4>
<hr />
<h1 class="title">Pairing with the Future</h1>
<hr />
<div class="contact right">Kelly Fox</div>
</section>
<section data-background-image="./assets/images/color-coded-racetrack.gif">
<h1 class="full-size">Code is communication</h1>
<h2 class="subtitle">Across time and space</h2>
<aside class="notes">
If your project or team is big enough, or your software is useful enough, your code will eventually be seen by other people. More importantly, it will probably need to be understood and changed by some of those other people. That means someone else, or maybe even you 6 months in the future, will need to read and understand your code.
</aside>
</section>
<section>
<h2>How do developers spend their time?</h2>
<image src="./assets/images/time-spent.png" class="stretch" />
<div>
(Based on how it feels.)
</div>
<aside class="notes">
From the Coding Horror blog by Jeff Attwood (Stack Overflow co-founder)
https://blog.codinghorror.com/when-understanding-means-rewriting/
</aside>
</section>
<section>
<h2 class="full-size">
Ease of change directly correlates
<br />
with ease of understanding
</h2>
<p class="attribution">
Rebecca Parsons
<br />
CTO, ThoughtWorks
</p>
<aside class="notes">
Comprehensible code facilitates change. If there are no surprises, it means you spend less time untangling someone else’s logic.
</aside>
</section>
<section>
<h2 class="full-size">
Code is written for humans first,
<br />
machines second
</h2>
<aside class="notes">
The MIT textbook Structure and Interpretation of Computer Programs said:
Programs must be written for people to read, and only incidentally for machines to execute
</aside>
</section>
<section>
<h2 class="full-size">
Projects are easy to start,
<br />
But harder to finish
</h2>
<aside class="notes">
Clean, well-structured code matters. As a project grows, the complexity increases. The more time you spend trying to understand how code is working is less time spent adding features or fixing bugs.
</aside>
</section>
<section>
<h1 class="full-size">Cache your context</h1>
<aside class="notes">
You need to look for ways to preserve your thought context.
</aside>
</section>
<section>
<h1>Suggestions, not rules</h1>
<ul>
<li>
What follows are starting points for discussion, and may not be appropriate for every situation.
</li>
<li>
Some suggestions may be easier to implement than others.
</li>
<li>
Use these guidelines to help you approach coding with a future-looking perspective. Imagine someone new to your codebase trying to make sense of the code you’re writing.
</li>
</ul>
</section>
<section data-background-image="./assets/images/cassini-orbits.gif">
<h1 class="full-size">Project, file, and function structure</h1>
</section>
<section>
<h2>Approaches to Project Organization</h2>
<ul>
<li>
Follow conventions for the language or framework
</li>
<li>
Arrange folders intuitively, from abstract to specific
</li>
<li>
Organize code by features or functionality
</li>
<li>
Keep related files and code “close together”
</li>
</ul>
</section>
<section>
<h2>General file layout</h2>
<ol>
<li>
Imports — built-in, external, internal, each section alphabetized
</li>
<li>
Variables common to the entire file
</li>
<li>
Function and class definitions, before use
</li>
<li>
Main program logic
</li>
<li>
Exports
</li>
</ol>
</section>
<section>
<h2>Structure of a function or method</h2>
<ol>
<li>
Variable declarations and assignments
</li>
<li>
Early return (if necessary)
</li>
<li>
Core function logic
</li>
<li>
Return statement/value
</li>
</ol>
<p>
Use blank lines to separate sections or logical chunks of code.
</p>
</section>
<section data-background-image="./assets/images/cat-in-a-box.gif">
<h1 class="full-size">Sizing</h1>
</section>
<section>
<h2>Sizing Suggestions</h2>
<table>
<thead>
<tr>
<th align="center">Item</th>
<th align="center">Limit</th>
</tr>
</thead>
<tbody>
<tr>
<td>Line Length</td>
<td>80-120 characters max</td>
</tr>
<tr>
<td>Function Arity</td>
<td>3 arguments max</td>
</tr>
<tr>
<td>Function Length</td>
<td>4-10 logical lines max</td>
</tr>
<tr>
<td>Class</td>
<td>2 pages max</td>
</tr>
<tr>
<td>File</td>
<td>3 pages max</td>
</tr>
<tr>
<td>Files in a folder</td>
<td>Minimal scrolling</td>
</tr>
</tbody>
</table>
</section>
<section>
<h1>Good functions and methods</h1>
<p>
<pre><code class="hljs" data-trim data-no-escape>
int getRandomNumber()
{
return 4; // chosen by 6-sided die roll
// guaranteed to be random
}
</code></pre>
</p>
</section>
<section>
<h2>Tips for Writing Good Functions and Methods</h2>
<ul>
<li>
Functions should focus on accomplishing one task.
</li>
<li>
Return early from functions when possible to avoid unnecessary processing.
</li>
<li>
Function layout should be: Variable declarations and assignments, then early returns, then core function logic, then the final return statement. Single blank lines should separate sections for clarity.
</li>
</ul>
</section>
<section>
<h2>More Tips for Writing Good Functions and Methods</h2>
<ul>
<li>
Code representing the primary behavior of a function shouldn't be buried inside an if/then statement.
</li>
<li>
Write short functions. This makes code easier to read, easier to reuse, easier to review, easier to adapt for other purposes, and easier to test.
</li>
<li>
When possible, avoid: sharing state with other functions, changing state, and side effects.
</li>
</ul>
</section>
<section>
<h2>Arity: The number of function arguments</h2>
<ul>
<li>
Try to keep the number of function arguments to three or less. It can sometimes be difficult to remember argument order with as few as two arguments!
</li>
<li>
If more arguments are needed, pass an “options” object as the last function argument.
An options object as the last function argument allows you to change the number of arguments without refactoring all references to that function.
</li>
</ul>
</section>
<section data-background-color="#34A5DA">
<h2>
There are only two hard problems in Computer Science: cache invalidation, naming things, and off-by-one errors.
</h2>
</section>
<section>
<h2>Naming</h2>
<ul>
<li>
Pick obvious names that are representative of the value or behavior.
</li>
<li>
Choose names that help your code read like a narrative.
</li>
<li>
Use long names if they’re appropriate. Tab-completion makes typing them easy, and finding all uses of a unique name is a simple task.
</li>
<li>
Define all “magic” numbers or strings as variables to explicitly communicate what they represent. For example, NUMBER_OF_SECONDS_IN_A_DAY is easier to understand than 86400.
</li>
<li>
Check for namespace collisions. Will the name you choose cause confusion with another existing name?
</li>
</ul>
</section>
<section>
<image src="./assets/images/code-in-comments.jpg" class="stretch" />
<h1>Code Comments</h1>
</section>
<section>
<h2>When To Use Comments</h2>
<ul>
<li>
API documentation, often for use with tools like Javadoc, JSDoc, Swagger, etc.
</li>
<li>
To specify or ignore linter rules, for tools like ESLint (JavaScript), flake8 (Python), etc.
</li>
<li>
Describing unusual code that you were forced to include for non-obvious reasons, e.g. to circumvent a known bug or deal with a poorly-written API. (Include a link to the issue, if possible.)
</li>
<li>
Illustrating program flow or data handling in code samples
</li>
<li>
Pseudocode, but only as temporary placeholders for actual code
</li>
</ul>
</section>
<section>
<h2>When Not To Use Comments</h2>
<ul>
<li>
Describing normal or conventional functionality. The code should describe itself.
</li>
<li>
Describing complex functionality. Refactor your code instead.
</li>
<li>
Preventing code from being executed, except for temporary debugging.
</li>
<li>
Keeping code around “just in case”. Delete it and rely on version control.
</li>
<li>
Managing “todos” or describing changes that need to happen later. Use an issue-tracking system.
</li>
</ul>
</section>
<section>
<image src="./assets/images/code-refactoring.gif" class="stretch" />
</section>
<section>
<h2>Reasons to Refactor Code</h2>
<ul>
<li>
DRY-ness
</li>
<li>
Simplicity
</li>
<li>
Clarity
</li>
<li>
Testability
</li>
</ul>
</section>
<section>
<h2>Refactoring for DRY-ness</h2>
<h3>
DRY = Don't Repeat Yourself
</h3>
<ul>
<li>
Extract repeated patterns from your code to helper functions.
</li>
<li>
Define common constants in a shared file.
</li>
<li>
Avoid over-generalizing functions, classes, or objects. Consider using function composition, inheriting from superclasses, or partitioning objects.
</li>
</ul>
</section>
<section>
<h2>Refactoring for Simplicity</h2>
<ul>
<li>
Avoid nesting. Try extracting nested code to external functions.
</li>
<li>
Avoid clever code. Cleverness often conceals functionality — save it for high-performance or coding challenges.
</li>
</ul>
</section>
<section>
<h2>Refactoring for Clarity</h2>
<ul>
<li>
Limit functions or methods to one purpose.
</li>
<li>
Move transformational code into separate functions with meaningful names.
</li>
<li>
Ensure magic numbers and strings are replaced by meaningful constants.
</li>
<li>
Don’t be afraid to create one-line functions!
</li>
<li>
Write more verbose code if it facilitates understanding and doesn’t adversely impact performance.
</li>
</ul>
</section>
<section>
<h2>Refactoring for Testability</h2>
<ul>
<li>
Only export what needs to be tested.
</li>
<li>
Don’t (deeply) test third-party code.
</li>
<li>
Get configuration out of your code. Use a file, database, environment variables, etc.
</li>
<li>
Use dependency injection to simplify testing of external services, varying environments, or complex objects.
</li>
</ul>
</section>
<section data-background-image="./assets/images/it-does-not-compile.png">
<h1 class="full-size">Safety Nets</h1>
</section>
<section>
<h2>Testing</h2>
<ul>
<li>
Good tests can explain how your code should work without looking at the code itself.
</li>
<li>
Only test what you need to test.
</li>
<li>
Bad tests can do more harm than good.
</li>
</ul>
</section>
<section>
<h2>Automated Testing</h2>
<ul>
<li>
Set up your development environment to “watch” files and automatically execute tests when you save changes.
</li>
<li>
Use a continuous integration testing service that executes your test suite after code is committed to source control.
</li>
</ul>
</section>
<section>
<h2>Using Source Control</h2>
<ul>
<li>
Work in a feature branch.
</li>
<li>
Commit early and often.
</li>
<li>
Write meaningful commit messages.
</li>
<li>
"Squash" your changes prior to merging.
</li>
<li>
Learn to use your tools <em>before</em> an emergency arises.
</li>
</ul>
</section>
<section>
<h2>Using Third-Party APIs</h2>
<p>
Consider wrapping your APIs with generalized wrappers if you think a service you’re using may eventually need to be replaced. This lets you swap out the underlying service with minimal disruption to the rest of your code.
</p>
</section>
<section>
<h2>Documentation</h2>
<ul>
<li>
Provide instructions for installing, further developing, testing, contributing to, and using your project.
</li>
<li>
If your code and tests are written with clarity, you may not need extensive documentation.
</li>
<li>
Leverage tools to document the code for you.
</li>
</ul>
</section>
<section>
<image src="./assets/images/derpcat.gif" class="stretch" />
<h1>Continuous Improvement</h1>
</section>
<section>
<h2>Tools for Success</h2>
<ul>
<li>
Use linters to identify problems as you type — eslint, pylint, etc.
</li>
<li>
Use “beautifiers” to format code according to agreed-upon conventions — JavaScript Standard Style, Black for Python, gofmt, etc.
</li>
<li>
Use EditorConfig and pre-commit hooks to enforce consistency.
</li>
<li>
Enable syntax highlighting.
</li>
<li>
Leverage type-checking if that’s an option.
</li>
<li>
Consider Dockerizing your entire development environment. (See also: VS Code's devcontainer.json.)
</li>
<li>
Use an IDE that facilitates all of the above with as little effort as possible.
</li>
</ul>
</section>
<section>
<h2>Choosing new tools</h2>
<ul>
<li>
Keep an open mind. Just because a tool or framework is popular does not necessarily mean it’s the best solution for your problem.
</li>
<li>
Find out what other people are using or creating, and why. Read books, blogs, and newsletters. Listen to podcasts. Watch videos. Attend meetups and conferences.
</li>
<li>
Don't "reinvent the wheel" unless you have a good reason to do so.
</li>
</ul>
</section>
<section>
<h2>More Resources</h2>
<ul>
<li>
<a href="https://bookshop.org/books/clean-code-a-handbook-of-agile-software-craftsmanship/9780132350884" target="_blank">Clean Code</a> by Robert C. Martin
</li>
<li>
<a href="https://bookshop.org/books/code-complete/9780735619678" target="_blank">Code Complete</a> by Steve McConnell
</li>
<li>
<a href="https://pragprog.com/titles/tpp20/the-pragmatic-programmer-20th-anniversary-edition/" target="_blank">The Pragmatic Programmer</a> by David Thomas, Andrew Hunt
</li>
<li>
<a href="https://www.hanselminutes.com/" target="_blank">The Hanselminutes Podcast</a> by Scott Hanselman
</li>
<li>
Any books, interviews, or talks with <a href="https://www.sandimetz.com/" target="_blank">Sandi Metz</a> or <a href="https://www.kytrinyx.com/" target="_blank">Katrina Owen</a>
</li>
<li>
Newsletters from <a href="https://cooperpress.com/publications/" target="_blank">Cooper Press</a>
</li>
</ul>
</section>
<section>
<h2 class="full-size">
Writing maintainable software
<br />
is an art that improves with practice
</h2>
<aside class="notes">
Like any technical or artistic endeavor, it requires time, practice, and reflection. Keep striving to improve yourself and the code you write.
</aside>
</section>
<section>
<h1>Questions</h1>
<image src="./assets/images/question.gif" class="plain stretch" />
</section>
<section>
<h1>Thanks!</h1>
<p class="contact">
Kelly Fox
</p>
<ul>
<li>
<a href="https://github.com/kfox">github.com/kfox</a>
</li>
<li>
<a href="https://twitter.com/kellyfox">@kellyfox</a>
</li>
</ul>
</section>
</div>
</div>
<script src="dist/reveal.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/highlight/highlight.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
autoPlayMedia: true,
plugins: [ RevealNotes, RevealHighlight ],
history: true,
mouseWheel: true,
progress: true,
showSlideNumber: 'speaker',
transition: 'convex',
width: 1280,
height: 720
})
</script>
</body>
</html>