110 likes | 311 Views
Chapter 6: While you were Coding. Presented by: Ben Palermo Nathan O’Grady. Programming by Coincidence . How to Program by Coincidence Accidents of Implementation It may just look like its working The boundary conditions may be an accident
E N D
Chapter 6: While you were Coding Presented by: Ben Palermo Nathan O’Grady
Programming by Coincidence • How to Program by Coincidence • Accidents of Implementation • It may just look like its working • The boundary conditions may be an accident • Behavior may change with the next library release • Superfluous code makes execution time longer • Extra calls increases the chances of new bugs • Accidents of Context • Implicit Assumptions
How to program deliberately • Be aware of what you are doing • Understand the project and the language • Use a plan • Only rely on what you know for sure • If you must assume, document it • Test your assumptions, as well as your code • Spend time on the important things • Do not be afraid to rewrite existing code
Algorithm Speed • O() notation • Estimation • Simple Loops • Nested Loops • Binary Chop • Divide and Conquer • Combinatoric • Algorithm speed in practice
Refactoring • What is refactoring? • When to refactor • When two units perform the same action • Non-orthogonal design • New requirements or a better understanding of the problem • Improving performance
Refactoring • Complications • Pressure to release a product • Refactor early, refactor often
Refactoring • How to refactor • Refactoring is redesign • Don’t refactor and add functionality • Establish good tests before refactoring • Make small, deliberate changes • Test after each change • Let refactoring changes break old builds
Testing Code • Unit Testing • Testing done on individual modules in isolation to each other • Creates artificial environment, then tests output based on known values
Testing Code • Using contracts • Design unit tests to check that a contract is fulfilled • Test modules in a bottom-up approach • Design code to be tested (i.e. design with contracts in mind)
Testing Code • Writing Unit Tests • Include in main source code • As a separate, normally unused function • Use test harnesses • JUnit test cases • Composable tests • Include a debugging window in final build • Culture of Testing
Evil Wizards • Don’t use wizard code you don’t understand. • Be able to write wizard code without the wizard.