/
Section  2 : Code Reasoning + Section  2 : Code Reasoning +

Section 2 : Code Reasoning + - PowerPoint Presentation

discoverfe
discoverfe . @discoverfe
Follow
343 views
Uploaded On 2020-06-15

Section 2 : Code Reasoning + - PPT Presentation

Programming tools cse331staffcswashingtonedu s lides borrowed and adapted from Alex Mariakis and CSE 390a Outline Reasoning about code Developer tools Eclipse and Java versions ssh ID: 777602

reasoning abs version svn abs reasoning svn version files true check control java ssh sqrt command washington stronger copy

Share:

Link:

Embed:

Download Presentation from below link

Download The PPT/PDF document "Section 2 : Code Reasoning +" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Section 2:Code Reasoning +Programming tools

cse331-staff@cs.washington.edu

s

lides borrowed and adapted from Alex

Mariakis

and CSE 390a

Slide2

OutlineReasoning about codeDeveloper tools

Eclipse and Java versionsssh

Version control

Slide3

Reasoning About CodeTwo purposesProve our code is correct

Understand why code is correct

Forward reasoning: determine what follows from initial conditionsBackward reasoning: determine sufficient conditions to obtain a certain result

Slide4

Forward Reasoning// {x

>=

0, y >= 0}y = 16;//x = x + y//x = sqrt(x)//

y = y - x

//

Slide5

Forward Reasoning// {x >= 0, y >= 0}

y = 16;

// {x >= 0, y = 16}x = x + y//x = sqrt(x)//y = y - x//

Slide6

Forward Reasoning// {x >= 0, y >= 0}

y = 16;

// {x >= 0, y = 16}x = x + y// {x >= 16, y = 16}x = sqrt(x)//y = y - x//

Slide7

Forward Reasoning// {x >= 0, y >= 0}

y = 16;

// {x >= 0, y = 16}x = x + y// {x >= 16, y = 16}x = sqrt(x)// {x >= 4, y = 16}

y = y - x

//

Slide8

Forward Reasoning// {x >= 0, y >= 0}

y = 16;

// {x >= 0, y = 16}x = x + y// {x >= 16, y = 16}x = sqrt(x)// {x >= 4, y = 16}

y

=

y - x

// {x

>=

4

,

y

<= 12}

Slide9

Forward Reasoning// {true}

if (x>0) {

// abs = x //}else { // abs = -x //}////

Slide10

Forward Reasoning// {true}

if (x>0) {

// {x > 0} abs = x //}else { // {x <= 0} abs = -x //}////

Slide11

Forward Reasoning// {true}

if (x>0) {

// {x > 0} abs = x // {x > 0, abs = x}}else { // {x <= 0} abs = -x // {x <= 0, abs = -x}}////

Slide12

Forward Reasoning// {true}

if (x>0) {

// {x > 0} abs = x // {x > 0, abs = x}}else { // {x <= 0} abs = -x // {x <= 0, abs = -x}}// {x > 0, abs = x OR x <= 0, abs = -x}

//

Slide13

Forward Reasoning// {true}

if (x>0) {

// {x > 0} abs = x // {x > 0, abs = x}}else { // {x <= 0} abs = -x // {x <= 0, abs = -x}}// {x > 0, abs = x OR x <= 0, abs = -x}

// {abs = |x|}

Slide14

Backward Reasoning//

a = x + b;

//c = 2b - 4 //x = a + c// {x > 0}

Slide15

Backward Reasoning//

a = x + b;

//c = 2b - 4 // {a + c > 0}x = a + c// {x > 0}

Slide16

Backward Reasoning//

a = x + b;// {a + 2b – 4 > 0}

c = 2b - 4 // {a + c > 0}x = a + c// {x > 0}

Slide17

Backward Reasoning// {x + 3b - 4 > 0}

a = x + b;

// {a + 2b – 4 > 0}c = 2b - 4 // {a + c > 0}x = a + c// {x > 0}

Slide18

ImplicationHoare triples are just an extension of logical implicationHoare triple: {P} S {Q}

P → Q after statement S

PQP → QTTT

F

F

T

F

F

Slide19

ImplicationHoare triples are just an extension of logical implicationHoare triple: {P} S {Q}

P → Q after statement SEverything implies true

False implies everythingPQP → QTTT

T

F

F

F

T

T

F

F

T

Slide20

Weaker vs. StrongerIf P1 → P2, thenP1 is stronger than P2P2 is weaker than P1

Weaker statements are more general, stronger statements say more

Stronger statements are more restrictiveEx: x = 16 is stronger than x > 0Ex: “Alex is an awesome TA” is stronger than “Alex is a TA”

Slide21

Weakest PreconditionThe most lenient assumptions such that a postcondition will be satisfied

If P* is the weakest precondition for {P} S {Q}, then P

→ P* for all P that make the Hoare triple validWP = wp(S, Q), which can be found using backward reasoningEx: wp(x = y+4, x > 0) = y+4>0

Slide22

Developer ToolsEclipse and Java versionsRemote access

Version control redux

Slide23

EclipseGet Java 7

Important: Java separates compile and execution, eg:

javac Example.java Example.classBoth compile and execute have to be the same Java!

produces

Slide24

What is an SSH client?Uses the secure shell protocol (SSH) to connect to a remote computerEnables you to work on a lab machine from home

Similar to remote desktopWindows users:

PuTTY and WinSCPPuTTY: ssh connectionWinSCP: transfer or edit filesMac/Linux users: Terminal applicationGo to Applications/Utilities/Terminal Type in “ssh cseNetID@attu.cs.washington.edu”“ssh -XY cseNetID@attu.cs.washington.edu” lets you use GUIs

Slide25

PuTTY

Slide26

Terminal (Linux, Mac)

Slide27

DEMO #1

http://courses.cs.washington.edu/courses/cse331/14au/tools/WorkingAtHome.html

Slide28

What is UniX?Multiuser modular operating systemTraditionally command-line

basedMac OS X is Unix-based!

CommandWhat it doespwdprints the name of the working directorylslists the files in a directory (i.e., lists stuff)cdchanges a directorycpcopies a file or directorymvmo

v

e

/rename a file or directory

rm

r

e

m

oves a file

mkdir

m

a

k

e a new

dir

ectory

rmdir

r

e

m

ove an empty

dir

ectory

man

pulls up the

man

ual pages

Slide29

Version Control

Working copy

Repository

svn

commit

update

Slide30

331 Version control

Repository

createWorking copy

update

commit

check out

add

check out

Working copy for grading

Slide31

331 Version ControlYour repo is at /projects/

instr/14au/cse331/YourCSENetID

/REPOS/cse331Only check out once (unless you’re working in a lot of places)Don’t forget to add files!!Check in your work!

Slide32

Version Control: gui

Slide33

Version Control: Command-line

command

description svn co

repo

check out

svn

ci

[files]

commit / check in changed files

svn

add

files

schedule files to be added at next commit

svn

help

[command]

get help info about a particular command

svn

merge

source1 source2

merge changes

svn

revert

files

restore local copy to repo's version

svn

resolve

files

resolve merging conflicts

svn

update

[files]

update local copy to latest version

others:

blame

,

changelist

,

cleanup

,

diff

,

export

,

ls/mv/rm/mkdir

,

lock/unlock

,

log

,

propset

Slide34

DEMO #2https://courses.cs.washington.edu/courses/cse331/14au/tools/versioncontrol.html