-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.qmd
696 lines (429 loc) · 13.1 KB
/
index.qmd
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
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
---
title: "Good practice:<br>How to suck less at<br>(research)<br>software engineering"
format:
revealjs:
theme: custom.scss
slide-number: true
show-slide-number: speaker
chalkboard: true
code-line-numbers: false
preview-links: auto
author: "**Dr David Wilby** (he/him)<br>[RSE Team](https://rse.shef.ac.uk/), The University of Sheffield<br>[**rse.shef.ac.uk**](https://rse.shef.ac.uk) | [**davidwilby.dev**](https://davidwilby.dev)"
date: 02/13/2023
date-format: "ddd Do MMMM YYYY"
footer: "these slides: [davidwilby.dev/ResearchSoftwareMethods](https://davidwilby.dev/ResearchSoftwareMethods) - {{< fa brands github >}} [improve this talk!](https://github.com/davidwilby/ResearchSoftwareMethods)"
from: markdown+emoji
---
# Firstly
. . .
Who am I?
. . .
And what am I doing here?
. . .
## Previously: Scientist
::: columns
::: {.column width="50%"}
[](https://doi.org/10.1016/j.visres.2019.02.008)
[Wilby *et al.* (2018) *Vision Research*](https://doi.org/10.1016/j.visres.2019.02.008)
:::
::: {.column width="50%"}
[{width="80%"}](https://doi.org/10.1242/jeb.152918)
[Wilby *et al.* (2015) *J. R. Soc. Interface*](http://dx.doi.org/10.1098/rsif.2015.0591) - [Wilby & Roberts (2017) *J. Exp. Biol.*](https://doi.org/10.1242/jeb.152918)
:::
:::
## Currently: Research Software Engineer
* Developing research code
* Educating researchers
* Translating research into production software
* Working with government
* Advocating for quality research practice
# Secondly
Who are you?
. . .
<br>
:rotating_light: **Audience participation** :rotating_light:
Go to [menti.com](https://menti.com) and enter the code **6762 9150**
## Outline
<br>
* Why do we need good practice? {{< fa solid magnifying-glass >}}
* Testing {{< fa solid flask >}}
* Environment & Dependency Management {{< fa solid seedling >}}
* Git {{< fa brands git-alt >}}
* GitHub {{< fa brands github-alt >}}
##
[](https://github.com/davidwilby/ResearchSoftwareMethods){fig-align="center"}
<https://github.com/davidwilby/ResearchSoftwareMethods>
<https://bit.ly/RSEmethods>
## Why do we need good practice?
Can't I just write some code?
##
{fig-align="center"}
[Wikipedia: Replication Crisis](https://en.wikipedia.org/wiki/Replication_crisis)
##
{fig-align="center"}
Credit: [Anna Krystalli](https://annakrystalli.me/rrresearchACCE20/slides/01_intro.html)
##
{fig-align="center"}
Credit: [Private Eye](https://www.private-eye.co.uk/pictures/special_reports/justice-lost-in-the-post.pdf)
# Testing
## Levels of testing
. . .
::: {.callout-note appearance="minimal"}
**Smoke Testing**:
*Very* brief initial checks that ensures the basic requirements required to run the project hold. If these fail there is no point proceeding to additional levels of testing until they are fixed.
:::
. . .
::: {.callout-warning appearance="minimal"}
**Unit Testing**:
*Individual units* of a codebase are tested, e.g. functions or methods. The purpose is to validate that each unit of the software performs as designed.
:::
. . .
::: {.callout-important appearance="minimal"}
**Integration Testing**:
Individual units are combined and tested as a *group*. The purpose of this level of testing is to expose faults in the interaction between integrated units.
:::
. . .
::: {.callout-tip appearance="minimal"}
**System Testing**:
A complete, integrated system is tested. The purpose of this test is to evaluate whether the *system as a whole* gives the correct outputs for given inputs.
:::
. . .
::: {.callout-caution appearance="minimal"}
**Acceptance Testing**:
Evaluate the system’s compliance with the project requirements and assess whether it is acceptable for the purpose.
:::
<font size="3">From: [The Turing Way](https://the-turing-way.netlify.app/reproducible-research/testing.html)</font>
## Test-driven development
<br>
. . .
(@) Write a test that fails
<br>
. . .
(@) Write code to make the test pass
<br>
. . .
(@) Refactor
. . .
##
```{mermaid}
%%| fig-height: 7
flowchart TB
classDef writecode fill:#7D7ABC,stroke-width:0px;
classDef testspass fill:#23F0C7,stroke-width:0px;
classDef testsfail fill:#EF767A,stroke-width:0px;
subgraph id1 [<b>Code-driven development</b>]
A((1. write test)) --> B((2. test<br>passes/fails))
B-->|test passes|A
B-->|test fails|C((3. Write only<br>enough code))
C-->|test fails|C
end
subgraph id2 [<b>Refactoring</b>]
C-->|test passes|D((4. Check all tests))
D-->|tests pass|E((5. Refactor))
E-->D
D-->|Some tests fail|F((6. Update failing tests<br>Correct regressions))
F-->D
end
class A,C,E,F writecode;
class B testsfail;
class D testspass;
```
# Environment & Dependency Management
## Python :snake:
<br>
```{mermaid}
%%| fig-width: 9
flowchart TB
subgraph Project 3
A[fab:fa-python Python 3.10]
A-->B[numpy 1.24.0]
A-->C[Django 4.0]
A-->D[TensorFlow 2.11]
end
subgraph Project 2
E[fab:fa-python Python 3.8]
E-->F[numpy 1.1.0]
E-->G[matplotlib 3.1]
end
subgraph Project 1
H[fab:fa-python Python 3.10]
H-->I[numpy 1.1.0]
H-->J[matplotlib 3.1]
end
K[fab:fa-python System Python]
```
. . .
<br>
`pip freeze`
```
numpy==1.1.0
matplotlib>3
```
`requirements.txt`
<br>
::: {.callout-note appearance="simple"}
**Tools**: [`venv`](https://docs.python.org/3/library/venv.html) / [`pipenv`](https://pipenv.pypa.io/en/latest/) / [`conda`](https://docs.conda.io/en/latest/) / [`poetry`](https://python-poetry.org/)
:::
# Control yourself
Why you **need** version control
\+
getting your head round it.
## What makes a version control system?
<br>
* :camera_flash: Snapshot current version
* :label: Name specific versions
* :leftwards_arrow_with_hook: Revert back to a particular version
<br>
Perhaps
* :books: Compare and merge versions
## Benefits of version control
. . .
**Git** (local) :computer:
* Protect against breaking *everything*
* Keep at least one working version of the code
* Snapshot your progress
. . .
**GitHub/GitLab** (remote) :globe_with_meridians:
* Work collaboratively
* Share code easily
* Remote backup
## Without version control
<br>
. . .
:confused: Make changes by making a copy of the entire codebase.
<br>
. . .
:neutral_face: Merging is a manual process.
<br>
. . .
:fearful: Lose track of which version contains what functionality.
<br>
. . .
:sob: Collaborating is just emailing zip files and crying.
<br>
# Version Control == Git
. . .
More often than not
## How does Git work?
```{mermaid}
%%| fig-width: 10
%%{init: { 'logLevel': 'debug', 'theme': 'base', 'gitGraph': {'showCommitLabel': true, 'rotateCommitLabel': true}} }%%
gitGraph
commit id: "commit 1"
commit id: "commit 2"
commit id: "commit 3"
commit id: "commit 4"
commit id: "commit 5"
commit id: "commit 6"
commit id: "commit 7"
```
::: {.callout-note appearance="simple"}
The most important concept in git is the `commit` - the name given to a unit of changes, and also to the process of making a commit.
:::
<br>
. . .
### Commits contain *changes*
Not actually *snapshots* of a file.
But can recreate a state from a sequence of changes.
## Demo
<https://onlywei.github.io/explain-git-with-d3>
or
<https://bit.ly/git-sandbox>
or
{{< qrcode https://onlywei.github.io/explain-git-with-d3 width=350 height=350 >}}
## Making a commit {{< fa solid code-commit >}}
```{mermaid}
%%| fig-height: 6
flowchart TB
A(fa:fa-pen fa:fa-file-code Edit file) --> B
B(fa:fa-download Save) --> C
C(fa:fa-plus <strong>Stage</strong> changes) --> D(fa:fa-check Commit)
```
## The commit hash
<br>
Git generates a hash string, uniquely identifying each commit.
::: {.callout-note appearance="simple"}
Git uses a "[Merkle tree](https://en.wikipedia.org/wiki/Merkle_tree)" under the hood. (Don't ask me how it works, I have no idea :shrug:)
:::
. . .
<br>
Hashes look like:
`d3dd03f493707256c8528bc83ad280a460f05a56`
. . .
<br>
But are most often seen as the first 7 characters, as this is easier to read/type and is normally enough to identify the commit.
`d3dd03f`
## The commit message
Each commit has a *message* associated with it.
<br>
**Summary/Title**: <50-72 characters
Displayed most frequently.
<br>
**Detailed description**: no character limit.
*Can* be used to capture more detail. Not used that often.
. . .
<br>
### This commit will...
::: columns
::: {.column width="30%"}
* :x: some stuff
* :x: code
* :x: updates
:::
::: {.column width="70%"}
* :heavy_check_mark: add new module "renderers"
* :heavy_check_mark: update README with new install instructions
* :heavy_check_mark: fix bug #17 with package update
:::
:::
## Branches {{< fa solid code-branch >}}
Used to work on new features/changes/additions to the code.
```{mermaid}
%%| fig-width: 10
%%{init: { 'logLevel': 'debug', 'theme': 'base'} }%%
gitGraph
commit id:"8bc2520"
commit id:"2a70480"
branch experiment
commit id:"089e06b"
commit id:"bec84f4"
commit id:"2420edd"
```
```bash
git branch experiment
git checkout experiment
git commit
git commit
git commit
```
::: {.callout-tip appearance="simple"}
**Checkout**: switching to a different branch.
:::
## Merging {{< fa solid code-merge >}}
<br>
Combine changes from two branches.
<br>
```{mermaid}
%%| fig-width: 10
%%{init: { 'logLevel': 'debug', 'theme': 'base'} }%%
gitGraph
commit id:"8bc2520"
commit id:"2a70480"
branch experiment
commit id:"089e06b"
commit id:"bec84f4"
commit id:"2420edd"
checkout main
merge experiment
commit id:"60489ec"
```
```bash
git checkout main
git merge experiment
git commit
```
## Repositories (Repos)
<br>
::: {.callout-tip appearance="simple"}
<font size="6">Once a directory/folder is *initialised* with `git` it becomes a *repository*.</font>
<br><br>
:::
::: columns
::: {.column width="40%"}
**directory**
```
.
├── src/
├── LICENSE.md
└── README.md
```
:::
::: {.column width="20%"}
`git init`
------->
:::
::: {.column width="40%"}
**repository**
```
.
├── .git/
├── src/
├── LICENSE.md
└── README.md
```
:::
:::
## How to interact with Git
<br>
### command line `git` {{< fa brands git-alt >}}
via unix shell (or gitbash/WSL on Windows)
```bash
$ git add README.md
$ git commit -m 'initial commit'
$ git status
```
<br>
. . .
::: columns
::: {.column width="50%"}
### IDEs
* [VSCode](https://code.visualstudio.com/)
* [RStudio](https://posit.co/download/rstudio-desktop/)
* [PyCharm](https://www.jetbrains.com/pycharm/)
* [Emacs](https://www.gnu.org/software/emacs/)
:::
::: {.column width="50%"}
### Other GUIs
* [GitKraken Client {{< fa brands gitkraken >}}](https://www.gitkraken.com/)
* [GitHub Desktop {{< fa brands github >}}](https://desktop.github.com/)
* [etc. etc.](https://git-scm.com/downloads/guis/)
:::
:::
## Git learning resources
::: columns
::: {.column width="60%"}
* [Pro Git Book](http://git-scm.com/book/en/v2)
* [Software carpentry lesson](http://swcarpentry.github.io/git-novice/)
* *\"oh sh\*\* git\"* - [zine](https://wizardzines.com/zines/oh-shit-git/), or [blog](https://ohshitgit.com/)
* [The Turing Way](https://the-turing-way.netlify.app/reproducible-research/vcs.html)
* [stack overflow](https://stackoverflow.com/) *etc.* - *use carefully* :warning:
* blogs on [dev](https://dev.to/) or [atlassian](https://www.atlassian.com/git/tutorials) *etc.*
<br>
::: {.callout-warning appearance="simple"}
<font size="6">
**Remember**
Learning Git is a process.
Everyone makes mistakes.
</font>
:::
:::
::: {.column width="40%"}
[](https://ohshitgit.com/)
:::
:::
## Git {{< fa brands git-alt >}} vs GitHub {{< fa brands github >}} or GitLab {{< fa brands gitlab >}}
<br>
**Git**
* Local client for source code management
* Interacting with remote git servers
**GitHub/GitLab**
* Code hosting
* Collaboration
* OSS contribution
* Project management
* Automated workflows/continuous delivery
## Repositories

## Issues

## Projects/Kanban Board

## Continuous integration/Automated testing
{fig-align="center"}
## Great resources
[](https://www.britishecologicalsociety.org/wp-content/uploads/2019/06/BES-Guide-Reproducible-Code-2019.pdf)
[{width="40%"}](https://the-turing-way.netlify.app/)
* [BES Guide to Reproducible Research Code](https://www.britishecologicalsociety.org/wp-content/uploads/2019/06/BES-Guide-Reproducible-Code-2019.pdf)
* [The Turing Way](https://the-turing-way.netlify.app/)
* [Software Sustainability Institute](https://software.ac.uk/)
* [This talk!](https://github.com/davidwilby/ResearchSoftwareMethods)