COMP1531
24T3 Week 1
Wednesday 5PM - 7PM (W17A)
Slides by Alvin Cherk (z5311001)
Today
- Git
- Javascript & Typescript
- Backend web development
- Teamwork skills
Introduction
- My name is Alvin
- Graduated CS
- Email: a.cherk@unsw.edu.au (Please try using the forums before emailing me, unless its for a personal reason)
- Include your zID somewhere so I can easily identify you
- I will usually take 24-48 hours at most to reply. If you don't get a reply, then send a follow up email.
- Course email: cs1531@cse.unsw.edu.au
- Don't like how something is handled? You're welcome to escalate it to course admins. (Do talk to me first if possible).
- Any personal issues as well
How will it work?
-
1 Hour tutorial, 2 hour lab
- Tutorial: Cover relevant and extra topics helpful for you to know for the project
- Lab: Lab exercises, general help, project check-ins/marking/demos (later).
-
Group project (90%)
- it1 Project Demo in wk 5 lab
- it2 Project emo in wk 8 lab
- Final Presentation in wk 11 (it3)
- Labs (10%)
-
Getting help (https://cgi.cse.unsw.edu.au/~cs1531/)
- Edstem forums
- Help sessions
- Lab time (tutors + lab assist)
Ice Breaker
- Name (and preferred name)
- Degree
- Favourite language & why
Or
Random interesting fact
Git
Git Revision
-
git add
- Stage files
-
git commit
- Commit the staged files as a snapshot
-
git push
- Push your new commits to an online origin (GitLab, BitBucket, GitHub)
-
git status
- State of current repository & branch
-
git log
- History of current branch
Git Config
When you commit
something, you are effectively saving the staged files as a new snapshot and signing it with your name and email.
You have to configure your git identity if you haven't done it before.
git config --global user.name "Your Name Here"
git config --global user.email "z555555@unsw.edu.au"
You then can add whatever email you have set in user.email on GitLab, so that it recognises all the commits that have been pushed to GitLab.
Please do this, its important Git etiquette.
It also allows your tutor to track the work you have done in your pair assignment.
Basic Syntax
Basic Syntax, Input/Output, Conditionals & Control Flow + Functions
#include <stdio.h>
#define SIZE 10
void print_parity(int num);
int main(void) {
char message[] = "Welcome to COMP1531!";
printf("%s\n", message);
printf("Numbers from 1 to %d\n", SIZE);
for (int num = 1; num <= SIZE; num++) {
print_parity(num);
}
return 0;
}
void print_parity(int num) {
if (num % 2 == 0) {
printf("EVEN: %d\n", num);
} else {
printf("ODD: %d\n", num);
}
}
- Why don't we need to specify the type of a variable when we declare it?
- What are
const
andlet
? - How is JavaScript's
console.log
function different toprintf
in C? - How can we format strings?
- What does
2=='2'
return? why? - Why don't JavaScript programs need a
main
function? - How do we create a function? how is this different to creating functions in c?
Basic Syntax, Input/Output, Conditionals & Control Flow + Functions
// No #include
// no main function
const SIZE = 10; // Dynamically typed & const
const message = 'Welcome to COMP1531!'; // Single quotes
console.log(message); // No '\n'
console.log(`Numbers from 1 to ${SIZE}`); // Recommended string layout
for (let num = 1; num <= SIZE; num++) { // let
print_parity(num);
}
function print_parity(num) { // function & no type in parameter & no return type
if (num % 2 === 0) { // Triple equals
console.log(`EVEN: ${num}`);
} else {
console.log(`ODD: ${num}`);
}
}
Array Objects + Loops
Javascript objects are just a collection of properties, kinda like structs, but better. Properties are key value pairs in the form key: value
where keys are strings or numbers and values can be of any type (String, Number, Array, Object, etc..).
let fruit = {
name: 'apple',
cost: 2
}
const arr = [1, 2.02, "3"]
for (const of in arr) {
console.log(typeof(i))
}
-
How can we get the name and cost of the fruit in the object above?
-
Brainstorm ways we can loop through the shopping list given in loopy.js to print the names of all items in the shopping list?
-
Why should we use for of loops instead of for in loops where possible?
(typeof
is a function that returns a string with the type of the argument passed in. what does this program output?)
Style
While we haven't given you a style guide yet, it's still important to maintain good style! Most styling rules taught in 1511 still apply.
Take a look at style.js. It contains many style issues :< You will have 5 minutes to review the code in your groups and identify as many style issues as you can!
Array Methods
JavaScript is a high-level language with many built-in features that simplify common tasks. This built-in functionality makes it easier to read, write and debug code :3
Today, we’ll focus on array methods. These are like functions specifically designed for performing common operations on arrays, such as adding elements, finding items, sorting, and more. We’ve already used the length
method earlier to determine the number of elements in an array!
COMP1531 Week 1 24T3
By kuroson
COMP1531 Week 1 24T3
- 82