# Tutorial 3
---

---
### Questions from last week
- Is there a way to do dice range and the Easter exercise without making everything a double?
---
### Overview
- Code review
- While Loops
- Variable Names
- #define
- Operations and Datatype Conversions
---
### Code Review
What to look for in a code review:
- Purpose
- Implementation
- Legibility and Style
Check this [Palantir guide for code reviews](https://medium.com/palantir/code-review-best-practices-19e02780015f)
---
### Code Review
In industry, they also check for:
- Maintainability
- Security
---
### Code Review: Who's next?
2 pairs each week for the next 6 weeks
- Josh and James
- Carla and Kailin
---
### Variable Names
* THX1138
* 2for1
* mr_bean
* my space
* event_counter
* \^oo\^
* _MEMLIMIT
* return
---
### Variable Names
* THX1138 (Valid, not good - doesn't start with a lower-case letter)
* 2for1 (Invalid - doesn't start with a letter or underscore)
* mr_bean (Valid, good if the variable has something to do with Mr Bean)
* my space (Invalid - you can't have spaces in variables names)
* event_counter (Valid in C, good)
* \^oo\^ (Invalid - only letters, numbers and underscore allowed)
* _MEMLIMIT (Valid not good - doesn't start with a lower-case letter)
* return (Invalid - this is a special keyword in C)
---
### Using #defines
```C=
#include <stdio.h>
#define FIRST_NUMBER 10
#define SECOND_NUMBER 20
#define TOTAL FIRST_NUMBER + SECOND_NUMBER
#define AVERAGE TOTAL / 2
int main(void) {
printf("The average of %d and %d is %d\n",
FIRST_NUMBER, SECOND_NUMBER, AVERAGE);
return 0;
}
```
---
### Operations and Datatype Conversions
* 1 / 2 * 500
* 1 / 2.0 * 500
* (17 / 5) * 5 + (17 % 5)
* (12 - 17) % 6 - 4
---
### Operations and Datatype Conversions
* 1 / 2 * 500 = 0
* 1 / 2.0 * 500 = 250.0
* (17 / 5) * 5 + (17 % 5) = 17
* (12 - 17) % 6 - 4 = -9
---
### Implicit C Datatype Conversions

---
### Conditionals
[According to Wikipedia...](https://en.wikipedia.org/wiki/Leap_year#Algorithm)
> if (year is not divisible by 4) then (it is a common year)
else if (year is not divisible by 100) then (it is a leap year)
else if (year is not divisible by 400) then (it is a common year)
else (it is a leap year)
---
### Typed languages
What does this mean? Why is this useful?
---
### Typed languages
What does this mean? Why is this useful?
- Easier debugging
- Better control over memory
---
### Style is important!
This week, please pick one piece of code from last week's lab to quickly be reviewed in lab for style.
**Note:** This will not count towards marks, purely to help make sure you're getting into good habits!
{"metaMigratedAt":"2023-06-14T17:29:58.019Z","metaMigratedFrom":"Content","title":"Tutorial 3","breaks":true,"contributors":"[{\"id\":\"3a8692fe-89b9-4b4e-824d-00af489f87f1\",\"add\":4752,\"del\":1940}]"}