You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: programming-fundamentals.md
+29-34
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,14 @@
4
4
In the introduction below, the syntax is python.
5
5
6
6
## Commands
7
-
Python, Matlab, and R are interpreted languages. That means the code is interpreted at runtime (there's no pre-compiling).
7
+
Python, Matlab, and R are interpreted languages. That means the code is interpreted at run-time (there's no pre-compiling).
8
8
Commands are given to the interpreter, either as a 'script', or in an interactive session.
9
9
The interpreter 'interprets' the code, translate it to binary CPU instructions, executes these instructions, and returns the result (if any).
10
10
11
11
## Variables & Datatypes
12
12
During execution, the instructions often need to access and manipulate data stored in memory.
13
13
14
-
Variables are named locations of the data in the memory, are of a specific 'datatype' have a value assigned to them.
14
+
Variables are named locations of the data in the memory, are of a specific 'datatype', and have a value assigned to them.
15
15
16
16
### Simple datatypes
17
17
@@ -97,7 +97,7 @@ We've already seen the assignment operator (`=`).
97
97
We also have the relational operators for comparing values (`==`, `!=`, `<`, `>`),
98
98
and the logical operators (`&&`, `and`, `||`, `or`, `!`, `not`).
99
99
100
-
So, we've covered, datatypes, variables, and operations. Next is the conditionals.
100
+
So, we've covered, datatypes, variables, and operators. Next is the conditionals.
101
101
102
102
## Conditionals
103
103
@@ -110,9 +110,9 @@ They use keywords like `IF`, `ELSE`, and `WHILE` to test conditions and execute
110
110
threshold = 40
111
111
my_value = 24
112
112
if(my_value >= 40):
113
-
print("Threshold passed")
113
+
print("Threshold passed")
114
114
else:
115
-
print("Threshold not passed")
115
+
print("Threshold not passed")
116
116
117
117
# > Threshold not passed
118
118
```
@@ -127,11 +127,11 @@ my_value = 41
127
127
my_name = "John Smith"
128
128
129
129
if(my_value >= threshold and my_name == "John Smith"):
130
-
print("Threshold passed by John Smith")
130
+
print("Threshold passed by John Smith")
131
131
elif(my_value >= threshold)
132
-
print("Threshold passed by " + my_name)
132
+
print("Threshold passed by " + my_name)
133
133
else:
134
-
print("Threshold not passed")
134
+
print("Threshold not passed")
135
135
136
136
# > Threshold passed by John Smith
137
137
```
@@ -149,8 +149,8 @@ At the end of the block we increment the counter. This will result in the code b
149
149
150
150
counter = 0
151
151
while(counter < 5):
152
-
print(counter)
153
-
counter = counter + 1
152
+
print(counter)
153
+
counter = counter + 1
154
154
155
155
# > 0
156
156
# > 1
@@ -169,10 +169,10 @@ the iterating counter printer into a function and call it to run the code.
169
169
# python
170
170
171
171
def print_number_of_times(times):
172
-
counter = 0
173
-
while(counter < times):
174
-
print(counter)
175
-
counter = counter + 1
172
+
counter = 0
173
+
while(counter < times):
174
+
print(counter)
175
+
counter = counter + 1
176
176
177
177
number_of_times(4)
178
178
@@ -192,8 +192,8 @@ in a nested format, whereby the output of one function becomes the input of anot
192
192
# python
193
193
194
194
def calculate_something(input1,input2):
195
-
intermediate = input1 * input2
196
-
return intermediate
195
+
intermediate = input1 * input2
196
+
return intermediate
197
197
198
198
print(calculate_something(3,6))
199
199
@@ -215,7 +215,7 @@ The definition of an object is a Class, and the instance of that Class is an obj
215
215
An objects functions are known as 'methods' and the variables are known as 'properties'.
216
216
217
217
## Control characters
218
-
Different languages use different 'control characters' for defining logical blocks executable code, for example separating out conditionals, operators, and function definitions.
218
+
Different languages use different 'control characters' for defining logical blocks of executable code, for example separating out conditionals, operators, and function definitions.
219
219
In Matlab and R, some control characters used are the
220
220
`{}()[]`. In Python, indentation and `:` is used to specify logical blocks.
221
221
@@ -233,9 +233,9 @@ In Matlab and R, some control characters used are the
233
233
234
234
import csv
235
235
with open('eggs.csv') as csvfile:
236
-
spamreader = csv.reader(csvfile)
237
-
for row in spamreader:
238
-
print(', '.join(row))
236
+
spamreader = csv.reader(csvfile)
237
+
for row in spamreader:
238
+
print(', '.join(row))
239
239
240
240
# > Spam, Spam, Spam, Spam, Spam, Baked Beans
241
241
# Spam, Lovely Spam, Wonderful Spam
@@ -254,33 +254,30 @@ with open('eggs.csv', 'w') as csvfile:
254
254
```
255
255
256
256
Libraries and packages exist for reading and writing many file types and DB connections.
257
-
Another example of when google is your friend.
257
+
When looking for informtion on these resources, google is your friend.
258
258
259
259
Carefully plan the format and structure of your data when designing your project
260
-
and writing your code. Most importantly, don't delete your raw data after you've processed it.
260
+
and writing your code. Most importantly, don't delete your raw data after you've processed it, keep it stored somewhere safe.
261
261
262
262
## Visualisation
263
263
264
264
When you are investigating your data, you will often want to plot the data.
265
265
266
266
Various charting libraries exist for most languages, each with different levels of functionality.
267
-
Some can produce very complex charts, but produce only static vector or bitmap images (ggplot2).
268
-
Others have less features but are interactive by default (plotly).
267
+
Some can produce very complex charts, but produce only static vector or bitmap images (`ggplot2`).
268
+
Others have less features but are interactive by default (`plotly`,Matlab).
269
269
270
-
They generally work by providing vectors of information and various settings.
271
-
272
-
Some examples of these will be provided for each language.
270
+
They generally work by providing vectors of information and various settings, such as type of chart, colours, legends, scale, etc.
273
271
274
272
## Help files
275
273
R and Matlab provide offline help files for understanding package functionalities and APIs.
276
-
Python's documentation is online, and packages often have readthedocs.io documentation pages.
274
+
Python's documentation is online, and packages often have `readthedocs.io` documentation pages.
277
275
Good documentation will give you an introduction to the package, argument settings,
278
276
and expected output. You should be able to drill down to to specific functions if
279
277
necessary. Learning how to read and interpret documentation will be necessary if you
280
-
plan to write any code beyond really basic stuff. Even then, most coders use google
281
-
for EVERYTHING.
278
+
plan to write any code beyond really basic stuff. Even then, most coders use google everyday.
282
279
283
-
## Managing code
280
+
## Managing code & version control
284
281
285
282
So, you've taken the leap and started coding. How should you manage the code you write?
286
283
With version control! Version control enables you to 'version' your code and create 'branches'
@@ -378,8 +375,6 @@ Good organisation of your workspace will enable you to write better code, with
378
375
less mistakes, and make it easier for you to come back in 6 months time and work
379
376
out what the hell was going on.
380
377
381
-
382
-
Keeping your data and code organised well will help you 6 months down the line.
383
-
378
+
That's the fundamentals covered, now it's on to Matlab.
0 commit comments