Effective Programming

Slides:



Advertisements
Similar presentations
Debugging Introduction to Computing Science and Programming I.
Advertisements

Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
13-Jul-15 Effective Programming. “The new US stealth fighter, the F-22 Raptor, was deployed for the first time to Asia earlier this month. On Feb. 11,
19-Aug-15 JUnit tests for output. Capturing output System.out.print and System.out.println usually “print” to the screen, but you can change that OutputStream.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
As you arrive… Get you laptop out and get ready to program some python Go to the course website and load all the example programs that are posted there.
Testing in Extreme Programming
Testing Michael Ernst CSE 140 University of Washington.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Ethics of Software Testing Thomas LaToza CS 210 Final Presentation 12 / 2 / 2002.
Debugging Strategies from Software Carpentry. Agan's Rules Many people make debugging harder than it needs to be by: Using inadequate tools Not going.
CS5103 Software Engineering Lecture 02 More on Software Process Models.
Testing CSE 160 University of Washington 1. Testing Programming to analyze data is powerful It’s useless (or worse!) if the results are not correct Correctness.
Welcome to Software Project Management. CONVENTIONAL SOFTWARE MANAGEMENT The BEST and WORST thing about software is its flexibility. 1.Software development.
Has Brian Kernighan’s thoughts on prototype vs. production programming.
29-Jun-16 Effective Programming. “The new US stealth fighter, the F-22 Raptor, was deployed for the first time to Asia earlier this month. On Feb. 11.
The goal here is to qualify the lead and turn it into a prospect A lead at this level is merely contact details We need to determine if the lead:  Has.
Code Simplicity: Software Design In Open Source Projects Max Kanat-Alexander
CSC 108H: Introduction to Computer Programming
Error Analysis Logic Errors.
Brussels Privacy Symposium on Identifiability
Lecture #8 Thursday, September 15, 2016 Textbook: Section 4.4
Steve Chenoweth Office Phone: (812) Cell: (937)
Mobile Testing - Bug Report
Chapter 3: Describing Relationships
Debugging Intermittent Issues
Testing and Debugging PPT By :Dr. R. Mall.
C++ coding standard suggestion… Separate reasoning from action, in every block. Hi, this talk is to suggest a rule (or guideline) to simplify C++ code.
Program Input/Output (I/O)
1. Welcome to Software Construction
Top Reasons Why Developers Choose Microsoft Access By:
Testing UW CSE 160 Winter 2017.
Debugging Intermittent Issues
Software engineering – 1
Whether you decide to use hidden frames or XMLHttp, there are several things you'll need to consider when building an Ajax application. Expanding the role.
Application Development Theory
Offline Analysis Framework STATUS
Start Small and Retire Early With Weekly Options
Information Systems Development
Testing UW CSE 160 Spring 2018.
Exceptions 10-Nov-18.
Refactoring and Code Smells
Objects First with Java
Number and String Operations
Testing UW CSE 160 Winter 2016.
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
Testing and debugging A short interlude 2-Dec-18.
COMP 208/214/215/216 Lecture 3 Planning.
OSU Payroll Services Overpayments Hello. Introduce everyone and the topic for today’s discussion. 12/4/2018 OSU Payroll Services
Effective Programming
Using a Debugger 1-Jan-19.
4. Computational Problem Solving
Introduction When searching for a new mattress, you have to make sure you know where to go to find the best one. The mattress you sleep on is going to.
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Topic 1: Problem Solving
Exceptions 19-Feb-19.
A Way to Get the Best Computer Repair Service Centre.
CS 240 – Advanced Programming Concepts
Operating Systems 1: News
ECE 352 Digital System Fundamentals
Testing and debugging A short interlude 17-Apr-19.
YOUR FUTURE AND INFORMATION TECHNOLOGY
Java & Testing.
Exceptions 10-May-19.
Test Cases, Test Suites and Test Case management systems
“How to Study and Critique a Speech”
Refactoring Low Level/High Level.
#1. LIKE YOURSELF The first self improvement tip is learning to love yourself. Unfortunately for many, this is easier said than done. You have to learn.
How to Successfully Peer Review
Presentation transcript:

Effective Programming 15-Jan-19

Why test? “The new US stealth fighter, the F-22 Raptor, was deployed for the first time to Asia earlier this month. On Feb. 11 [2007], twelve Raptors flying from Hawaii to Japan were forced to turn back when a software glitch crashed all of the F-22s’ on-board computers as they crossed the international date line...every fighter completely lost all navigation and communications when they crossed the international date line. They reportedly had to turn around and follow their tankers by visual contact back to Hawaii...if they had not been with their tankers, or the weather had been bad, this would have been serious.” http://slashdot.org/index.pl?issue=20070225

Program design “In preparing for battle I have always found that plans are useless, but planning is indispensable.” --Dwight D. Eisenhower The same is true in programming You must plan out your program in advance, so you know where you are trying to go--but expect many changes along the way Don’t just jump into coding with the first approach that occurs to you, but consider alternate plans Always be ready to refactor as needed “How far you can go without destroying from within what you are trying to defend from without?” --Dwight D. Eisenhower Actually, I don’t think this quote has any relevance to programming

Why refactor? Refactoring: Making changes to your program that don’t affect what the program does Some refactorings: The name of a method no longer accurately describes what it does, so you want to rename it You need more control over what a method does, so you want to add a parameter You need to use only part of what a method does, so you extract that part into a separate method You realize that a method is in the wrong class, so you move it to a different class Eclipse makes these and other refactorings relatively “safe”--that is, they are unlikely to break your program Not all refactorings are as easy

Regression testing Regression testing: Testing whether the program still works, after you have made a change to it JUnit tests are extremely useful for regression testing A thorough set of tests gives you the confidence to refactor Debugging is dangerous--fixing a bug is very likely to introduce new bugs It is a general rule that the difficulty of debugging a program goes up as the square of the program size

Programming discipline To write impressively good programs, here are some rules to follow Plan ahead--consider more than one design before you start programming Refactor early and often Test everything you can as thoroughly as you can--don’t let the code get out of control Writing tests before you write the code isn’t the only way to program, but it improves your program design as well as your code Start with “the simplest thing that could possibly work” Insofar as possible, make only small changes to your program Don’t add features until the code you already have is “completely” debugged It takes discipline to follow these rules--it’s easier to just jump in and start writing code--but a methodical approach greatly increases your chance of success

Dealing with I/O We can (in some cases) test our output methods PrintStream originalOut = System.out; OutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps); We can even test our input methods InputStream originalIn = System.in; byte[] buf = "Some input string".getBytes(); InputStream is = new ByteArrayInputStream(buf); System.setIn(is);

Dealing with GUIs GUIs are not easy to test with JUnit-like software There are programs that attempt to provide automatic JUnit tests for GUIs, but I haven’t found any I like If you want to write a GUI testing framework, you should explore java.awt.Robot There is a reasonably good, albeit not perfect, solution to the problem of testing GUIs... Don’t do any work in the GUI class! Use the MVC (Model-View-Controller) approach The GUI should only communicate between the user and the model Of course, this is easier said than done, but still.... Even if a GUI “works,” that doesn’t make it easy to use Of course you think your GUI is obvious You should always have at least one other person try it out without help from you--you will probably be surprised at the result

Creeping featurism “Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” --Antoine de Saint-Exupery In my opinion, the highest praise you can give to a program is to say “it just works” Unfortunately, most software competes on the basis of how many features it offers Sometimes you need those features When you don’t need them, you are better off without them

The End The original study that showed huge variations in individual programming productivity was conducted in the late 1960s by Sackman, Erikson, and Grant (1968). They studied professional programmers with an average of 7 years’ experience and found that the ratio of intitial coding time between the best and worst programmers was about 20:1; the ratio of debugging times over 25:1; of program sizes 5:1; and of program execution speed about 10:1. They found no relationship between a programmer’s amount of experience and code quality or productivity. -- Code Complete, page 548