25-Jun-15 Managing Complexity Programming is more than just syntax.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Chapter 1: Computer Systems
Written by: Dr. JJ Shepherd
Access to Names Namespaces, Scopes, Access privileges.
Web Security A how to guide on Keeping your Website Safe. By: Robert Black.
15-Jun-15 Beginning Style. 2 Be consistent! Most times, you will enter an ongoing project, with established style rules Follow them even if you don’t.
Sparse arrays.
16-Jun-15 Recognizers. 2 Parsers and recognizers Given a grammar (say, in BNF) and a string, A recognizer will tell whether the string belongs to the.
16-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
19-Jun-15 Access to Names Namespaces, Scopes, Access privileges.
20-Jun-15 Methods. Complexity The programmer's biggest adversary is complexity The programmer's biggest adversary is complexity Primitive types and the.
Outline Java program structure Basic program elements
26-Jun-15 Methods. About methods A method is a named group of declarations and statements If a method is in the same class, you execute those declarations.
26-Jun-15 Methods. About methods A method is a named group of declarations and statements You execute those declarations and statements by calling the.
Grouping Objects 1 Introduction to Collections.
28-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
28-Jun-15 Access to Names Namespaces, Scopes, Access privileges.
28-Jun-15 Recognizers. 2 Parsers and recognizers Given a grammar (say, in BNF) and a string, A recognizer will tell whether the string belongs to the.
29-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
30-Jun-15 Static Methods. About methods A method is a named group of declarations and statements You execute those declarations and statements by calling.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Java. Why Java? It’s the current “hot” language It’s almost entirely object-oriented It has a vast library of predefined objects It’s platform independent.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 3.0.
The Java Programming Language
Errors And How to Handle Them. GIGO There is a saying in computer science: “Garbage in, garbage out.” Is this true, or is it just an excuse for bad programming?
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Examples of Recursion Data Structures in Java with JUnit ©Rick Mercer.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
Refactoring An Automated Tool for the Tiger Language Leslie A Hensley
10-Nov-15 Java Object Oriented Programming What is it?
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
CS100A, Fall 1998 Key Concepts 1 These notes contain short definitions of the basic entities that make up a Java program, along with a description of the.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
How to Test Methods Computer Science 3 Gerb Objective: Test methods properly.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Written by: Dr. JJ Shepherd
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
CS/ENGRD 2110 FALL 2013 Lecture 3: Fields, getters and setters, constructors, testing 1.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Coding – Week 2 Functions, Arrays, and Objects. Functions  Functions are not a new concept – you’ve been using them already.  void setup() {} and void.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
ENCAPSULATION. WHY ENCAPSULATE? So far, the objects we have designed have all of their methods and variables visible to any part of the program that has.
Information and Computer Sciences University of Hawaii, Manoa
Working with Java.
Introduction to Computer Science / Procedural – 67130
C++ coding standard suggestion… Separate reasoning from action, in every block. Hi, this talk is to suggest a rule (or guideline) to simplify C++ code.
Java Coding 3 – part2 David Davenport Computer Eng. Dept.,
Classes and Objects 2nd Lecture
Building Java Programs
Static Methods 14-Nov-18.
Lesson 2: Building Blocks of Programming
Building Java Programs
Classes and Objects Encapsulation
Building Java Programs
Units with – James tedder
Units with – James tedder
Namespaces, Scopes, Access privileges
Instructor: Alexander Stoytchev
Building Java Programs
slides created by Ethan Apter and Marty Stepp
Presentation transcript:

25-Jun-15 Managing Complexity Programming is more than just syntax

Learning things that matter Things change rapidly in computer science Languages go in and out of popularity, operating systems change, even programming styles changes Half of what you learn in my class will be outdated in five years CIT591 is primarily an introductory programming course It uses this year’s popular programming language Unfortunately, that language is so complex that learning the syntax takes time away from learning to program In this slide set I’m talking about things that will not be outdated in five years But my examples will be from Java

Programs should work Programs should work correctly Many programs must be highly reliable Medical programs, space vehicle control programs, sales programs, income tax programs Household robots, self-driving automobiles The need for correctness isn’t going to change any time soon Programs should continue to work correctly after they are modified, or updated, or had new features added Thus, it is important to be able to modify programs safely This means: Clear, concise, readable programs Good tests, especially regression tests

Readability Can we read a program, or do we have to decipher it? Here’s a method I would consider readable: public boolean isLeapYear(int year) { if (year % 400 == 0) return true; if (year % 100 == 0) return false; return year % 4 == 0; } At this point, you may feel that all programs have to be deciphered I feel the same way when I try to read German With practice, deciphering changes to reading—mostly

Another readable method void playGame() { boolean playAgain = true; while (playAgain) { int computersScore = 0; int usersScore = 0; boolean nobodyHasWonYet = true; while (nobodyHasWonYet) { computersScore = computersScore + resultOfComputersTurn(); usersScore = usersScore + resultOfUsersTurn(); printCurrentScores(computersScore, usersScore); nobodyHasWonYet = computersScore < WINNING_SCORE && usersScore < WINNING_SCORE; } printFinalScores(computersScore, usersScore); playAgain = askUser("Do you want to play again?"); } }

A less readable method private static int giveRandomNumber(int minValue, int maxValue) { if (minValue>maxValue){ int temp=maxValue; maxValue=minValue; minValue=temp; } Random random=new Random(); int temp; if(maxValue temp){ temp=random.nextInt(maxValue+1); }//w }//e return temp; }

What makes a method “readable”? Short enough to see the entire method at once, without scrolling Does a single thing Has a meaningful, descriptive name Is properly formatted, and follows established conventions Has comments that further clarify what the method does Calls methods with meaningful, descriptive names Uses established idioms Very idiomatic: for (int i = 0; i < array.length; i++) Less idiomatic: for (row = 0; row <= array.length - 1; ++row) Has a short, memorable parameter list, with well-chosen parameter names Doesn’t do “weird” things Doesn’t change parameter objects unnecessarily If available outside the class, works for any valid object That is, it doesn’t depend on some other method being called first

What makes a program “modifiable”? Good tests are essential More bugs are introduced when “correcting” a program than at any other time If you have a complete set of tests, you can do this much more safely Frequently, in order to introduce new features, you have to refactor (reorganize) a program If you have a complete set of tests, you can do this much more safely You can add features, but you cannot change features that other people (that is, other parts of the project) depend upon At least, not without an extremely convincing reason You can’t change what methods do, but you can change how they do it You can only change how methods work if nothing else depends on it This is why you must hide as much as possible of your implementation

Example A modifiable program: public class Lexicon { private String[] words; private int[] counts; private int numberOfWords = 0; // etc. } An unmodifiable program: public class Lexicon { String[] words; int[] counts; int numberOfWords = 0; // etc. }

Information hiding When you provide a class to a project, You should provide everything that is needed by the project You should not provide anything that isn’t needed If you do, someone, somewhere, will take advantage of it If you then change it, you will get the blame There is a lot more to be said on the topic of information hiding, but I don’t have the time right now to say it all I will add this much: Information hiding also applies to your JUnit tests If you don’t want your tests to break when you make correct changes to your program, don’t depend on features that should be hidden

The End