L15cs2110fa08 - Designing, Coding, and Documenting Lecture...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Designing, Coding, and Documenting Lecture 15 CS2110 Fall 2008 2 Announcements A4 is up, due Sunday November 9 more difficult than the previous assignments more code distributed client/server app lots of concurrency 3 Quiz 2 What value is printed? class Foo { String s; Foo(String t) { s = "Happy " + t; } public String toString() { return s; } } class Bar extends Foo { Bar(String r) { super("New " + r); } } System.out.println(new Bar("Year!")); 3 Quiz 2 What value is printed? class Foo { String s; Foo(String t) { s = "Happy " + t; } public String toString() { return s; } } class Bar extends Foo { Bar(String r) { super("New " + r); } } System.out.println(new Bar("Year!")); r: "Year!" 3 Quiz 2 What value is printed? class Foo { String s; Foo(String t) { s = "Happy " + t; } public String toString() { return s; } } class Bar extends Foo { Bar(String r) { super("New " + r); } } System.out.println(new Bar("Year!")); r: "Year!" super("New Year!") 3 Quiz 2 What value is printed? class Foo { String s; Foo(String t) { s = "Happy " + t; } public String toString() { return s; } } class Bar extends Foo { Bar(String r) { super("New " + r); } } System.out.println(new Bar("Year!")); r: "Year!" super("New Year!") t: "New Year!" 3 Quiz 2 What value is printed? class Foo { String s; Foo(String t) { s = "Happy " + t; } public String toString() { return s; } } class Bar extends Foo { Bar(String r) { super("New " + r); } } System.out.println(new Bar("Year!")); r: "Year!" super("New Year!") t: "New Year!" s: "Happy New Year!" 4 Designing and Writing a Program Don't sit down at the terminal immediately and start hacking Design stage THINK first about the data you are working with about the operations you will perform on it about data structures you will use to represent it about how to structure all the parts of your program so as to achieve abstraction and encapsulation Coding stage code in small bits test as you go understand preconditions and postconditions insert sanity checks (assert statements in Java are good) worry about corner cases Use Java API to advantage 5 The Design-Code-Debug Cycle Design is faster than debugging (and more fun) extra time spent designing reduces coding and debugging Which is better? Actually, should be more like this: design code debug design code debug 6 Divide and Conquer! Break program into manageable parts that can be implemented, tested in isolation Define interfaces for parts to talk to each other develop contracts (preconditions, postconditions) Make sure contracts are obeyed Clients use interfaces correctly Implementers implement interfaces correctly (test!) Key: good interface documentation 7 Pair Programming Work in pairs Pilot/copilot pilot codes, copilot watches and makes suggestions pilot must convince copilot that code works take turns Or: work independently on different parts after...
View Full Document

This note was uploaded on 02/01/2010 for the course CS 2110 at Cornell University (Engineering School).

Page1 / 47

L15cs2110fa08 - Designing, Coding, and Documenting Lecture...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online