Charlie Garrod Bogdan Vasilescu School of Computer Science 17-214 1 - - PowerPoint PPT Presentation

charlie garrod bogdan vasilescu
SMART_READER_LITE
LIVE PREVIEW

Charlie Garrod Bogdan Vasilescu School of Computer Science 17-214 1 - - PowerPoint PPT Presentation

Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 1: Introduc9on Course overview and introduc9on to so3ware design Charlie Garrod Bogdan Vasilescu School of Computer Science 17-214 1 So3ware is everywhere 17-214 2


slide-1
SLIDE 1

1

17-214

School of Computer Science

Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 1: Introduc9on Course overview and introduc9on to so3ware design

Charlie Garrod Bogdan Vasilescu

slide-2
SLIDE 2

2

17-214

So3ware is everywhere

slide-3
SLIDE 3

3

17-214

Growth of code and complexity over 9me

(informal reports)

slide-4
SLIDE 4

4

17-214

15-313 Software 4

slide-5
SLIDE 5

5

17-214

Blackout of 2003 Normal night-time image

slide-6
SLIDE 6

6

17-214

School of Computer Science

Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 1: Introduc9on Course overview and introduc9on to so3ware design

Charlie Garrod Bogdan Vasilescu

slide-7
SLIDE 7

7

17-214

binary tree graph search sorting primes GCD

slide-8
SLIDE 8

8

17-214

Our goal: understanding both the building blocks and the design principles for construction of software systems

From programs to systems

Wri9ng algorithms, data structures from scratch Func9ons with inputs and outputs Sequen9al and local computa9on Full func9onal specifica9ons Reuse of libraries, frameworks Asynchronous and reac9ve designs Parallel and distributed computa9on Par9al, composable, targeted models

slide-9
SLIDE 9

9

17-214

School of Computer Science

Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 1: Introduc9on Course overview and introduc9on to so3ware design

Charlie Garrod Bogdan Vasilescu

slide-10
SLIDE 10

10

17-214

Objects in the real world

slide-11
SLIDE 11

11

17-214

Object-oriented programming

  • Programming based on structures

that contain both data and methods

public class Bicycle { private final Wheel frontWheel, rearWheel; private final Seat seat; private int speed; … public Bicycle(…) { … } public void accelerate() { speed++; } public int speed() { return speed; } }

slide-12
SLIDE 12

12

17-214

School of Computer Science

Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 1: Introduc9on Course overview and introduc9on to so3ware design

Charlie Garrod Bogdan Vasilescu

slide-13
SLIDE 13

13

17-214

Semester overview

  • Introduc9on to Java and O-O
  • Introduc9on to design

– Design goals, principles, paSerns

  • Designing classes

– Design for change – Design for reuse

  • Designing (sub)systems

– Design for robustness – Design for change (cont.)

  • Design case studies
  • Design for large-scale reuse
  • Explicit concurrency
  • CrosscuXng topics:

– Modern development tools: IDEs, version control, build automa9on, con9nuous integra9on, sta9c analysis – Modeling and specifica9on, formal and informal – Func9onal correctness: Tes9ng, sta9c analysis, verifica9on

slide-14
SLIDE 14

14

17-214

Sorting with a configurable order, version A

static void sort(int[] list, boolean ascending) { … boolean mustSwap; if (ascending) { mustSwap = list[i] < list[j]; } else { mustSwap = list[i] > list[j]; } … }

slide-15
SLIDE 15

15

17-214

Sorting with a configurable order, version B

interface Comparator { boolean compare(int i, int j); } class AscendingComparator implements Comparator { public boolean compare(int i, int j) { return i < j; } } class DescendingComparator implements Comparator { public boolean compare(int i, int j) { return i > j; } } static void sort(int[] list, Comparator cmp) { … boolean mustSwap = cmp.compare(list[i], list[j]); … }

slide-16
SLIDE 16

16

17-214

Sorting with a configurable order, version B'

interface Comparator { boolean compare(int i, int j); } final Comparator ASCENDING = (i, j) -> i < j; final Comparator DESCENDING = (i, j) -> i > j; static void sort(int[] list, Comparator cmp) { … boolean mustSwap = cmp.compare(list[i], list[j]); … }

slide-17
SLIDE 17

17

17-214

Which version is better?

static void sort(int[] list, boolean ascending) { … boolean mustSwap; if (ascending) { mustSwap = list[i] < list[j]; } else { mustSwap = list[i] > list[j]; } … } interface Comparator { boolean compare(int i, int j); } final Comparator ASCENDING = (i, j) -> i < j; final Comparator DESCENDING = (i, j) -> i > j; static void sort(int[] list, Comparator cmp) { … boolean mustSwap = cmp.compare(list[i], list[j]); … }

Version A: Version B':

slide-18
SLIDE 18

18

17-214

It depends?

slide-19
SLIDE 19

19

17-214

Software engineering is the branch of computer science that creates practical, cost-effective solutions to computing and information processing problems, preferably by applying scientific knowledge, developing software systems in the service of mankind.

Software Engineering for the 21st Century: A basis for rethinking the curriculum Manifesto, CMU-ISRI-05-108

slide-20
SLIDE 20

20

17-214

Software engineering is the branch of computer science that creates practical, cost-effective solutions to computing and information processing problems, preferably by applying scientific knowledge, developing software systems in the service of mankind. Software engineering entails making decisions under constraints of limited time, knowledge, and resources… Engineering quality resides in engineering judgment… Quality of the software product depends on the engineer’s faithfulness to the engineered artifact… Engineering requires reconciling conflicting constraints… Engineering skills improve as a result of careful systematic reflection on experience… Costs and time constraints matter, not just capability…

Software Engineering for the 21st Century: A basis for rethinking the curriculum Manifesto, CMU-ISRI-05-108

slide-21
SLIDE 21

21

17-214

Goal of so3ware design

  • For each desired program behavior there are infinitely many

programs

– What are the differences between the variants? – Which variant should we choose? – How can we synthesize a variant with desired proper9es?

slide-22
SLIDE 22

22

17-214

A typical Intro CS design process

1. Discuss so3ware that needs to be wriSen 2. Write some code 3. Test the code to iden9fy the defects 4. Debug to find causes of defects 5. Fix the defects 6. If not done, return to step 1

slide-23
SLIDE 23

23

17-214

Metrics of so3ware quality

  • Sufficiency / func9onal correctness

§ Fails to implement the specifica9ons … Sa9sfies all of the specifica9ons

  • Robustness

§ Will crash on any anomalous event … Recovers from all anomalous events

  • Flexibility

§ Must be replaced en9rely if spec changes … Easily adaptable to changes

  • Reusability

§ Cannot be used in another applica9on … Usable without modifica9on

  • Efficiency

§ Fails to sa9sfy speed or storage requirement … sa9sfies requirements

  • Scalability

§ Cannot be used as the basis of a larger version … is basis for much larger version…

  • Security

§ Security not accounted for at all … No manner of breaching security is known

Source: Braude, Bernstein, Software Engineering. Wiley 2011

Design challenges/goals

slide-24
SLIDE 24

24

17-214

BeSer so3ware design

  • Think before coding
  • Consider non-func9onal quality aSributes

– Maintainability, extensibility, performance, …

  • Propose, consider design alterna9ves

– Make explicit design decisions

slide-25
SLIDE 25

25

17-214

Using a design process

  • A design process organizes your work
  • A design process structures your understanding
  • A design process facilitates communica9on
slide-26
SLIDE 26

26

17-214

Preview: Design goals, principles, and paSerns

  • Design goals enable evalua9on of designs

– e.g. maintainability, reusability, scalability

  • Design principles are heuris9cs that describe best prac9ces

– e.g. high correspondence to real-world concepts

  • Design pa.erns codify repeated experiences, common solu9ons

– e.g. template method paSern

slide-27
SLIDE 27

27

17-214

School of Computer Science

Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 1: Introduc9on Course overview and introduc9on to so3ware design

Charlie Garrod Bogdan Vasilescu

slide-28
SLIDE 28

28

17-214

Concurrency

  • Roughly: doing more than one thing at a 9me
slide-29
SLIDE 29

29

17-214

Summary: Course themes

  • Object-oriented programming
  • Code-level design
  • Analysis and modeling
  • Concurrency
slide-30
SLIDE 30

30

17-214

So3ware Engineering (SE) at CMU

  • 17-214: Code-level design

– Extensibility, reuse, concurrency, func9onal correctness

  • 17-313: Human aspects of so3ware development

– Requirements, teamwork, scalability, security, scheduling, costs, risks, business models

  • 17-413 Prac9cum, 17-415 Seminar, Internship
  • Various courses on requirements, architecture, so3ware

analysis, SE for startups, etc.

  • SE Minor: hSp://isri.cmu.edu/educa9on/undergrad

30

slide-31
SLIDE 31

31

17-214

COURSE ORGANIZATION

slide-32
SLIDE 32

32

17-214

Precondi9ons

  • 15-122 or equivalent

– Two semesters of programming – Knowledge of C-like languages

  • 21-127 or equivalent

– Familiarity with basic discrete math concepts

  • Specifically:

– Basic programming skills – Basic (formal) reasoning about programs

  • Pre/post condi9ons, invariants, formal verifica9on

– Basic algorithms and data structures

  • Lists, graphs, sor9ng, binary search, etc.
slide-33
SLIDE 33

33

17-214

Learning goals

  • Ability to design medium-scale programs
  • Understanding OO programming concepts & design decisions
  • Proficiency with basic quality assurance techniques for

func9onal correctness

  • Fundamentals of concurrency
  • Prac9cal skills
slide-34
SLIDE 34

34

17-214

Course staff

  • Bogdan Vasilescu

vasilescu@cmu.edu Wean 5115

  • Charlie Garrod

charlie@cs.cmu.edu Wean 5101

  • Teaching assistants: Adithya, Arihant, Bujji, David, Megan, Nick, Tian
slide-35
SLIDE 35

35

17-214

Course mee9ngs

  • Lectures: Tuesday and Thursday 3:00 – 4:20pm DH A302

– Electronic devices discouraged

  • Recita9ons: Wednesdays 9:30 - … - 2:20pm

– Supplementary material, hands-on prac9ce, feedback – Bring your laptop

  • Office hours: see course web page

– hSps://www.cs.cmu.edu/~charlie/courses/17-214/

Recitation attendance is required

Smoking Section

slide-36
SLIDE 36

36

17-214

Infrastructure

  • Course website: hSp://www.cs.cmu.edu/~charlie/courses/17-214

– Schedule, office hours calendar, lecture slides, policy documents

  • Tools

– Git, Github: Assignment distribu9on, hand-in, and grades – Piazza: Discussion board – Eclipse or IntelliJ: Recommended for code development (other IDEs are fine) – Gradle, Travis-CI, Checkstyle, Findbugs: Prac9cal development tools

  • Assignments

– Homework 1 available tomorrow

  • First recita9on is tomorrow

– Introduc9on to Java and the tools in the course – Install Git, Java, some IDE, Gradle beforehand

slide-37
SLIDE 37

37

17-214

Textbooks

  • Required course textbooks (electronically

available through CMU library):

– Joshua Bloch. Effec9ve Java, Third Edi9on. Addison-Wesley, ISBN 978-0-13-468599-1. – Craig Larman. Applying UML and PaSerns. 3rd

  • Edi9on. Pren9ce Hall, ISBN 978-0321356680.
  • Addi9onal readings on design, Java, and

concurrency on the course web page

slide-38
SLIDE 38

38

17-214

Approximate grading policy

  • 50% assignments
  • 20% midterms (2 x 10% each)
  • 20% final exam
  • 10% quizzes and par9cipa9on

This course does not have a fixed leSer grade policy; i.e., the final leSer grades will not be A=90-100%, B=80-90%, etc.

slide-39
SLIDE 39

39

17-214

Collabora9on policy (also see the course syllabus)

  • We expect your work to be your own

– You must clearly cite external resources so that we can evaluate your own personal contribu9ons.

  • Do not release your solu9ons (not even a3er end of semester)
  • Ask if you have any ques9ons
  • If you are feeling desperate, please mail/call/talk to us

– Always turn in any work you've completed before the deadline

  • We use chea9ng detec9on tools
slide-40
SLIDE 40

40

17-214

Late day policy

  • You may turn in each* homework up to 2 days late
  • You have five free late days per semester

– 10% penalty per day a3er free late days are used

  • We don't accept work 3 days late
  • See the syllabus for addi9onal details
  • Got extreme circumstances? Talk to us
slide-41
SLIDE 41

41

17-214

10% quizzes and par9cipa9on

  • Recita9on par9cipa9on counts toward your par9cipa9on grade
  • Lecture has in-class quizzes
slide-42
SLIDE 42

42

17-214

Summary

  • So3ware engineering requires decisions, judgment
  • Good design follows a process
  • You will get lots of prac9ce in 17-214!
slide-43
SLIDE 43

1

17-214

School of Computer Science

Principles of So3ware Construc9on: Objects, Design, and Concurrency Introduc3on to course infrastructure

Charlie Garrod Bogdan Vasilescu

slide-44
SLIDE 44

2

17-214

Remember: class website

slide-45
SLIDE 45

3

17-214

DevOps

slide-46
SLIDE 46

4

17-214

A DevOps Defini9on

  • “DevOps is a set of prac9ces

intended to reduce the 9me between commiKng a change to a system and the change being placed into normal produc9on, while ensuring high quality.”

slide-47
SLIDE 47

5

17-214

DevOps Toolchain

https://marketplace-cdn.atlassian.com/s/f01dfe0a9e6d2f8a1d1bada432a8914f126aea8b/public/devops-hero.png

slide-48
SLIDE 48

6

17-214

You will need for homework 1

  • Java (+Eclipse/IntelliJ): more on Thursday
  • Version control: Git
  • Hos9ng: GitHub
  • Build manager: Gradle
  • Con9nuous integra9on service: Travis-CI
slide-49
SLIDE 49

7

17-214

What is version control?

  • System that records changes to a set of files over

9me

– Revert files back to a previous state – Revert en9re project back to a previous state – Compare changes over 9me – See who last modified something that might be causing a problem

  • As opposed to:

hw1.java

hw1_v2.java hw1_v3.java hw1_final.java hw1_final_new.java …

slide-50
SLIDE 50

8

17-214

Brief 9meline of VCS

  • 1982: RCS (Revision Control System), s9ll maintained
  • 1990: CVS (Concurrent Versions System)
  • 2000: SVN (Subversion)
  • 2005: Bazaar, Git, Mercurial

Git

  • Developed by Linus Torvalds, the creator of Linux
  • Designed to handle large projects like the Linux kernel

efficiently

– Speed – Thousands of parallel branches

slide-51
SLIDE 51

9

17-214

Centralized version control

  • Single server that

contains all the versioned files

  • Clients check out/in

files from that central place

  • E.g., CVS, SVN

(Subversion), and Perforce

https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control

slide-52
SLIDE 52

10

17-214

SVN

Server (truth) Clients Network svn checkout

slide-53
SLIDE 53

11

17-214

SVN

Server (truth) Clients Network svn commit

slide-54
SLIDE 54

12

17-214

SVN

Server (truth) Clients Network svn update

slide-55
SLIDE 55

13

17-214

SVN

Server (truth) Clients Network svn commit: FAIL

slide-56
SLIDE 56

14

17-214

SVN

Server (truth) Clients Network svn update

slide-57
SLIDE 57

15

17-214

SVN

Server (truth) Clients Network svn update: CONFLICT

slide-58
SLIDE 58

16

17-214

Centralized version control

  • Advantages:

– Everyone knows what everyone else is doing (mostly) – Administrators have more fine-grained control

  • Disadvantages:

– Single point of failure – Cannot work offline – Slow – Does not scale

  • Easier to lose data
  • Incen9ve to use version

control sparingly

  • Tangled instead of

atomic commits

slide-59
SLIDE 59

17

17-214

SVN

Server (truth) Clients Network svn update: CONFLICT svn commit Every 9me there is a commit on the system there is a chance of crea9ng a conflict with someone else

slide-60
SLIDE 60

18

17-214

SVN

Server (truth) Conflicts: sometimes Network svn update: CONFLICT svn commit 3 developers

slide-61
SLIDE 61

19

17-214

SVN

Server (truth) Conflicts: often Network svn update: CONFLICT svn commit 30 developers

slide-62
SLIDE 62

20

17-214

SVN

Server (truth) Conflicts: all the time to everybody Network svn update: CONFLICT svn commit 300 developers

slide-63
SLIDE 63

21

17-214

Git

Server (truth) Git is distributed. There is not one server …

slide-64
SLIDE 64

22

17-214

Git

… but many

slide-65
SLIDE 65

23

17-214

Git

Actually there is one server per computer

slide-66
SLIDE 66

24

17-214

Git

Every computer is a server and version control happens locally.

slide-67
SLIDE 67

25

17-214

Distributed version control

  • Clients fully mirror the

repository

– Every clone is a full backup of all the data

  • Advantages:

– Fast, works offline, scales – Bener suited for collabora9ve workflows

  • E.g., Git, Mercurial,

Bazaar

https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control

slide-68
SLIDE 68

26

17-214

SVN (le3) vs. Git (right)

  • SVN stores changes to a base

version of each file

  • Version numbers (1, 2, 3, …)

are increased by one a3er each commit

  • Git stores each version as a

snapshot

  • If files have not changed, only a

link to the previous file is stored

  • Each version is referred by the

SHA-1 hash of the contents

https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control

slide-69
SLIDE 69

27

17-214

Git

git commit How do you share code with collaborators if commits are local?

slide-70
SLIDE 70

28

17-214

Git

git push git pull git push … But requires host names / IP addresses You push your commits into their repositories / They pull your commits into their repositories

slide-71
SLIDE 71

29

17-214

GitHub typical workflow

GitHub Public repository where you make your changes public

slide-72
SLIDE 72

30

17-214

GitHub typical workflow

GitHub git commit

slide-73
SLIDE 73

31

17-214

GitHub typical workflow

GitHub git commit

slide-74
SLIDE 74

32

17-214

GitHub typical workflow

GitHub git push push your local changes into a remote repository.

slide-75
SLIDE 75

33

17-214

GitHub typical workflow

GitHub git push Collaborators can push too if they have access rights.

slide-76
SLIDE 76

34

17-214

GitHub typical workflow

GitHub git pull

Without access rights, “don’t call us, we’ll call you” (pull from trusted sources) … But again requires host names / IP addresses.

slide-77
SLIDE 77

35

17-214

GitHub typical workflow

GitHub git push “Main” “Forks”

Instead, people maintain public remote “forks” of “main” repository on GitHub and push local changes.

slide-78
SLIDE 78

36

17-214

GitHub typical workflow

GitHub Pull Request “Main” “Forks”

Availability of new changes is signaled via ”Pull Request”.

slide-79
SLIDE 79

37

17-214

GitHub typical workflow

GitHub git pull “Main” “Forks”

Changes are pulled into main if PR accepted.

slide-80
SLIDE 80

38

17-214

214 workflow

GitHub “Main”

Your local “clone” TA’s “clone” You push homework solutions; pull recitations, homework assignments, grades. TAs vice versa

slide-81
SLIDE 81

39

17-214

You will need for homework 1

  • Java (+Eclipse/IntelliJ): more on Thursday
  • Version control: Git
  • Hos9ng: GitHub
  • Build manager: Gradle
  • Con9nuous integra9on service: Travis-CI
slide-82
SLIDE 82

40

17-214

Build Manager

  • Tool for scrip9ng the automated steps

required to produce a so3ware ar9fact, e.g.:

– Compile Java files in src/main/java, place results in target/classes – Compile Java files in src/test/java, place results in target/test-classes – Run JUnit tests in target/test-classes – If all tests pass, package compiled classes in target/classes into .jar file.

slide-83
SLIDE 83

41

17-214

Build Manager

  • Tool for scrip9ng the automated steps

required to produce a so3ware ar9fact, e.g.:

– Compile Java source files into class files – Compile Java test files – Run JUnit tests – If all tests pass, package compiled classes into .jar file.

slide-84
SLIDE 84

42

17-214

Aside: Java virtual machine

http://images.slideplayer.com/21/6322821/slides/slide_9.jpg

slide-85
SLIDE 85

43

17-214

Types of Build Managers

  • IDE project managers (limited func9onality)
  • Dependency-Based Managers

– Make (1977)

  • Task-Based Managers

– Ant (2000) – Maven (2002) – Ivy (2004) – Gradle (2012)

slide-86
SLIDE 86

44

17-214

Dependency-Based Managers

  • Dependency graph:

– Boxes: files – Arrows: dependencies; “A depends on B”: if B is changed, A must be regenerated

  • Build manager (e.g.,

Make) determines min number of steps required to rebuild a3er a change.

slide-87
SLIDE 87

45

17-214

Task-Based Managers: Ant

  • Disadvantages of Make:

– Not portable (system- dependent commands, paths, path lists) – Low level (focus on individual files)

  • Ant:

– Focus on task dependencies – Targets (dependencies) described in build.xml

slide-88
SLIDE 88

46

17-214

Task-Based Managers: Maven

  • Maven:

– build management (like Ant), – and dependency management (unlike Ant)

  • Can express standard project layouts and

build conven9ons (project archetypes)

  • S9ll uses XML (pom.xml)
slide-89
SLIDE 89

47

17-214

Organizing a Java Project

(Project root) Op9onal: Sub- Project src main java resources test java resources target Op9onal: Sub- Project ... Derived (does not go into version control), e.g., compiled Java Actual source code Everything below src/main gets deployed, i.e., no tests README.md, LICENSE.md, version control, configuration management

slide-90
SLIDE 90

48

17-214

Task-Based Managers: Gradle

  • Combines the best of Ant and Maven
  • From Ant keep:
  • Portability: Build commands described plarorm-independently
  • Flexibility: Describe almost any sequence of processing steps
  • … but drop:
  • XML as build language, inability to express simple control flow
  • From Maven keep:
  • Dependency management
  • Standard directory layouts & build conven9ons for common

project types

  • … but drop:
  • XML, inflexibility, inability to express simple control flow
slide-91
SLIDE 91

49

17-214

You will need for homework 1

  • Java (+Eclipse/IntelliJ): more on Thursday
  • Version control: Git
  • Hos9ng: GitHub
  • Build manager: Gradle
  • Con9nuous integra9on service: Travis-CI
slide-92
SLIDE 92

50

17-214

Big Builds

  • Must run frequently:
  • fetching and setup of

3rd party libraries

  • sta9c analysis
  • compila9on
  • unit tes9ng
  • packaging of ar9facts
  • Can run less

frequently:

  • documenta9on
  • deployment
  • integra9on tes9ng
  • test coverage

repor9ng

  • system tes9ng
  • Keep track of different Ant/Maven targets, or …
slide-93
SLIDE 93

51

17-214

Con9nuous Integra9on

  • Version control with central “official” repository. Run:

– automated builds & tests (unit, integra9on, system, regression) with every change (commit / pull request) – Test, ideally, in clone of produc,on environment – E.g., Jenkins (local), Travis CI (cloud-based)

  • Advantages:

– Immediate tes9ng of all changes – Integra9on problems caught early and fixed fast – Frequent commits encourage modularity – Visible code quality metrics mo9vate developers – (cloud-based) Local computer not busy while wai9ng for build

  • Disadvantages:

– Ini9al effort to set up

slide-94
SLIDE 94

52

17-214

Travis CI

  • Cloud-based CI service; GitHub integra9on

– Listens to push events and pull request events and starts “build” automa9cally – Runs in virtual machine / Docker container – No9fies subminer of outcome; sets GitHub flag

  • Setup: project top-level folder .travis.yml

– Specifies which environments to test in (e.g., jdk versions)

slide-95
SLIDE 95

53

17-214

You will need for homework 1

  • Java (+Eclipse/IntelliJ): more on Thursday
  • Version control: Git
  • Hos9ng: GitHub
  • Build manager: Gradle
  • Con9nuous integra9on service: Travis-CI