Software Engineering Variables. The data literacy test Count 1.0 if you know what the concept means. Count 0.5 if you believe you know what the concept.

Slides:



Advertisements
Similar presentations
Variables and Powerful Names Nathan Scheck CS525 Software Engineering II Fall II 2007 – Sheldon X. Liang, Ph.D. Nathan Scheck CS525 Software Engineering.
Advertisements

Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
Software Engineering Fundamental data types. Guidelines - numbers Avoid “magic numbers” (hard- coded values that are not self- explanatory): Changes can.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Software Engineering Routine design. High quality routines Routine: individual method or procedure invocable for a single purpose.
Software Engineering Class design. Class design – ADT Abstract Data Types:  Why use ADT? Hidden implementation details Changes do not affect whole program.
Chapter 10 Introduction to Arrays
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Variables and Powerful Naming Ryan Ruzich. Naming Considerations The most important consideration in naming a variable is that the name fully and accurately.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Lecture-5 Though SQL is the natural language of the DBA, it suffers from various inherent disadvantages, when used as a conventional programming language.
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
C++ for Engineers and Scientists Third Edition
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
String Escape Sequences
General Issues in Using Variables
Code-Tuning By Jacob Shattuck. Code size/complexity vs computation resource utilization A classic example: Bubblesort A classic example: Bubblesort const.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
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.
Chapter 7: High Quality Routines By Raj Ramsaroop.
Sahar Mosleh California State University San MarcosPage 1 A for loop can contain multiple initialization actions separated with commas Caution must be.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
CS242.  Reduce Complexity  Introduce an intermediate, understandable abstraction  Avoid code duplication  Support subclassing  Hide sequences  Hide.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Guidelines for a Language- Independent Convention Identify global variables –Use g_prefix –Exp: g_RunningTotal Identify module variables –Use m_prefix.
Best Practices for Variables
Using Variables Chapter Outline 2  Variable Initialization  Scope  Persistence  Using Each Variable for Single Purpose  Variable Names.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
CSC Programming I Lecture 6 September 4, 2002.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
Introduction to Loops Iteration Repetition Counting Loops Also known as.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
By Mr. Muhammad Pervez Akhtar
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
CPS120: Introduction to Computer Science Variables and Constants.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Beginning C For Engineers Fall 2005 Lecture 3: While loops, For loops, Nested loops, and Multiple Selection Section 2 – 9/14/05 Section 4 – 9/15/05 Bettina.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Review for Test2. Scope 8 problems, 60 points. 1 Bonus problem (5 points) Coverage: – Test 1 coverage – Exception Handling, Switch Statement – Array of.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
General Issues in Using Variables
Computing and Statistical Data Analysis Lecture 2
Java Primer 1: Types, Classes and Operators
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
University of Central Florida COP 3330 Object Oriented Programming
CMSC 202 Java Primer 2.
Coding Concepts (Basics)
Chapter 09 – Part II Using Variables
Object Oriented Programming in java
Java Programming Language
Introduction to Computer Science
Primitive Types and Expressions
CHAPTER 6 Testing and Debugging.
Introduction to Classes and Objects
Presentation transcript:

Software Engineering Variables

The data literacy test Count 1.0 if you know what the concept means. Count 0.5 if you believe you know what the concept means, but you are not sure. Add the points and check your score.

The data literacy test abstract data typeheapretroactive synapse arrayindexreferential integrity bitmapintegerstack boolean variablelinked liststring B-treenamed constantstructured variable character variableliteraltree container classlocal variabletypedef double precisionlookup tableunion elongated streammember datavalue chain enumerated typepointervariant floating pointprivate

The data literacy test 0-14: beginner. You should not be attending this course : intermediate. How would you consider attending more basic courses? 20-24: expert. Welcome to this course : genius. You should be teaching this course : fraud. You could not even identify some meaningless names that were included in the list...

Variable initialisation Initialise each variable as it is declared (re)Initialise each variable close to where it is first used Ideally, declare and initialise each variable close to where it is first used Use final (Java), const (C++), etc. whenever possible, so that programming variables behave similar to mathematical variables

Variable initialisation Pay special attention to counters and accumulators Initialise a class's member data in its constructor Check the need for reinitialisation Check input parameters for validity

Scoping Localise (i.e. put as close as possible) references to variables Minimise average variable span (span: distance between consecutive references of a variable, in lines): a = 0;span(a) = 2 b = 0;span(b) = 1 c = 0;span(c) = 0 a = b + c;

Scoping Minimise “life span” of each variable (life span: total number of lines between first and last reference to a variable) Initialise variables in a loop immediately before the loop Do not assign a value to a variable until just before the value is used

Scoping Group related statements with respect to variable referencing Break groups of related statements into separate routines Larger scopes make program easier to write; smaller scopes make program easier to read

Using variables Use each variable for one purpose only Avoid hidden meanings (e.g. “Age means age of a person, except when it values -1, in which case it denotes that the person's age is unknown”) Make sure that all declared variables are used

Naming variables Names should be expressive and self- contained Names should refer to the problem rather than the solution (e.g. EmployeeData is better than InputRec) Names should not be too long nor too short (between 8 and 20 characters is fine)

Naming variables Use conventions for variable names related to specific data types: Loop indices: recordCount, teamIndex Status variables: characterType, recalcNeed Temporary variables: avoid them; if you need them, avoid names like temp or x Boolean variables: done, error, found, success, ok; avoid negative names like notFound

Naming variables USE CONVENTIONS

Naming variables Abbreviations: Do not abbreviate by removing one character from a word Abbreviate consistently Create names that you can pronounce Avoid combinations that result in misreading or mispronunciation Document short names with translation tables in the code

Naming variables Names to avoid: Avoid misleading names or abbreviations Avoid names with similar meanings Avoid variables with different meanings and similar names Avoid names that sound similar Avoid numerals in names, as in file1 and file2 Avoid misspelled words in names Do not differentiate variables solely by capitalisation

Naming variables Names to avoid: Avoid multiple natural languages Avoid the names of standard types, variables and routines Avoid names containing hard-to-read characters, e.g. Hard2Read and HardZRead Do not use names that are totally unrelated to what the variables represent