1 Variables (Chapters 10-11 of Code Complete) Steve Chenoweth CSSE 375, Rose-Hulman Based on Don Bagert’s 2006 Lecture.

Slides:



Advertisements
Similar presentations
CISC Data Structures Ben Perry University of Delaware Summer 2011.
Advertisements

9-Jun-14 Enum s (and a review of switch statements)
Programming Languages and Paradigms
Lecture 9: More on objects, classes, strings discuss hw3 assign hw4 default values for variables scope of variables and shadowing null reference and NullPointerException.
Arrays CS177 (Week 06). Announcements ● Project 2 due today ● Project 3 will be posted tomorrow.
1 Software Craftsmanship Steve Chenoweth CSSE 375, Rose-Hulman Based on Don Bagert’s 2006 Lecture Right – Making sundials. From website
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
1 Program Understanding Steve Chenoweth CSSE 375, Rose-Hulman Based on Don Bagert’s 2006 Lecture.
1 Maintenance Metrics and Measures (M 12) Steve Chenoweth CSSE 375, Rose-Hulman Based on Don Bagert’s 2006 Lecture.
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
Sanjay Goel, School of Business, University at Albany, SUNY 1 MSI 692: Special Topics in Information Technology Lecture 2 Sanjay Goel University at Albany,
1 Quality Assurance in Construction and Maintenance (Section 13.4 of Maintenance Text; Chapter 20 of Code Complete) Steve Chenoweth CSSE 375, Rose-Hulman.
1 Detailed Design Representations (Chapter 9 of Code Complete) Steve Chenoweth CSSE 375, Rose-Hulman Based on Don Bagert’s 2006 Lecture.
Saturday May 02 PST 4 PM. Saturday May 02 PST 10:00 PM.
CSE 115 Week 4 February 4 - 8, Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.
Types A type consists of –a set of values –a set of operations on those values Types can be –primitive (atomic, non-decomposable) –composite (includes.
1 Maintenance Management and Organization Steve Chenoweth CSSE 375, Rose-Hulman Based on Don Bagert’s 2006 Lecture.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
General Issues in Using Variables
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Java Implementation: Part 3S CompSci 230 Software Construction.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Week 9 - Friday.  What did we talk about last time?  typedef  Linked lists.
 Thursday: › Team Presentations › Risk Assessment and project plan due 11:55 pm  Friday: › Help on coding/testing  Monday: › HW 5 due, 11:55 pm.
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
Compound Statements If you want to do more than one statement if an IF- else case, you can form a block of statements, or compound statement, by enclosing.
1 Statements: Control Structure Issues (Chapters and 19 of Code Complete) Don Bagert CSSE 375, Rose-Hulman October 17, 2006.
F27SA1 Software Development 1 3. Java Programming 2 Greg Michaelson.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 11/06/2012 and 11/07/2012 -Test 3 Study Guide.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
Compound Statements If you want to do more than one statement if an if- else case, you can form a block of statements, or compound statement, by enclosing.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
More Selection Executing Statements Selectively Chap. 7 (Read § & Part of Picture: Boolean Logic and Digital Design) 1.
3. Controlling Program Flow Methods, parameters, and return values Boolean expressions Conditional branching Loops.
Using Variables Chapter Outline 2  Variable Initialization  Scope  Persistence  Using Each Variable for Single Purpose  Variable Names.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
1 BUILDING JAVA PROGRAMS CHAPTER 2 Pseudocode and Scope.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
Boolean Expressions and if-else Statements Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006.
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
1 COMP313A Programming Languages Object Oriented Progamming Languages (2)
CONTENTS Wrapper Class Enumeration Garbage Collection Import static.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
1 Homework –Continue Reading K&R Chapter 2 –We’ll go over HW2 at end of class today –Continue working on HW3 Questions?
1 Maintenance of Documentation and Documentation of Maintenance Quiz 7 Tori Bowman CSSE 375, Rose-Hulman October 1, 2006.
Simple Data Types Chapter Constants Revisited t Three reasons to use constants –Constant is recognizable –Compiler prevents changes in value.
Flipping the classroom FOUNDATIONS OF ALGEBRA 2 / TRIG.
Agent program is the one part(class)of Othello program. How many test cases do you have to test? Reversi [Othello]
CSci 162 Lecture 2 Martin van Bommel. Enumeration –process of listing all of the elements in the domain of a type Enumerated type –type defined via enumeration.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
More Selection Executing Statements Selectively Chap. 7 (Read § & Part of Picture: Boolean Logic and Digital Design) 1.
1 Enums (Chapter 4) To enumerate is: to name things one after another in a list Java has a type, called an enum, where a programmer specifies a finite.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays days until the AP Computer Science test.
What are the importance of the days of the week ?
Simple Data Types Chapter Constants Revisited t Three reasons to use constants –Constant is recognizable –Compiler prevents changes in value.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
ENUMERATED TYPES Java Basics. Enumerated Type Topics Why use them? Defining an enumerated type Using an enumerated type Advanced features.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
CS0007: Introduction to Computer Programming
General Issues in Using Variables
Control Statements: Part 2
Chapter 8 JavaScript: Control Statements, Part 2
Variables ICS2O.
Documentation and Style
Presentation transcript:

1 Variables (Chapters of Code Complete) Steve Chenoweth CSSE 375, Rose-Hulman Based on Don Bagert’s 2006 Lecture

2 Today  Your variable results may vary…this  Tonight – turn in HW 4  HW 5 – due Mon, Oct 24 (next Mon) Ronald – from

3 Outline Variables Maintenance Issue with variables -- in general The Data Literacy Test Declarations “PLC Issues” Naming Issues Variables in Maintenance/Open Source

4 Maintenance issue with variables…  How to make it clear what they’re looking at. Say, you encounter the following variable for the first time: accountindex++ ;  What is going on? -- translates to What are they doing with this variable? Often, have to guess at both pieces of knowledge: What does accountindex stand for? What’s the current value now?

5 An example – Mac’s  I said, “I’ll have a number 1 with a Coke.”  She said, “What size?”  I said, “The 4.95 size.”  She looked back at the menu, said, “Medium or large?”  I said, “How should I know?” What was the problem? Picture from suzero.com/blog/?m= suzero.com/blog/?m=200704

6 A lot of programs have similar problems in explaining vbl meaning…  From an infamous CSSE 374 program (TwentyFour): static final int maxDepth = 10; // How deep is our search table? (see next line) int operandTbl[][] = new int[maxDepth][9]; // for selecting operands & recording answers /* Values of slots in this table are as follows, for each i = 1 to maxDepth: answer = operandTbl[i][0]; // answer, or original operand status flag = operandTbl[i][1]; // 0 = empty, kinda; 1 = ready to use, 2 = used op1 = operandTbl[i][2]; // recover pieces of each calc, for display op2 = operandTbl[i][3]; // 2nd operand or flag if unary operation opn = operandTbl[i][4]; // operation, or -1 = original operand with no operation …

7 Quiz Exercise 1: Data Literacy Test (page 238 of Code Complete) -- see also p. 2 of your daily quiz

8 An interesting style question…  Why do you use enumerated types?

9 An interesting style question…  Typical example of enumerated types – public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } … public void tellItLikeItIs() { switch (day) { case MONDAY: System.out.println("Mondays are bad."); break; \ case FRIDAY: System.out.println("Fridays are better."); break; …

10 Declaration Issues  Implicit declarations are bad! (Messed up an early Mars mission, for instance)  Initializing all variables is an example of defensive programming, but which may also decrease readability

11 Variable “Problems” grow with the system:  As you make a class more and more complex, the variable use becomes messy.  Say, we started with a method that decides if Steve (or whomever) has an account with us: boolean CheckForName(string name){ boolean found = false; while (not db.eof()) { record nextOne = db.getNext(); if nextOne.name == name { found = true; break; } } return found; }  Later, you want to use this same routine to look up their account balance…

12 “PLC Issues”  Topics that are usually covered in CSSE 304: Scope Persistence Binding Time

13 How’s this one working out?  In Java, variables created with new persist until they are garbage collected.  In C++, variables created with new persist until you delete them.

14 Identifier Naming Issues  Mnemonic (meaningful) names  Length of 6-20 characters recommended  Use names for loop indices?  Language-specific conventions (pages of Code Complete) e.g. for Java, variable and method names begin with a small letter, while class names start with a capital

15 Example  Java names -- notoriously long, even for “trivial” purposes: // Create label for displaying moon phase images and put a border around it. phaseIconLabel = new JLabel(); phaseIconLabel.setHorizontalAlignment(JLabel.CENTER); phaseIconLabel.setVerticalAlignment(JLabel.CENTER); phaseIconLabel.setVerticalTextPosition(JLabel.CENTER); phaseIconLabel.setHorizontalTextPosition(JLabel.CENTER); phaseIconLabel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(5,5,5,5))); …

16 Quiz Question 5: Identifier Programming Style See sample code, pp. 3-4 of your daily quiz. Do with a team mate.