Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Basic -2 Classes and Objects. Classes and Objects A class is a complex data TYPE An object is an instance of a class. Example: Class: Person Objects:
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Exceptions: when things go wrong. Various sources of error public static doSomething() { int i = 3.0; while(!done); { int i = false } ) Syntactic errors.
Yoshi
Telecooperation/RBG Technische Universität Darmstadt Copyrighted material; for TUD student use only Introduction to Computer Science I Topic 16: Exception.
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Written by: Dr. JJ Shepherd
CSE 332: C++ exceptions Overview of C++ Exceptions Normal program control flow is halted –At the point where an exception is thrown The program call stack.
Java Exceptions. Types of exceptions  Checked exceptions: A checked exception is an exception that is typically a user error or a problem that cannot.
1 / 89 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 11 Programming Fundamentals using Java 1.
A Review. a review of lessons learned so far… ( 2 steps forward - 1 step back) Software Development Cycle: design, implement, test, debug, document Large.
1 CS2200 Software Development Lecture: Testing and Design A. O’Riordan, 2008 K. Brown,
Debugging Introduction to Computing Science and Programming I.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Exceptions Three categories of errors: Syntax errors Runtime errors Logic errors Syntax errors: rules of the language have not been followed. Runtime error:
Lecture 4: Objects and Classes Classes Objects Data fields (instance variables) Methods –Instance methods –Static methods –Constructors But first…
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Fall 2007CS 225 Program Correctness and Efficiency Chapter 2.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Exception Handling in Java Course Lecture Slides 7 th July 2010 “ Admitting.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
Class Inheritance UNC-CHAPEL HILL COMP 401 BRIAN CRISTANTE 5 FEBRUARY 2015.
The Java Programming Language
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
Lecture 2: Classes and Objects, using Scanner and String.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
1 Debugging. 2 A Lot of Time is Spent Debugging Programs Debugging. Cyclic process of editing, compiling, and fixing errors. n Always a logical explanation.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 15: More-Advanced Concepts.
Introduction to Exception Handling and Defensive Programming.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Exception Handling Unit-6. Introduction An exception is a problem that arises during the execution of a program. An exception can occur for many different.
ECE122 Feb. 22, Any question on Vehicle sample code?
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CSC Programming I Lecture 6 September 4, 2002.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Methods. Methods also known as functions or procedures. Methods are a way of capturing a sequence of computational steps into a reusable unit. Methods.
CIS 234: Java Methods Dr. Ralph D. Westfall April, 2010.
Static?. Static Not dynamic class Widget { static int s; int d; // dynamic // or instance // variable }
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
Error Handling Tonga Institute of Higher Education.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
Lecture 6: Methods MIT-AITI Kenya © 2005 MIT-Africa Internet Technology Initiative In this lecture, you will learn… What a method is Why we use.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Wrapper Classes Debugging Interlude 1
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Chapter 10 – Exception Handling
Logger, Assert and Invariants
Testing and Debugging.
Static Methods 14-Nov-18.
Tonga Institute of Higher Education
Java Statements B.Ramamurthy CS114A, CS504 4/23/2019 BR.
Lecture 14: Testing Testing used to verify object behavior through designed test suites Can test Classes – “unit” testing Object interactions – “integration”
Presentation transcript:

Coding Methodology How to Design Code

© 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.

© 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; }

© 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.

© 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.

© 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.

© 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.

© 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.

© 2005 MIT-Africa Internet Technology Initiative “Debug a Blank Sheet of Paper” - Dr. Brian Harvey UC Berkeley