13-SoftwareDesignIII

13-SoftwareDesignIII - Designing and Writing a Program...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
6/15/2011 1 CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2011 Thorsten Joachims Lecture 13: Designing, Coding, and Documenting 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 2 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: 3 design code debug design code debug 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 4 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 5 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. 6
Image of page 1

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

View Full Document Right Arrow Icon
6/15/2011 2 Javadoc An important Java documentation tool Extracts documentation from classes, interfaces Requires properly formatted comments Produces browsable, hyperlinked HTML web pages 7 Java source code (many files) Linked HTML web pages javadoc 8 How Javadoc is Produced /** * Constructs an empty <tt>HashMap</tt> with the specified initial * capacity and the default load factor (0.75). * * @param initialCapacity the initial capacity.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern