–stop: Sets a breakpoint. The debugger will interrupt execution to allow debugging when abreakpoint is hit.

•“stop at Test:24”: breaks at test.java, line 24.

•“stop inTest.testmethod”: breaks whenTest.testmethod

is invoked.

–print: prints out a variable or method’s value.

–step: steps through the program line-by-line.

–cont: continues execution after a breakpoint is hit.

–where: prints a stack trace.

•up: goes one frame up the system stack. (pops)

•down: goes one frame down the system stack if not already at the bottom. (pushes)

–locals: lists all local variables in the current stack frame.

–list: prints the source around the current location.

Version Control

•Your own personal time machine.

•Stores old versions of programs and lets you revert back to them at need.

•Also great for collaboration or if you work on the same documents fromplace to place.

•Every time you make a revision, you can save, or “commit” it to a versioncontrol repository.

•You can later compare further changes to any old version you’ve evercommitted (“diff”) or revert your changes entirely by “updating” to an oldversion.

•If you move to another system with an old copy, you can “update” it to thenewest committed revision as well.

•You can also “check out” the latest update on a new system at any time.

•The most popular systems are Subversion (SVN) and CVS. Using one willmake your task far easier.

Existing Solutions

•You have other sorts of tools, too. These don’t help you code; theyhelp youfind

code.

–Google.

–Koders.

–Krugle.

–PlanetSourceCode.

–SourceForge.

–CPAN (for Perl) and other module repositories.

–Many others…

•Use these when you hit roadblocks: chances are that others havehit them too, and their solutions can help you.

•Also use them to find libraries; try not to waste time doingsomething that has already been done.

–Being able to quickly understand and use these libraries from theirdocumentation is an essential programming skill as well.

What’s the Connection?

•What lets me take metaphors from onelanguage or UI and simply assume they willwork in others?

•Why can some people use programs they hadnever seen before, while others have difficultywith tasks they haven’t memorized?

Intuition.

Intuitive Design

•Good UIs are intuitive.

–They place tasks where users expect to find them (e.g. “Open” is always underthe “File” menu because it’s the first place people will look).

–They utilize the same sorts of shortcuts as other programs.

–Commands are placed according to their function; common functionalities aregrouped.

–Frequently used commands should be easy to access.

•Good languages are intuitive.

–They do what you’d expect them to, andonly

what you’d expect them to.

–Command names hint at their functionality.

–Nothing is “magic”; commands don’t mean different things in different places.

•Goodprograms

are intuitive.

–Variable and function names represent their functions.

–There is a sense of overall structure to the program.

–The pieces are split up in a self-contained way, like a puzzle fitting together.

–It is clear what role each piece plays in solving the problem.

–Nothing is done “by accident”–

every piece of the program serves a purpose.

Problem Solving

•An art: there are no strict rules.

•There are some recurring patterns, though.

•Takes both intelligence and creativity.

–Most people don’t realize it at first, but computer science is a very creative field.

•The algorithm design paradigms are problem solving strategies:

–Divide and Conquer: break the problem down into smaller instances of itself, solve them, andmerge them back together.

–Memoization: store solutions to smaller problems and look them up when needed.

–The Greedy Approach: solve the problem by making the best short-term decision at each step.

–Dynamic Programming: build the solution up from overlapping smaller solutions.

•Also some others we didn’t discuss:

–Hill Climbing: come up with an approximate solution, then gradually improve it.

–Genetic Algorithms: generate many solutions, have them compete, and select the best ones.

•Solutions are often easier to verify than to generate, so this can work well.

•Visualization of the problem can help you solve it.

–Flowcharts, UML, graphs, diagrams… sometimes the key is to just get an image of what thesolution must do into your head.

•Intuition is important here too: go beyond the verbal description of the problemand try to understand what the problem actually is.

Solutions

•Only once you understand the problem can youbegin working on a solution to it.

•In programming, the solution usually involves an“architecture”: some hierarchy of self-containedcomponents which interact to generate asolution.

•Algorithms are recipes for solving problems, sothink of the architecture as a way of enabling youto do complex things like “create a pizza crust”,rather than having to list out each step involvedin creating a crust at once.

Problem: Make a Pizza

•Questions to ask:

–What is a pizza?

•Apielike

food with a crust on the bottom, topped withcheese and tomato sauce.

–What “high-level” ingredients will be required?

•Crust.

•Sauce.

•Cheese.

–How can they interact to create a pizza?

•The crust can be rolled thin, the sauce spread on top ofit, and the cheese added, in that order. The assembledpizza is then baked in a pizza oven for 10 to 15 minutes.

Drill-Down

•What is involved in generating the crust, sauce,and cheese?

–Crust: flour, wheat, water, … must be mixed togenerate a dough.

–Sauce: either created by mashing tomatoes or simplybought ready-made (libraries!)

–Cheese: needs to be shredded before topping on apizza.

•Note that we don’t care about rolling the dough,adding the sauce, or adding the cheese at thislevel. We’ve dealt with that above.

“Pseudocode”

•Once we’ve drilled down to an elementary level, we are ready to construct asolution from our architecture:

Pizzamakepizza() {

//Gather low-level ingredients.

Tomato[] tomatoes = new Tomato[5];

Flour fl =Cabinet.getBagOfFlour();

Cheesech

= new Mozzarella();

//Polymorphism. Mozzarella “ISA” Cheese.

Water w =Sink.pour(4);

//Pour 4 ounces of water.

Crustcr

= Crust.mix(fl, w);

Sauce s =Tomato.mash(tomatoes);

Pizza p = new Pizza(cr, s,ch);

Oven.bake(p, 350, 15);

return p;

}

Now With a Program

•Say you wanted to create a booking system foran airline.

–What components would your program need?

–How would they interact?

–What low-level operations might each componentneed to perform?

–What data must be stored by each?

I have problems.

•This lesson was on problem solving andproblem decomposition, as well as mastery ofyour development environment.

•Specifically, it covered how to solve problemsusing the programming techniques you havebeen learning in this course and elsewhere.

•The lesson:

–Problem solving is often a matter of intuition, inwhich both intelligence and creativity are broughtto bear.