-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslides.Rmd
More file actions
179 lines (112 loc) · 4.79 KB
/
Copy pathslides.Rmd
File metadata and controls
179 lines (112 loc) · 4.79 KB
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
---
title: "Tips for generating clean and readable code"
author: "Brad Duthie"
date: "14/20/2020"
output:
beamer_presentation: default
ioslides_presentation: default
slidy_presentation: default
---
# Why is writing readable code important?
*"If the code runs successfully, who cares how it looks?"* \pause
\vspace{2mm}\hrule
{width=85%}
\vspace{4mm}
\hrule
"I won't edit your code, so I don't care what it looks like." (true) \pause
"It's frustrating enough just getting the code to work, so I shouldn't feel bad about writing code that doesn't look good." (**[very](https://github.com/StirlingCodingClub/code_readability/blob/main/early_eg.R) [true](https://github.com/bradduthie/PolyInbreed/blob/master/parents.c)**)
# Why is writing readable code important?
*"If the code runs successfully, who cares how it looks?"*
\vspace{2mm}\hrule
{width=85%}
\vspace{4mm}
\hrule
"I won't see your code, so I don't care what it looks like." (true)
"It's frustrating enough just getting the code to work, so I shouldn't feel bad about writing code that doesn't look good." (**[very](https://github.com/StirlingCodingClub/code_readability/blob/main/early_eg.R) [true](https://github.com/bradduthie/PolyInbreed/blob/master/parents.c)**)
# Why is writing readable code important?
*"If the code runs successfully, who cares how it looks?"*
\vspace{2mm}\hrule
{width=85%}
\vspace{4mm}
\hrule
"I won't see your code, so I don't care what it looks like." (true)
"It's frustrating enough just getting the code to work, so I shouldn't feel bad about writing code that doesn't look good." (**[very](https://github.com/StirlingCodingClub/code_readability/blob/main/early_eg.R) [true](https://github.com/bradduthie/PolyInbreed/blob/master/parents.c)**)
# Why is writing readable code important?
*"If the code runs successfully, who cares how it looks?"*
\vspace{2mm}\hrule
{width=85%}
\vspace{4mm}
\hrule
"I won't see your code, so I don't care what it looks like." (true)
"It's frustrating enough just getting the code to work, so I shouldn't feel bad about writing code that doesn't look good." (**[very](https://github.com/StirlingCodingClub/code_readability/blob/main/early_eg.R) [true](https://github.com/bradduthie/PolyInbreed/blob/master/parents.c)**)
# Why is writing readable code important?
*"If the code runs successfully, who cares how it looks?"*
\vspace{2mm}\hrule
{width=85%}
\vspace{4mm}
\hrule
"I won't see your code, so I don't care what it looks like." (true)
"It's frustrating enough just getting the code to work, so I shouldn't feel bad about writing code that doesn't look good." (**[very](https://github.com/StirlingCodingClub/code_readability/blob/main/early_eg.R) [true](https://github.com/bradduthie/PolyInbreed/blob/master/parents.c)**)
# Sometimes readability is sacrificed for speed
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{itemize}
\setlength\itemsep{1.0em}
\item Usually better to focus on human readability first
\item Can refactor code later if \href{https://github.com/bradduthie/PolyInbreed/blob/master/Inbreed.c}{absolutely necessary}
\item Often there are alternative solutions
\begin{itemize}
\item Find a faster computer (short term)
\item Learn a new programming language (long term)
\end{itemize}
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\includegraphics{DuffsDevice.png}
\end{column}
\end{columns}
# What makes code readable?
\begin{itemize}
\item \textbf{Judicious use of comments}
\begin{itemize}
\item Used to clarify where necessary
\item No need to use where redundant \pause
\end{itemize}
\vspace{2mm}
\item \textbf{Clear naming of variables and functions}
\begin{itemize}
\item E.g., 'make\_data\_table' instead of 'mdt'
\item Easier to follow, less need for comments \pause
\end{itemize}
\vspace{2mm}
\item \textbf{Consistent and readable spacing}
\setlength\itemsep{0.0em}
\begin{itemize}
\item Easy to follow indentation style
\item Spaces after commas, semicolons, etc.
\item Avoid deep nesting where possible
\end{itemize}
\end{itemize}
# Other considerations aiding readability
\begin{itemize}
\item \textbf{What does the code look like on other screens?}
\begin{itemize}
\item Set a limit to characters per line (80 is common)
\item If a lot of code, consider using multiple files \pause
\end{itemize}
\vspace{2mm}
\item \textbf{Break code into manageable chunks}
\begin{itemize}
\item Avoids having to remember a lot all at once
\item Functions that can be viewed without scrolling help
\item Much easier to test (fewer bugs!) \pause
\end{itemize}
\item \textbf{Rstudio tools can be very helpful}
\begin{itemize}
\item Code > Reflow Comment
\item Code > Reindent Lines
\item Code > Reformat Code
\end{itemize}
\end{itemize}
# Find something that works for you
