L15cs2110fa08-6up

L15cs2110fa08-6up - Designing Coding and Documenting...

Info iconThis preview shows pages 1–3. 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
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!")); 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 deciding on an interface " frequent design review " each programmer must convince the other " reduces debugging time ! Test everything 8 Documentation is Code ! Comments (esp. specifications) are as important as the code itself " determine successful use of code " determine whether code can be maintained " creation/maintenance = 1/10 ! Documentation belongs in code or as close as possible " Code evolves, documentation drifts away " Put specs in comments next to code when possible " Separate documentation? Code should link to it. ! Avoid useless comments " x = x + 1; //add one to x-- Yuck! " Need to document algorithm? Write a paragraph at the top. " Or break method into smaller, clearer pieces. 9 Javadoc ! An important Java documentation tool ! Extracts documentation from classes, interfaces " Requires properly formatted comments ! Produces browsable, hyperlinked HTML web pages Java source code (many files) Linked HTML web pages javadoc 10 11 /** * Constructs an empty <tt>HashMap</tt> with the specified initial * capacity and the default load factor (0.75).* capacity and the default load factor (0....
View Full Document

This note was uploaded on 02/01/2010 for the course CS 2110 at Cornell.

Page1 / 7

L15cs2110fa08-6up - Designing Coding and Documenting...

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

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