50
What makes a good language • Does the task you want • Keeps you from making mistakes • Supports debugging when you need it • Has a strong tool kit

What makes a good language

  • Upload
    garson

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

What makes a good language. Does the task you want Keeps you from making mistakes Supports debugging when you need it Has a strong tool kit. Big number bug. - PowerPoint PPT Presentation

Citation preview

Page 1: What makes a good language

What makes a good language

• Does the task you want

• Keeps you from making mistakes

• Supports debugging when you need it

• Has a strong tool kit

Page 2: What makes a good language

Big number bug

On June 4, 1996 an unmanned Ariane 5 rocket launched by the European Space Agency exploded just forty seconds after its lift-off from Kourou, French Guiana. The rocket was on its first voyage, after a decade of development costing $7 billion. The destroyed rocket and its cargo were valued at $500 million. A board of inquiry investigated the causes of the explosion and in two weeks issued a report. It turned out that the cause of the failure was a software error in the inertial reference system. Specifically, a 64 bit floating point number relating to the horizontal velocity of the rocket with respect to the platform was converted to a 16 bit signed integer. The number was larger than 32,768, the largest integer that could be stored in a 16 bit signed integer, and so the conversion failed.

Page 3: What makes a good language

Pentium II bug

• Software bug encoded in hardware• Division algorithm uses a lookup table of

1066 entries• Only 1061 of the entries are downloaded to

the PLA (programmed logic array from which the data are used)

• Intel had to recall all versions of the chip

Page 4: What makes a good language

Syntax “typo” bugs

• NASA Mariner 1 , Venus probe (1992)

• Intended to be the first US spacecraft to visit another planet, it was destroyed by a range officer on 22 July 1962 when it behaved erratically four minutes after launch. – Essentially a period instead of a comma in a

FORTRAN DO-Loop

Page 5: What makes a good language

Control flow bug

• AT&T long distance service fails for nine hours(Wrong BREAK statement in C code)

• January 15, 1990:• 70 million of 138 million long distance customers

in the US lost long distance service. • Cost to ATT was between $ 75 Million and $100

Million (plus the loss of good will).

Page 6: What makes a good language

• E-mail buffer overflow (1998)• Several E-mail systems suffer from a "buffer

overflow error", when extremely long e-mail addresses are received.  The internal buffers receiving the addresses do not check for length and allow their buffers to overflow causing the applications to crash.  Hostile hackers use this fault to trick the computer into running a malicious program in its place.

Data structure management bug

Page 7: What makes a good language

Summary• Programming is difficult

– Have to thoroughly understand the task– Have to anticipate all possibilities– Code is written at a fairly primitive level– Impossible to anticipate what users might do

• Programming languages allow the user to use tools to build code

• But everything still has bugs• The cost of a bug can be very large

• There is no Moore’s Law for software.

Page 8: What makes a good language

The big picture

• We built a computer

• We talked about languages and compilers to make programming the computer easier

• Next we talk about algorithms, which are implemented by programs

Page 9: What makes a good language

Algorithms

• Recipes for doing computations

• The underpinnings of programming – Think out your algorithm– Show that it works– Determine it’s efficiency– Write it as a program

Page 10: What makes a good language

What is an algorithm

• Algorithm is a recipe

• Has – Inputs

– Rules

– Evaluation Criteria

– Output

Page 11: What makes a good language

When Do We Use Algorithms

• When we have a problem to solve

• Examples of problems– Baking cookies– Putting things in alphabetical order– Searching the Web

Page 12: What makes a good language

Chocolate chip cookies

Page 13: What makes a good language

Chocolate chip cookies

• Input– flour (2 ¼ c)– baking soda (1t) – salt (1t)– butter (1c)– granulated sugar (3/4 c)– brown sugar(3/4c) – vanilla(1t) – eggs (2)– chocolate chip morsels (2c)– chopped nuts (1c)

• Output– 5 dozen cookies

Page 14: What makes a good language

Chocolate chip cookies: Steps• Combine flour, baking soda, and salt in small bowl.• Beat butter, granulated sugar, brown sugar and vanilla in

large bowl • Add eggs one at a time Beating after adding each egg• Gradually beat in flour mixture• Stir in morsels and nuts• Drop by rounded tablespoons onto ungreased baking sheets• Bake 9-11 minutes• Let stand for 2 minutes

Page 15: What makes a good language

Chocolate chip cookie algorithm

• Primitives– Inputs

• Flour, baking soda, salt, butter, brown sugar, granulated sugar, vanilla, egg, morsels, nuts

• Alternatively, chocolate chip cookie mix

• Alternatively, wheat, sugar cane, …

– Operators• Combine, Beat, Gradually beat, Stir, Drop, Bake, Let

stand

Page 16: What makes a good language

Chocolate chip cookie algorithm

• Execution– First 2 steps can be done in parallel?

• Parbegin (Combine(),Beat()) Parend

– Machine dependencies• Ovens vary (Bake 9-11 minutes)

• Ingredients vary and so need to be handled differently

Page 17: What makes a good language

Chocolate chip cookie algorithm

• Algorithm testing– Proof of the pudding is in the eating– How do we mechanize this?

Page 18: What makes a good language

Chocolate chip cookie algorithm

• Comparing different algorithms– Quality of results– User time– Machine (oven) time

Page 19: What makes a good language

Putting things in alphabetical order

• Data set sizes– Course list for COS 111 10-15 students

– PU directory assistance 10,000 people

– Manhattan phone book 1 million people

– Social Security database 1 billion records

– Long distance call billing records 100 billion/year

• Different methods for different tasks– Fast for large

– Simple for small

Page 20: What makes a good language

A simple method for sorting

• Find smallest value -- put it first in list

• Find second smallest value -- put it second

• …

• Find next smallest value – put it next

• …

• When no more values, you’re done

Page 21: What makes a good language

How it works

57

190

219

34

Page 22: What makes a good language

How it works

Find smallest value -- put it first in list

57

190

219

34

34

190

219

57

Page 23: What makes a good language

How it works

Find second smallest value -- put it second

57

190

219

34

34

190

219

57

34

57

219

190

Page 24: What makes a good language

How it works

Finish the sorting

57

190

219

34

34

190

219

57

34

57

219

190

34

57

190

219

Page 25: What makes a good language

A simple method for sorting

• To sort array x = {x[1],x[2], … , x[n]}

For I = 1 to n For J = I+1 to n

If (x[I] > x[J]) Then swap their valuesnext

next

Page 26: What makes a good language

Another sorting algorithm

• Sorting by Merging

• Key idea It’s easy to merge 2 sorted lists

Page 27: What makes a good language

Merging 2 sorted lists

190

219

463

155

255

355

Page 28: What makes a good language

Merging 2 sorted lists

190

219

463

155

255

355

Start at the top of each list

Page 29: What makes a good language

Merging 2 sorted lists

190

219

463

155

255

355

190 is bigger than 155

Page 30: What makes a good language

Merging 2 sorted lists

190

219

463

155

255

355

155

Record 155 and move the arrow

Page 31: What makes a good language

Merging 2 sorted lists

190

219

463

155

255

355

155

190

190 is less than 255

Page 32: What makes a good language

Merging 2 sorted lists

190

219

463

155

255

355

155

190

219

219 is less than 255

Page 33: What makes a good language

Merging 2 sorted lists

190

219

463

155

255

355

155

190

219

255

255 is less than 463

Page 34: What makes a good language

Merging 2 sorted lists

190

219

463

155

255

355

155

190

219

255

355

463Finished when at the end of each list

Page 35: What makes a good language

Sorting by Merging

• Key idea It’s easy to merge 2 sorted lists

• Sort larger lists by – Sorting smaller lists– Merging the results

• How do we sort smaller lists?

Page 36: What makes a good language

Sort then merge

157

227

345

134

157

227

345

134

Subdivide

Page 37: What makes a good language

Sort then merge

157

227

345

134

157

227

345

134

157

227

134

345

Subdivide Sort piecesBy merging

Page 38: What makes a good language

Sort then merge

157

227

345

134

157

227

345

134

157

227

134

345

134

157

227

345

Subdivide Sort pieces Merge

Page 39: What makes a good language

SortMerge algorithm

Function SortMerge(x,1,n) -- sort list of n elements xIf n = 1 then

Return -- nothing to sortEnd ifMid = (1+ n)/2 -- midpoint of listSortMerge(x,1, Mid ) -- sort first half of listSortMerge(x, Mid +1, n) -- sort second half of

listMerge(x,1, Mid , Mid +1, n) -- merge sorted halves

End Function

Page 40: What makes a good language

Does it work?

• Have to be careful about stopping

• There are always a lot of things going on

Sort(n) Sort(n/2)

Sort(n/2)

Merge

Sort(n/4)

Sort(n/4)

Merge

Sort(n/2)

Merge

Sort(n/8)

Sort(n/8)

Merge

Sort(n/4)

Merge

Sort(n/2)

Merge

Page 41: What makes a good language

Divide and conquer

• Use recursion– reduce solving for problem of size n to solving

two problems of size n/2 – then combine the solutions

• S(n) = 2 S(n/2) + M(n/2,n/2)

• Solving a sorting problem of size n requires solving 2 sorting problems of size n/2 and doing a merge of 2 sets of size n/2

Page 42: What makes a good language

Comparing running times

N Insertion (ms) SortMerge(ms)

100 1 0

200 2 0

1000 58 1

10,000 5841 11

100,000 626943 162

1,000,000 70626916 3421

Page 43: What makes a good language

Comparing running times

N Insertion (ms) SortMerge(ms)

100 1 0

200 2 0

1000 58 1

10,000 5841 11

100,000 626943 162

1,000,000 70626916 3421

Reducing 20 hours to 3 seconds

Page 44: What makes a good language

Searching

• Once a list is in alphabetical order, how do you find things in it?

• For example, is COS 111 on the list of courses that satisfy the (EC) Epistemology and Cognition requirement?

Page 45: What makes a good language

EC coursesPHI 201

PHI 204

PHI 301

PHI 304

PHI 312

PHI 321

PHI 333

PHI 338

PSY 255

PSY 306

PSY 307

PSY 316

AAS 391

ANT 201

COS 302

FRS 135

FRS 137

GER 306

HUM 365

LIN 213

LIN 302

LIN 306

LIN 315

PHI 200

Page 46: What makes a good language

Searching for COS 111

Compare to the middle

AAS 391

ANT 201

COS 302

FRS 135

FRS 137

GER 306

HUM 365

LIN 213

LIN 302

LIN 306

LIN 315

PHI 200

PHI 201

PHI 204

PHI 301

PHI 304

PHI 312

PHI 321

PHI 333

PHI 338

PSY 255

PSY 306

PSY 307

PSY 316 COS 111

Page 47: What makes a good language

Searching

Compare to the middle

If smaller search first half

If larger search second half

AAS 391

ANT 201

COS 302

FRS 135

FRS 137

GER 306

HUM 365

LIN 213

LIN 302

LIN 306

LIN 315

PHI 200

PHI 201

PHI 204

PHI 301

PHI 304

PHI 312

PHI 321

PHI 333

PHI 338

PSY 255

PSY 306

PSY 307

PSY 316 COS 111

Page 48: What makes a good language

Repeat

Compare to the middle

If smaller search first half

If larger search second half

AAS 391

ANT 201

COS 302

FRS 135

FRS 137

GER 306

HUM 365

LIN 213

LIN 302

LIN 306

LIN 315

PHI 200 COS 111

Page 49: What makes a good language

Building indicesPHI 201

PHI 204

PHI 301

PHI 304

PHI 312

PHI 321

PHI 333

PHI 338

PSY 255

PSY 306

PSY 307

PSY 316

AAS 391

ANT 201

COS 302

FRS 135

FRS 137

GER 306

HUM 365

LIN 213

LIN 302

LIN 306

LIN 315

PHI 200

AAS

ANT

COS

FRS

GER

HUM

LIN

PHI

PSY

Page 50: What makes a good language

Search indices then dataPHI 201

PHI 204

PHI 301

PHI 304

PHI 312

PHI 321

PHI 333

PHI 338

PSY 255

PSY 306

PSY 307

PSY 316

AAS 391

ANT 201

COS 302

FRS 135

FRS 137

GER 306

HUM 365

LIN 213

LIN 302

LIN 306

LIN 315

PHI 200

AAS

ANT

COS

FRS

GER

HUM

LIN

PHI

PSY

COS 111