1 / 25

Read me that page, Daddy! -Shoshanna Hertz

Read me that page, Daddy! -Shoshanna Hertz. CSC 313 – Advanced Programming Topics. Lecture 4: Communication. Strategy Pattern Review. Define interface for family of algorithms Signature creates data used by entire family Make each Strategy interchangeable

lonna
Télécharger la présentation

Read me that page, Daddy! -Shoshanna Hertz

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Read me that page, Daddy! -Shoshanna Hertz

  2. CSC 313 – Advanced Programming Topics Lecture 4:Communication

  3. Strategy Pattern Review • Define interface for family of algorithms • Signature creates data used by entire family • Make each Strategy interchangeable • Encapsulate one in its own class • Separate Strategy from its Context • Can change Strategy used dynamically • Add new Strategies without modifying code • Can also reuse Strategy in new environments

  4. public interface Greeter {public void greet(String name); } public class Formal implements Greeter {public void greet(String name) {System.out.println(“Hello ” + name);} } public class Informal implements Greeter {public void greet(String name) {System.out.println(“Hiya ” + name);} } public class French implements Greeter {public void greet(String name) {System.out.println(“Bonjour ” + name);} }

  5. public interface Greeter {public void greet(String name); } public abstract class Interpersonal {protected Greeter g; } public class Worker extends Interpersonal {private String person;public void greet() { g.greet(person); } } public class DrHertz extends Interpersonal {public void greet() { g.greet(“Bob”); } } public class Flanders extends Interpersonal {private String person; public void greet() { g.greet(person + “doodly”);} }

  6. Shared Vocabulary Necessary

  7. Shared Vocabulary Necessary

  8. Shared Vocabulary Necessary • Hints: Wise Creative Humorous Attractive Impatient Lazy Full of hubris Person assigning grades

  9. Shared Vocabulary Necessary • Hints: Tool Useless Waste of Time Former TRL Host Dr. Hertz’s odd fascination

  10. Shared Vocab. Not Sufficient

  11. Not a Free Gift • Design patterns are useful… • Provide usable design solutions • Enable shared vocabulary • … but are not panacea • Do not prevent complex designs • Cannot eliminate bugs • Are not “gift” in the box

  12. Brevity is the soul of wit The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague. Edsger Dijkstra

  13. Spot the Bug public boolean isPrime(int n) {for (int i = 2; i < n; i++) { if ((n % i) == 0) { return false; }}return true; } public boolean isPrime(int n) {for (int i = 1; i < n; i++) { if ((n % i) == 0) { return false; }}return true; }

  14. } catch (IOException ioe) { if ( n == 0 ) { spec.harness.Context.out.println("Empty database"); return; } spec.harness.Context.out.println("ERROR opening/reading input file \""+filename+"\""); // System.exit(1); }; entry = new Entry(); spec.harness.Context.out.print("OK\nBuilding database ..."); spec.harness.Context.out.flush(); n = buffer.length; s = e = 0; while ( (e < n) && (s < n) ) { // Check for CR also - rrh 2/18/98 while ( (e < n) && (buffer[e] != '\n') && (buffer[e] != '\r') ) e++; if ( e < n ) { if ( buffer[s] == '#' ) { add(entry); entry = new Entry(); } else entry.items.addElement(new String(buffer, 0, s, e-s)); // Discard CR & LF - rrh 2/18/98 … Spot the Bug public void read_db(String filename) { Entry entry; int i; int n = 0, act = 0, e, s; boolean OK; byte buffer[] = null; spec.harness.Context.out.print("Reading database "+dbname+" ... "); spec.harness.Context.out.flush(); try { spec.io.FileInputStream sif = new spec.io.FileInputStream(filename); n = sif.getContentLength(); buffer = new byte[n]; int bytes_read; while ( (bytes_read = sif.read(buffer, act , (n - act))) > 0){ act = act + bytes_read; } sif.close(); sif = null; // 03/11/98 rrh if ( act != n ){ spec.harness.Context.out.println("ERROR reading input file"); //System.exit(1); return; }

  15. Brevity is the soul of wit Complexity kills. It sucks the life out of developers, it makes products difficult to plan, build and test, it introduces security challenges and it causes end-user and administrator frustration. Ray Ozzie

  16. Elevator Talk • Big name in field (or company VP) gets in your elevator asks, “What are you working on?” • You duration of elevator ride to explain it all • Need to impress, but not BS • Boss comes by and asks, “How is it going?” • Does not care/have time to get into details • Have 90 seconds to get out important issues

  17. Why Does This Matter?

  18. This Does Matter • Need to market your ideas and designs • Requires explaining to lazy, impatient coders • Get bored well before 90 seconds are up • If cannot explain design in elevator talk • Code created from design will have bugs • Will require major effort to get to work • IT IS TOO COMPLEX

  19. More Marketing • This also matters for documentation • Bad versus good documentation

  20. More Marketing • Documentation must be brief • Provides only necessary details • Details “needed” only to get user coding Before software can be reusable it first has to be usable. -- Ralph Johnson An API that isn't comprehensible isn't usable. -- James Gosling

  21. Which Line Is Yours?

  22. Why Comments are Useful If the code and the comments disagree, then both are probably wrong. Norm Schryer

  23. Why Comments are Useful As you're about to add a comment, ask yourself, 'How can I improve the code so that this comment isn't needed?' Improve the code and then document it to make it even clearer. Steve McConnell

  24. …and finally For every complex problem there is an answer that is clear, simple, and wrong. -- H L Mencken Computers are useless. They can only give you answers. -- Pablo Picasso

  25. For Next Lecture • Two (short) readings available on web • Will start looking into how code is optimized • Begin by investigating how programs actually run • Also look at some of the simplest optimizations • Important to understand to improve code written • There is lab assignment this week • Posted to web/Angel • Will be due before lab in two weeks

More Related