-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprogramming_and_version_control_class.Rmd
97 lines (79 loc) · 3.72 KB
/
programming_and_version_control_class.Rmd
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
---
title: 'Programming and Version Control'
author: "[Brian High](https://github.com/brianhigh)"
date: "![CC BY-SA 4.0](cc_by-sa_4.png)"
output:
ioslides_presentation:
fig_caption: yes
fig_retina: 1
fig_width: 6
fig_height: 4
keep_md: yes
smaller: yes
logo: logo_128.png
---
## Common Programming Issues
* Poorly formatted, not following "best practices" style guides
- Long sections of poorly commented code with obscure vairable names
- Not enough blank lines separating code sections
- No spaces between list items, function parameters
* Too much copy and paste
- Difficult to read, debug and maintain
* Fail to check for problems
- Packages, utilities, files or folders missing
- Invalid data entry
* Inefficient
- Redoing work already done (installing, downloading, etc.)
- Processing more data than needed, usinfg more RAM
- Looping more times than needed
- Not taking advantage of language features
## Common Programming Solutions
* Code reuse, modular design (functions, loops)
```
function task:
do steps: [1, 2, 3, 4, 5]
mylist = [A, B, C, D]
foreach item in mylist: do task to item
```
* Consider dependencies, anticipate problems
* Validate input (with e.g., regular expressions)
* Use resources wisely (RAM, CPU, storage)
* Use language "idiomatically" - as designed to be used
* Use clear comments, descriptive and consistent variable naming scheme
## Programming Examples
* Web programming: [Panopto Link Maker](https://github.com/brianhigh/panopto-linkmaker) (HTML/JavaScript/Regex)
- Input validation with Regular Expressions
- Completely client-side programming: completely portable
* API Programming: [Amazon Search](https://github.com/brianhigh/amzn-srch) (Python/R)
- Embedding non-R system commands in Rmd
- Small "remove duplicates" Python script to use from shell with pipe
* Functions: [Reddit Wordclouds](https://github.com/brianhigh/reddit-wordclouds) (Python/R)
- Loops versus *apply functions
- Example of Rmd ioslides presentation with license info and icon
* Regular expressions filtering, streaming: [Filter-fastq](https://github.com/brianhigh/filter-fastq) (Python/Perl/Regex)
* Validation: [Get-logo-png](https://github.com/brianhigh/research-computing/blob/master/get_logo_png.sh) (Bash/Regex)
- Checking requirements, command-line arguments
- Input validation with Regular Expressions
- Automation using CLI tools, pipes
## Version Control
Different systems: an _evolution_ of version control systems (VCS)
- RCS: Revision Conrtrol System (1982, single user)
- CVS: Concurrent Versions System (1990, multi user, central server)
- SVN: Subversion (2000, updated, improved, CVS-like, central server)
- various distributed VCS: Git (2005), Mercurial (2005), Bazarr (2005)
Demo basic "git" workflow:
* fork, clone, pull, edit, commit, push, pull-request
- From RStudio GUI
- From command line
- From other GUI or web browser (GitHub site)
## Exercise: Practice Git
Try to fork, clone, commit, push, and send a "pull request" with these projects.
Pick a project (from course modules page, GitHub):
- [Panopto-linkmaker](https://github.com/brianhigh/panopto-linkmaker) (HTML, JavaScript, CSS)
- [Airquality-example](https://github.com/brianhigh/airquality-example) (R)
- [WA Water Quality](https://github.com/brianhigh/wa-water-quality) (R)
- [Medicare-ipps](https://github.com/brianhigh/medicare-ipps) (R)
- [Amazon-search](https://github.com/brianhigh/amzn-srch) (R, Python)
- [Reddit-wordclouds](https://github.com/brianhigh/reddit-wordclouds) (R, Python)
- [Filter-fastq](https://github.com/brianhigh/filter-fastq) (Python, Perl)
- [Get-logo-png](https://github.com/brianhigh/research-computing/blob/master/get_logo_png.sh) (Bash)