1 of 20

COMPSCI 220

Programming Methodology

2 of 20

What Have You Learned So Far?

Java Java Java Java

Java!!�+a few algorithms & data structures

3 of 20

Can you just master Java and be done?

No!

4 of 20

Different Tasks => Different Languages

GLShader

Arduino-C

Python

5 of 20

New Languages Show Up At An Unprecedented Rate

6 of 20

The COMPSCI 220 Approach

  • You will need to learn many new languages to succeed in computer science
  • We’d love to spend 10+ years teaching you all the languages�(but then you’d miss the new languages introduced in those years)
  • We don’t have 10+ years

Thus, what we will teach you:

  • Principles that translate across any modern language, including Java, C++, Scala, Go, Swift
  • How to reason about programs for correctness, ease of debugging, and maintainability

7 of 20

JavaScript Is Everywhere

8 of 20

JavaScript Is Everywhere

9 of 20

The 220 web-based IDE: Ocelot

10 of 20

A Modern Take On JavaScript �COMPSCI 220-JS: Design to match other languages

  1. JavaScript has been around for > 20 years�Many old ways of programming still exist�New features, abstractions, and capabilities have been continuously added
  2. COMPSCI 220: An emphasis on modern JavaScript�Checks will disallow older features that have been superseded�Known bad coding practices are explicitly prohibited
  3. Arbitrary JS code from the internet may not compile�Much of the internet uses older JS features, and often poor coding practices�You should not be using code from the internet for assignments anyway
  4. TL;DR�Do not listen to the internet.�!!! If it does not run in Ocelot, it will get you 0 points.

11 of 20

What We Will Focus On (A Sampler)

  • First-class functions
  • Higher-order functions
  • Dynamic typing
  • Testing: unit, property based, reference
  • Functional programming
  • Abstract data types
  • Applications: Robotics, programming language implementation

12 of 20

Rules

  1. Read the syllabus�More rules included in the syllabus
  2. Work on your own�Cheating = automatic F
  3. Your code must compile�Does not compile = 0 on assignment
  4. No late submissions�See syllabus for exceptions

13 of 20

Rules

  1. Project Deadlines are hard and non-negotiable
    1. We will drop one lowest grade for each category
    2. These accommodates exceptional circumstances, including includes illness, family issues etc.
  2. Exam: make-up exam or disability service requests must be approved one week before the exam.
    • If you fall ill on the day of exam and have to request a make-up, you must provide an official doctor’s note.
    • No accommodation will be made after the exam.

13

14 of 20

Grading

Component

Weight

Projects: programming component

30%

Projects: quiz component

30%

Mid-Term 1

20%

Mid-Term 2

20%

15 of 20

How To Succeed

  1. Attend class�Doing homework without attending class will take 10x long, and you’ll do much worse.�We will sometimes give away answers.
  2. Start assignments early�You will need to think about them before coding.�Starting on the last day will not work well.
  3. Come to office hours and discussions�The quickest and easiest way to resolve doubts. Even faster than Piazza, email, text, facebook, twitter, etc.
  4. Ask questions�If you have a doubt about something, so will others. Those who don’t, will benefit from revision. You’re really helping everyone by asking.

16 of 20

JS: Basic Syntax; Using the Console

let a = 42; // Declare a variable, and assign it a number.

let b = 'Hello World'; // A string.

let c = [0, 1, 4, 9]; // An array of numbers.

const pi = 3.14159265359; // A constant.

console.log('The value of pi is ' + pi.toString()); // Print to the console.

console.log(c); // The console can display objects.

let d; // Will not compile: need to initialize value.

// The === operator in JS is equivalent to the == in other languages.

if (1 === 1) {

console.log('All is good.');

}

function factorial(x) {

let y = 1;

for (let z = 1; z <= x; ++z) {

y = y * z;

}

return y;

}

17 of 20

Types in JavaScript

> typeof 1

"number"

> typeof 2.3

"number"

> typeof "Hello, world!"

"String"

> typeof true

"boolean"

  1. Static types: In Java, you have to specify the types of variables and methods. The Java compiler catches type errors before you run the program.
  2. Dynamic types: In JavaScript, you do not have to specify the types in the program. The JavaScript evaluator catches type errors when the program is running.
  3. Note: JavaScript has types.�

Java

JavaScript

int a = 2;

float b = 1.3;

double c = 1.3;

String d = "Hello world";

let a = 2; // All numbers are doubles

let b = 1.3;

let c = 1.3;

let d = "Hello world";

Note: all numbers have the type "number", which is equivalent to the type double in Java.

18 of 20

Some Small Gotcha Points About JS

  1. Instead of "==", use "===". �Instead of "!=", use "!=="�JavaScript does not treat "==" and "!=" the same way as other languages. �We will not use this feature: remember, good programming practices.
  2. The type of a variable can changeDo not deliberately use this feature. It hampers readability, and may lead to bugs. �let a = 2;�a = "Hello world";
  3. The value undefined has type "undefined". It is similar to null in Java.�

19 of 20

Project 1: Image Processing

Removed green and blue

Grayscale

Highlight edges

Blur

20 of 20

COMPSCI 220 Homework

Programming:

  • Submit on Gradescope
  • Autograder will only reveal full test results after due date. Only a few simple test results will be shown before.

Written:

  • Fill in the answers, and upload pdf to Gradescope

See course website for late policy