About the required reading. Construction: High quality code for programming in the large. What is high quality code?

Similar documents
Construction: High quality code for programming in the large

the gamedesigninitiative at cornell university Lecture 13 Architecture Design

the gamedesigninitiative at cornell university Lecture 12 Architecture Design

Northeastern University - Seattle. Computer and Information Sciences

Review sheet for Final Exam (List of objectives for this course)

6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5.

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

Write for your audience

Documentation (and midterm review)

An Example. Unified Modelling Language - 2 ITNP090 - Object Oriented Software Design. Class diagram. Class diagram. Dr Andrea Bracciali

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics

CS 251 Intermediate Programming Methods and Classes

The compiler is spewing error messages.

CS 251 Intermediate Programming Methods and More

Our second exam is Thursday, November 10. Note that it will not be possible to get all the homework submissions graded before the exam.

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

CS Exam 1 Review Suggestions

Core Java Syllabus. Pre-requisite / Target Audience: C language skills (Good to Have)

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

CSE wi Final Exam 3/12/18. Name UW ID#

Human-Computer Interaction IS4300

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation

COMP 401 Fall Recitation 7: Factories and Lists

Inf1-OOP. OOP Exam Review. Perdita Stevens, adapting earlier version by Ewan Klein. March 16, School of Informatics

Introduction to Programming

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

A few more things about Agile and SE. Could help in interviews, but don t try to bluff your way through

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Lecture 5: Implementing Lists, Version 1

Object-Oriented Programming Classes, Objects, Variables

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

1 Getting used to Python

CSE 70 Final Exam Fall 2009

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Tips from the experts: How to waste a lot of time on this assignment

Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page:

Tips from the experts: How to waste a lot of time on this assignment

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage)

This assignment requires that you complete the following tasks (in no particular order).

Text Input and Conditionals

Object-Oriented Software Engineering. Chapter 2: Review of Object Orientation

CS1 Lecture 5 Jan. 26, 2018

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages

This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units.

Understanding and Exploring Memory Hierarchies

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Comp215: Thinking Generically

CSCU9T4: Managing Information

CS Problem Solving and Object-Oriented Programming

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

CS 11 java track: lecture 3

CISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters.

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

CPS221 Lecture: Threads

QUIZ. How could we disable the automatic creation of copyconstructors

CS112 Lecture: Defining Instantiable Classes

Initial Coding Guidelines

Laboratory 1: Eclipse and Karel the Robot

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

Javadoc. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 7

Tuesday, November 15. Testing

Quality Assurance User Interface Modeling

Soda Machine Laboratory

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

CS2112 Fall Assignment 4 Parsing and Fault Injection. Due: March 18, 2014 Overview draft due: March 14, 2014

CS121/IS223. Object Reference Variables. Dr Olly Gotel

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

CALCULUS LABORATORY ACTIVITY: Numerical Integration, Part 1

Lecture (06) Java Forms

CSE 331 Software Design & Implementation

Programming Principles 1 (CSC131) & 2 (CSC132) Software usage guide

The first program: Little Crab

QUIZ. How could we disable the automatic creation of copyconstructors

16. Linked Structures and Miscellaneous

Java/RealJ Troubleshooting Guide

Mock Objects and the Mockito Testing Framework Carl Veazey CSCI Friday, March 23, 12

The Dynamic Typing Interlude

Chapter 1 Getting Started

APCS Semester #1 Final Exam Practice Problems

Example Program. public class ComputeArea {

Chapter 5 Errors. Bjarne Stroustrup

Exceptions. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1.

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

Our second exam is Monday, April 3. Note that it will not be possible to get all the homework submissions graded before the exam.

CS 251 Intermediate Programming Java Basics

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

CSE 331 Final Exam 12/9/13

CPS122 Lecture: Defining a Class

Software Design Models, Tools & Processes. Lecture 6: Transition Phase Cecilia Mascolo

Objectives: 1. Introduce the course. 2. Define programming 3. Introduce fundamental concepts of OO: object, class

Getting Started (1.8.7) 9/2/2009

Mathematics/Science Department Kirkwood Community College. Course Syllabus. Computer Science CSC142 1/10

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO

Transcription:

About the required reading All the reading described as required is examinable. For example, you should be able to: briefly explain concepts like process requirement, stakeholder, tacit knowledge, conceptual modelling, requirements allocation, traceability constructively criticise a written requirement suggest several ways to elicit requirements from stakeholders Use common sense: I will not ask which parts of SWEBOK04 come from [Dav93] or in which Knowledge Area is... discussed. Try to notice when different sources use terms somewhat differently: main example here is system requirement. Exam questions will disambiguate as necessary! Construction: High quality code for programming in the large Nigel Goddard School of Informatics University of Edinburgh What is high quality code? What has this to do with programming in the large? High quality code does what it is supposed to do...... and will not have to be thrown away when that changes. Obviously intimately connected with requirement engineering and design: but today let s concentrate on the code itself. Why is the quality of code more important on a large project than on a small one? Fundamentally because other people will have to read and modify your code even you in a year s time count as other people! E.g., because of staff movement for code reviews for debugging following testing for maintenance (Exercise. Dig out your early Java exercises from Inf1. Criticise your code. Rewrite it better without changing functionality.)

How to write good code Follow your organisation s coding standards - placement of curly brackets, indenting, variable and method naming... Coding standard example Suppose you are used to... public Double getvolumeasmicrolitres() { if (m_volumetype.equals(volumetype.millilitres)) return m_volume * 1000; return m_volume;... and you see public Double getvolumeasmicrolitres() { if(m_volumetype.equals( VolumeType.Millilitres)) { return m_volume*1000; return m_volume; Even worse: mixed styles in one file - inevitable without standards! How to write good code Follow your organisation s coding standards - placement of curly brackets, indenting, variable and method naming... Use meaningful names (for variables, methods, classes...) If they become out of date, change them. Avoid cryptic comments. Try to make your code so clear that it doesn t need comments. Balance structural complexity against code duplication: don t write the same two lines 5 times (why not?) when an easy refactoring would let you write them once, but equally, don t tie the code in knots to avoid writing something twice. Be clever, but not too clever (recursion!). Remember the next person to modify the code may be less clever than you! Don t use deprecated, obscure or unstable language features unless absolutely necessary. Remove dead code, unneeded package includes, etc. Clicker: Which of these fragments is better? 1. for(double countery = -8; y < 8; countery+=0.5){ x = counterx; y = countery; r = 0.33 - Math.sqrt(x*x + y*y)/33; r += sinanim/8; g.fillcircle( x, y, r ); 2. for(double countery = -8; y < 8; countery+=0.5){ x = counterx; y = countery; r = 0.33 - Math.sqrt(x*x + y*y)/33; r += sinanim/8; g.fillcircle( x, y, r ); 3. They are both fine.

Clicker: Which of these fragments is better? What else is wrong with this? 1. c.add(o); 2. customer.add(order); 3. They are both fine. r = 0.33 - Math.sqrt(x*x + y*y)/33; r += sinanim/8; g.fillcircle( x, y, r ); Use comments when they re useful and not when they re not if (moveshapemap!=null) { // Need to find the current position. All shapes have // the same source position. Position pos = ((Move)moveShapeSet.toArray()[0]).getSource(); Hashtable legalmovestoshape = (Hashtable)moveShapeMap.get(pos); return (Move)legalMovesToShape.get(moveShapeSet); // if the move shape map is null if (moveshapemap!=null) { Too many comments is actually a more common serious problem than too few. Good code in a modern high-level language shouldn t need many explanatory comments, and they can cause problems. If the code and the comments disagree, both are probably wrong (Anon) But there s another use for comments...

Javadoc Any software project requires documenting the code by which we mean specifying it, not explaining it. Documentation held separately from code tends not to get updated. So use comments as the mechanism for documentation even if the reader won t need to look at the code itself. Javadoc is a tool from Sun. Programmer writes doc comments in particular form, and Javadoc produces pretty-printed hyperlinked documentation. E.g. Java API documentation at java.sun.com. See web page for Required reading tutorial. Javadoc example (from Sun) /** * Returns an Image object that can then be painted on the screen. * The url argument must specify an absolute {@link URL. The name * argument is a specifier that is relative to the url argument. * <p> * This method always returns immediately, whether or not the * image exists. When this applet attempts to draw the image on * the screen, the data will be loaded. The graphics primitives * that draw the image will incrementally paint on the screen. * * @param url an absolute URL giving the base location of the image * @param name the location of the image, relative to the url argument * @return the image at the specified URL * @see Image */ public Image getimage(url url, String name) { try { return getimage(new URL(url, name)); catch (MalformedURLException e) { return null; Rendered Javadoc (Eclipse) The relevance of object orientation Construction is intimately connected to design: it is design considerations that motivate using an OO language. Key need: control complexity and abstract away from detail. This is essential for systems which are large (in any sense). Objects; classes; inheritance; packages all allow us to think about a lot of data at once, without caring about details. Interfaces help us to focus on behaviour. Revise classes, interfaces and inheritance in Java.

A common pattern in Java Example: GUI I interface Foo {... class FooImpl implements Foo {... Exercise: why is this so much used? public class ListenExample extends JFrame implements WindowListe // Example WindowListener method public void windowiconified(windowevent e) { // Handle window minimised events //... Other WindowListener methods Example: single method interface JButton button = new JButton("Example Button"); button.addactionlistener( new ActionListener() { actionperformed(actionevent ae) { Packages Recall that Java has packages. Why, and how do you decide what to put in which package? Packages: are units of encapsulation. By default, attributes and methods are visible to code in the same package. give a way to organize the namespace. allow related pieces of code to be grouped together. ); // Handle the action So they are most useful when several people must work on the same product. But the package hierarchy is not really a hierarchy as far as access restrictions are concerned the relationship between a package and its sub/superpackages is just like any other package-package relationship.

Packages extended example Concretely: In file... eduni/inf/cardgame.java: A class eduni.inf.jcb.mahjong inherits from a class eduni.inf.cardgame. It inherits a protected method deal(). Somewhere in the MahJong class occurs the following code: eduni.inf.cardgame c = new eduni.inf.cardgame(); Will this compile? package eduni.inf; protected void deal() { In file eduni/inf/jcb/mahjong.java: package eduni.inf.jcb; public class MahJong extends eduni.inf.cardgame { eduni.inf.cardgame c = new eduni.inf.cardgame(); Does this compile? And this? In file... eduni/inf/cardgame.java: A Yes, and it would even if we removed protected. B Yes, but it wouldn t if we removed protected. C No, deal() needs to be public because CardGame and MahJong are in different packages. D No, and wouldn t unless we made some other change. package eduni.inf; protected void deal() { In file eduni/inf/jcb/mahjong.java: package eduni.inf.jcb; public class MahJong extends eduni.inf.cardgame { this.deal();

And this? In file... eduni/inf/cardgame.java: package eduni.inf; protected void deal() { In file eduni/inf/jcb/mahjong.java: package eduni.inf.jcb; public class MahJong extends eduni.inf.cardgame { MahJong c = new MahJong(); And this? In file CardGame.java: protected void deal() { In file MahJong.java: public class MahJong extends CardGame { CardGame c = new CardGame(); Suggested lab exercises Reading 1. Revise Inf2B first couple of labs, and remind yourself how to use Eclipse to start a project and import code. 2. Play with the Umlet tool for drawing use case diagrams. Information (and downloads for home use) at http://www.umlet.com. Key points: to create a new diagram, use menu File/New/Other.. then select Umlet/Diagram. Double click on a diagram element to insert it. You have a choice of palette s. 3. Experiment with Java packages (see web). 4. Do the JavaDoc tutorial. Required: something that makes you confident you completely understand Java packages (e.g., see course web page). Required: the JavaDoc tutorial Suggested: Stevens Ch14-4 pages discussing UML s notion of packages. Exercise: compare it with Java s.