General Issues in Using Variables

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

Programming Languages and Paradigms
1 C++ Syntax and Semantics The Development Process.
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 Chapter 4. Think back to any very difficult quantitative problem that you had to solve in some science class How long did it take? How many times.
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.
Pointers Typedef Pointer Arithmetic Pointers and Arrays.
Variables and Powerful Naming Ryan Ruzich. Naming Considerations The most important consideration in naming a variable is that the name fully and accurately.
CS414 C Programming Tutorial Ben Atkin
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Program Design and Development
1 Introduction to Computers and Programming Quick Review What is a Function? A module of code that performs a specific job.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Guide To UNIX Using Linux Third Edition
C++ for Engineers and Scientists Third Edition
Which is better?. Assume s1 and s2 are Strings: A.if (s1 == s2) {... } B.if (s1.equals(s2)) {... }
VB .NET Programming Fundamentals
Introduction to C++ Programming
Code-Tuning By Jacob Shattuck. Code size/complexity vs computation resource utilization A classic example: Bubblesort A classic example: Bubblesort const.
Python quick start guide
1 Course Lectures Available on line:
Call-by-Value vs. Call-by-Reference Call-by-value parameters are used for passing information from the calling function to the called function (input parameters).
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.
VARIABLES AND TYPES CITS1001. Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Scope.
Chapter 7: High Quality Routines By Raj Ramsaroop.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
Chapter 2 Overview of C++. A Sample Program // This is my first program. It calculates and outputs // how many fingers I have. #include using namespace.
Pointers OVERVIEW.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Some Fortran programming tips ATM 562 Fall 2015 Fovell (see also PDF file on class page) 1.
CS242.  Reduce Complexity  Introduce an intermediate, understandable abstraction  Avoid code duplication  Support subclassing  Hide sequences  Hide.
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.
Introduction to Programming
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
Language Find the latest version of this document at
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
1 Scope Lifetime Functions (the Sequel) Chapter 8.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Today: –Two simple binding examples. –Function Hiding.
MORE POINTERS Plus: Memory Allocation Heap versus Stack.
Introduction to Computing Systems and Programming Programming.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Computer Programming 12 Lesson 4 - Computer Programming Structure By Dan Lunney.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
General Issues in Using Variables
Chapter 1.2 Introduction to C++ Programming
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Exam 1 Review.
Bill Tucker Austin Community College COSC 1315
Functions Inputs Output
Designing and Debugging Batch and Interactive COBOL Programs
T. Jumana Abu Shmais – AOU - Riyadh
Loop Strategies Repetition Playbook.
Chapter 09 – Part II Using Variables
Variables and Constants
Presentation transcript:

General Issues in Using Variables Chapter 10 General Issues in Using Variables

Data Literacy Find the three data types that don’t fit: Elongated Stream Double Precision Heap Retroactive Synapse Stack Value Chain Array Local Variable Typedef

Making Variable Declarations Easy If a programming language doesn’t require that you implicitly define the variable, define it anyway. Declare all variables before you use them. Make a list of all variables declared. Check to make sure that you have declared a variable before it’s put to use.

Guidelines for Initializing Variables Improper data initialization is one of the most problematic sources of error in computer programming. Guidelines for avoiding initialization problems: Initialize and define each variable as its declared. Initialize each variable close to where it’s used. Use final or const when possible. Pay attention to counters. Check if re-initialization is necessary. Actually read the warnings from the compiler.

Guidelines for Initializing Variables More guidelines for avoiding initialization problems: Check input parameters for validity. Check for bad pointers. Initialize working memory at the start of your program.

Scope Scope is the “live time” of a variable. Keep the scope short to make code more readable. Group variables with similar scopes.

Persistence The lifespan of a piece of data. Main problem: assuming a variable has a longer lifespan than it actually has. Ways to avoid persistence problems: Use debug code to check for improper initialization. Set variables to null when finished with them.

Relationship Between Data Types and Control Structures Sequential data translates to sequential statements in a program. Selective data translates to if and case statements. Iterative data translates to for, repeat, and while looping structures in a program.

Using Each Variable for Exactly One Purpose Use one variable for one purpose only.

The Power of Variable Names Chapter 11 The Power of Variable Names

Considerations in Choosing Good Names Choose good names for variables. Make them easy to read. Make them understandable. Don’t make them too long or too short.

Naming Specific Types of Data Status Variables (flag) Temporary Variables (temp) Boolean Variables (true or false)

The Power of Naming Conventions Why there are standards: Global decisions not local ones. Transfer knowledge across processes. Lean code more quickly on a project. Compensate for language weakness. Emphasize relationships between variables.

Standard Prefixes For a Word Document: Ch (character) Doc (document) Pa (paragraph) Scr (screen region) Sel (selection) Wn (window)

Creating Short Names That Are Readable Use standard abbreviations Use combinations of numbers and letters Document all code abbreviations

Kinds of Names to Avoid Duplicating words Commonly misspelled words Words that cross multiple languages Unrelated names

Questions?