lecture 12 - nus computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of oop and fp,...

40

Upload: duongkien

Post on 02-May-2018

228 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions
Page 2: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Lecture 12Review

Page 3: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

What will you learn?

Page 4: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Understand and apply advanced programming concepts, including object-oriented concepts and functional programming concepts and constructs

• Comfortable with reading and developing medium-scale software

• Become proficient with modern Java (1.8 or above)

Page 5: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• know the pros/cons of OOP and FP, and when to use which

• be able to pick up new languages and advanced programming concepts quickly

Page 6: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Abstractions

Page 7: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Abstractions

• Abstraction of data: types

• Abstraction of instructions: methods

• Composite data type: classes and objects

Page 8: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Abstractions

• Abstraction of common behaviours across different types: generic types

• Abstraction of common behaviours over different behavior: lambdas

Page 9: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Benjamin C Pierce, Types and Programming Languages

"Each significant piece of functionality in a program should be implemented in just one place in the source code. Where similar functions are carried out by distinct pieces of code, it is generally beneficial to combine them into one by abstracting out the varying parts."

Page 10: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Less boiler plate codestream.filter().map()

• Can change easilystream.parallel().filter()..

Page 11: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• An abstraction barrier hides implementation details from users

Page 12: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Abstractions

• One of the most important concepts in computer science for dealing with complexity (in our case, complex code)

• You will see abstractions in computer architecture, OS, DB, networking, etc.

Page 13: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

New mindset: Write code for others

Page 14: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Provide a clear interface

• Hide your implementation details

• Provide documentation

Page 15: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Make your code clean and readable, following a certain convention

• Allow extension by inheritance

Page 16: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Modern Programming Constructs

Page 17: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Optional to avoid null

• Future/Promises to represent data that is not yet available

• Monads to chain and manipulate variables in certain context

• Threads/tasks as abstraction for concurrent programming

Page 18: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Effect-free Programming

Page 19: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Pure vs. unpure functions

• Immutable data types

• No side effects

• Made parallelization simple

Page 20: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Lazy evaluation

Page 21: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Asynchronous programming

• Infinite data structures

Page 22: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Java 8

Page 23: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Still a widely used language in the industry

• Static and strongly type language

• You should now be able read / write thousands of lines of Java code

Page 25: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Java libraries are mostly well designed and are good examples of OO design and implementation

Page 26: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

OOP vs FP

Page 27: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• OOP’s strength is polymorphism (abstractions over function pointers)

• FP’s strength is immutability

Page 28: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

- Uncle Bob , OO vs FP

“OO programming is good, when you know what it is. Functional programming is good when you know what it is. And functional OO programming is also good once you know what it is.”

Page 29: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Java vs Others

Page 30: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• You don’t always have a choice in programming language

• But if you do, there are many possibilities

Page 31: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Functional: Haskell, Erlang, OCaml

• Concurrent / Parallel: Erlang, Go

• Multi-paradigm: Javascript, Kotlin, Clojure, Scala, Goovy etc.

Page 32: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Have to use Java? Consider

• Google Guava

• Apache Commons

• Functional Java / JOOƛ

Page 33: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

What’s Next after CS2030 ?

Page 34: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

CS2103 Intro to Software Enginering

Page 35: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

CS2104 Concepts of Programming

Languages

Page 36: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

CS3210/11 Parallel Computing

Parallel / Concurrent Programming

Page 37: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

Final Exam

Page 38: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• Open Book: bring your notes!

• APIs (not in the notes) will be provided

• Covers Lecture 1 - 11, Lab 1 - 11 with more emphasis on topics not covered in midterm

Page 39: Lecture 12 - NUS Computingcs2030/1718-s1/cs2030-lec12.pdf · • know the pros/cons of OOP and FP, and when to use which ... • MCQs with short questions

• MCQs with short questions

• Mixed of conceptual and programming questions