CS 448 Lecture - coding/debugging
Topics for today:
- "Any system that will make the same mistake forever is not intelligent".
JHHolland
- Programming
- Threads
- Foo extends Thread
- public void run()... while(true)... the Thread exists until run exits
- Foo myFoo = new Foo();... myFoo.start() (spawns a Thread and sends it run())... myFoo.join(); suspends until myFoo ends...
- Similarly: repaint() schedules update(Graphics) in 100 msecs... if no other repaint() happens before that, it happens
- Image buffering
- Create an image (Components know how)
- Get it's graphics context (Graphics offScreenG = theImage.getGraphics())
- When painting it, paint to offScreenG
- Then, after all the painting is done, drawImage(theImage)
- Debugging - part of the skill of programming is having faith you can find any bug (eventually)
- Analysis ; if that works, done, else
- add diagnostic output; if that shows the problem, done, else
- use the debugger... breakpoints, stepping, stacktrace, values of variables
- create the problem in a simpler context...
- write test code
- formulate hypotheses and test them (when all else fails use the scientific method!)
- Compared to what?
- Different ways to compare: best value, average value, best individual in: CPU-time/generations/evaluations
- random (or enumeration)
- mutation only
- bit-climbing
- Fitness functions