Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay...
-
Upload
curtis-holmes -
Category
Documents
-
view
213 -
download
0
Transcript of Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay...
![Page 1: Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.](https://reader036.fdocuments.us/reader036/viewer/2022082820/56649e505503460f94b476f6/html5/thumbnails/1.jpg)
Coding Methodology
How to Design Code
![Page 2: Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.](https://reader036.fdocuments.us/reader036/viewer/2022082820/56649e505503460f94b476f6/html5/thumbnails/2.jpg)
©2005
MIT-Africa Internet Technology Initiative
Pay Attention to Detail
• When implementing or using APIs details are everything.
• Spelling and capitalization.
• Names.
• Argument types.
• Return type.
![Page 3: Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.](https://reader036.fdocuments.us/reader036/viewer/2022082820/56649e505503460f94b476f6/html5/thumbnails/3.jpg)
©2005
MIT-Africa Internet Technology Initiative
Create a Skeleton
• Type in method signatures with empty bodies:– public static void foo() { }
• For methods with primitive return types, declare a dummy variable or return 0:– private int bar(int x) { int i; return i; }– double deuce() { return 0.0; }
• For Object return types, return null:– public String toString() { return null; }
![Page 4: Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.](https://reader036.fdocuments.us/reader036/viewer/2022082820/56649e505503460f94b476f6/html5/thumbnails/4.jpg)
©2005
MIT-Africa Internet Technology Initiative
Write Test Code
• Write test code that makes calls to your skeleton.
• You’ll expect null or zero values and can’t call anything on the returned objects.
• Start out with really basic tests, like instantiating an object.
• Add new tests as you fill in your skeleton.
![Page 5: Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.](https://reader036.fdocuments.us/reader036/viewer/2022082820/56649e505503460f94b476f6/html5/thumbnails/5.jpg)
©2005
MIT-Africa Internet Technology Initiative
Types of Bugs
• Compile time bugs: typos and syntax.
• Logic or control bugs: Correct syntax, but incorrect design. Compiles, but code does not work as expected.
• Runtime bugs: Bugs that arise from data provided at runtime.– Bad input, divide by zero, null pointers. – Can be handled with Exceptions.– Or can cause program to crash.
![Page 6: Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.](https://reader036.fdocuments.us/reader036/viewer/2022082820/56649e505503460f94b476f6/html5/thumbnails/6.jpg)
©2005
MIT-Africa Internet Technology Initiative
Add Debugging Output
• Put in a lot of println() statements that output values of variables for yourself.
• Can add messages like “Entering method foo” or “Exiting Method NNN”.
• Can also add debugging messages that help you trace program flow through control structures.
• Java 1.4 has java.util.logging package that helps with debugging output.
![Page 7: Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.](https://reader036.fdocuments.us/reader036/viewer/2022082820/56649e505503460f94b476f6/html5/thumbnails/7.jpg)
©2005
MIT-Africa Internet Technology Initiative
Code, Compile, Repeat
• Add some code to a skeleton method.
• Write test code to check the new code.
• Compile your code.
• Run it.
• Check for correct debugging output.
• Repeat.
![Page 8: Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.](https://reader036.fdocuments.us/reader036/viewer/2022082820/56649e505503460f94b476f6/html5/thumbnails/8.jpg)
©2005
MIT-Africa Internet Technology Initiative
Philosophies
• Extreme Programming (XP):– Design test cases first, always test.– Implement incrementally.– Design organically (hack).– Expect to write the same code twice.– Code in pairs: Typist and shoulder-surfer.
• Old School:– Design everything on paper.– Rigid implementation plan.– Testing and QA is last step.
![Page 9: Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.](https://reader036.fdocuments.us/reader036/viewer/2022082820/56649e505503460f94b476f6/html5/thumbnails/9.jpg)
©2005
MIT-Africa Internet Technology Initiative
“Debug a Blank Sheet of Paper”- Dr. Brian Harvey
UC Berkeley