SlideShare a Scribd company logo
1 of 24
General Issues in Using Variables Chapter:10
Contents
• ■ 1 Data Literacy
1.1 Data Literacy Test
• ■ 2 Making Variable Declarations Easy
2.1 Implicit Declarations
2.2 Explicit Declarations
■ 3 Guidelines for Initializing Variables
3.1 Guidelines for avoiding initialization problems:
• ■ 4 Scope
• ■ 5 Persistence
• ■ 6 Binding Time
• ■ 7 Relationship Between Data Types and Control Structures
• ■ 8 Using Each Variable for Exactly One Purpose
• 8.1 General Considerations In Using Data
ii
1/29/2016
Chp:10 General issues in using varibale
Data Literacy
Defination:
Data literacy is the ability to read,create, and communcate
data as infomation and has been formally described in varying
ways.
1.1
1/29/2016
Chp:10 General issues in using varibale
Data literacy
Data literacy Terms
Abstract data type literal Array
local variable bitmap lookup table
boolean variable member data B-tree
pointer character variable private
container class retroactive synapse double precision
referential integrity elongated stream stack
enumerated type string Floating point
Structured Variable Heap Tree
Index Typedef integer
Union Linked List Value Chain
Named Constant Variant
1.2
These are some Common Terms that use in programming language
1/29/2016Chp:10 General issues in using varibale
Making Variable Declaration Easy
Two types of Declaration occur
1. Implicit Declaration
(use in visual Basic,Fortron,PHP)
2. Explicit Declaration
(use in java,C++)
2.1
1/29/2016
Chp:10 General issues in using varibale
Making Variable Declaration Easy
Implicit Declaration:
• Some languages compiler implicitly declare, which means that you can
use every variable without Declaration. You can remove this
requirement and permit explicit declaration.
• In implicit declaration variable automatically convert to that type
which type of value assign to that variable.
2.2
Explicit Declaration:
• Most of the language use explicit declaration, which means that
you can not use any variable without Declaration. You should declare
the type of variable before use it .After this compiler assign the
memory to that variable according to that type.
• In explicit declaration user should follow the type of variable that he
declare otherwise compiler give error Message.
1/29/2016
Chp:10 General issues in using varibale
Making Variable Declaration Easy
Explicit Declaration is Recomended.
2.3
Which one is the best implicit or explicit??
1/29/2016Chp:10 General issues in using varibale
What do you do if you program in a language with implicit
declarations?
Some suggestions:
1. Turn off implicit declaration
2. Declare all variables
3. Use naming conventions
4. Check Variable names
2.4Making Variable Declaration Easy
1/29/2016Chp:10 General issues in using varibale
Guidelines for Initializing Variables
Improper data initialization is one of the most fertile sources
of error in computer programming.
3.1
 Reasons:
 The variable has never been assigned a value.
 Part of the variable has been assigned a value and part has not.
 The value in the variable is outdated .
1/29/2016Chp:10 General issues in using varibale
Following are guidelines for avoiding initialization
problems:
 Initialize each variable as it's declared.
 Use const/final when possible.
 Pay attention to counters and accumulators.
 Initialize a class's member data in its constructor.
 Check the need for re-initialization.
 Take advantage of your compiler's warning messages
 Check input parameters for validity .
 Use a memory-access checker to check for bad pointers.
 Initialize working memory at the beginning of your program.
3.2Guidelines for Initializing Variables
1/29/2016Chp:10 General issues in using varibale
Scope
“Scope” is a way of thinking about a variable’s celebrity
status: how famous is it?
• It refers to the area to which your variables are known and
can be referenced throughout a program.
• A variable with limited or small scope is known in only a
small area of a program
• A variable with large scope is known in many places in a
program
4.1
1/29/2016Chp:10 General issues in using varibale
Scope
 We can measure scope by:
 Span.
It is a method of measuring how close together the
references to a variable are.
 Live Time.
The total number of statements over which a variable is live
4.2
1/29/2016Chp:10 General issues in using varibale
Scope 4.3
 Measuring span and life time
1. a = 0;
2. a++; Life time = (4-1 +1) = 4
3. a+= 10; Average span = (0+0+0)/3 = 0;
4. a = 3;
1. a = 0;
2. b= 1; Life time = (4-1 +1) = 4
3. c = 0; Average span = 2/1 = 2;
4. a = b + c;
1/29/2016Chp:10 General issues in using varibale
Scope 4.4
 Why we try to restrict live time?
 You can concentrate on a smaller section of code.
 Code more readable.
 reduces the chance of initialization errors .
 Easy to modify.
1/29/2016Chp:10 General issues in using varibale
Scope 4.5
1/29/2016Chp:10 General issues in using varibale
Scope 4.6
 Initialize variables used in a loop immediately before the
loop .
 Don't assign a value to a variable until just before the
value is used.
 Break groups of related statements into separate routines .
 Begin with most restricted visibility, and expand the
scope if necessary .
 Keep both span and live time as short as you can.
Guideline for minimizing Scope:
1/29/2016Chp:10 General issues in using varibale
Persistence 5.1
 Persistence is life span of a piece of data.
 Problem:
When you assume variable is persist but it's not .
 Solution:
 Set variables to "unreasonable values" when they doesn’t persist.
 Use assertions to check critical variables.
 Declare and Initialize all data right before it's used.
1/29/2016Chp:10 General issues in using varibale
Binding Time 6.1
 The time at which the variable and its value
are bound.
The later you bind, the more flexibility you get
and the higher complexity you need .
titleBar.color = ReadTitleBarColor( )
titleBar.color = 0xFF;
titleBar.color = TITLE_BAR_COLOR;
Run Time
Compile Time
Code-Writing Time
1/29/2016Chp:10 General issues in using varibale
Relationship Between Data Types
and Control Structures
• Data types and control structures relate to each other in well-
defined ways that were originally described by the British
computer scientist Michael Jackson
• Jackson draws connections between three types of data and
corresponding control structures:
1. Sequential data
2. Selective data
3. Iterative data
7.1
1/29/2016Chp:10 General issues in using varibale
Using Each Variable for Exactly
One Purpose
• Use each variable for one purpose only
it’s sometimes tempting to use one variable in two different
places for two different activities. Usually, the variable is
named inappropriately for one of its uses or a “temporary”
variable is used in both cases (with the
8.1
// Compute roots of a quadratic equation
temp = Sqrt( b*b - 4*a*c );
root[0] = ( -b + temp ) / ( 2 * a );
root[1] = ( -b - temp ) / ( 2 * a );
...
// swap the roots
temp = root[0];
root[0] = root[1];
root[1] = temp ;
1/29/2016Chp:10 General issues in using varibale
Using Each Variable for Exactly
One Purpose 8.2
 Avoid hybrid coupling.
Double use is clear to you but it won't be to someone
else.
 Make sure all declared variables are used.
1/29/2016Chp:10 General issues in using varibale
Checklist: General Considerations
In Using Data : 8.3
Initializing Variables
 Does each routine check input parameters for validity?
 Does the code declare variables close to where they're first
used?
 Does the code initialize variables as they're declared, if
possible?
 Are counters and accumulators initialized properly and, if
necessary, reinitialized each time they are used?
 Does the code compile with no warnings from the compiler?
1/29/2016Chp:10 General issues in using varibale
Checklist: General Considerations
In Using Data Cont.. 8.4
Other General Issues in Using Data
 Do all variables have the smallest lift time possible?
 Are references to variables as close together as possible?
 Are all the declared variables being used?
 Are all variables bound with balance between the flexibility
and the complexity associated?
 Does each variable have only one purpose?
 Is each variable's meaning explicit, with no hidden meanings?
1/29/2016Chp:10 General issues in using varibale
1/29/2016Chp:10 General issues in using varibale

More Related Content

What's hot (20)

Packet scheduling
Packet schedulingPacket scheduling
Packet scheduling
 
Vlan
Vlan Vlan
Vlan
 
DATA-LINK LAYER.ppt
DATA-LINK LAYER.pptDATA-LINK LAYER.ppt
DATA-LINK LAYER.ppt
 
Transport layer
Transport layerTransport layer
Transport layer
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 25
Chapter 25Chapter 25
Chapter 25
 
aloha
alohaaloha
aloha
 
Pstn (Public Switched Telephone Networks)
Pstn (Public Switched Telephone Networks)Pstn (Public Switched Telephone Networks)
Pstn (Public Switched Telephone Networks)
 
Multiple Access in Computer Network
Multiple Access in Computer NetworkMultiple Access in Computer Network
Multiple Access in Computer Network
 
TCP and UDP
TCP and UDP TCP and UDP
TCP and UDP
 
Routing Presentation
Routing PresentationRouting Presentation
Routing Presentation
 
Ip Addressing Basics
Ip Addressing BasicsIp Addressing Basics
Ip Addressing Basics
 
Wan technologies
Wan technologiesWan technologies
Wan technologies
 
X.25
X.25X.25
X.25
 
TFTP - Trivial File Transfer Protocol
TFTP - Trivial File Transfer ProtocolTFTP - Trivial File Transfer Protocol
TFTP - Trivial File Transfer Protocol
 
IPocalypse
IPocalypseIPocalypse
IPocalypse
 
Frame relay
Frame relayFrame relay
Frame relay
 
TCP /IP
TCP /IPTCP /IP
TCP /IP
 
TFTP
TFTPTFTP
TFTP
 
Isdn networking
Isdn networkingIsdn networking
Isdn networking
 

Viewers also liked

Figuring It Out: Who is Supporting TSA Now & Who Will Support It In The Future
Figuring It Out: Who is Supporting TSA Now & Who Will Support It In The FutureFiguring It Out: Who is Supporting TSA Now & Who Will Support It In The Future
Figuring It Out: Who is Supporting TSA Now & Who Will Support It In The FutureTrueSense Marketing
 
Power of Open SDN- The Vendor Neutral Approach to Optimizing Your Network 09...
Power of Open SDN- The Vendor Neutral Approach to Optimizing Your Network  09...Power of Open SDN- The Vendor Neutral Approach to Optimizing Your Network  09...
Power of Open SDN- The Vendor Neutral Approach to Optimizing Your Network 09...Cary Hayward
 
Maximize Your Revenue. Feed More People.
Maximize Your Revenue. Feed More People.Maximize Your Revenue. Feed More People.
Maximize Your Revenue. Feed More People.TrueSense Marketing
 
Sesa Presentation 2015
Sesa Presentation 2015Sesa Presentation 2015
Sesa Presentation 2015Nick Loader
 
agricultura Presentacion luirro............
agricultura Presentacion luirro............agricultura Presentacion luirro............
agricultura Presentacion luirro............Luis Roberto Vasquez
 
Opstartvergadering MTB jeugdcoaching Wielerbond Vlaanderen
Opstartvergadering MTB jeugdcoaching Wielerbond VlaanderenOpstartvergadering MTB jeugdcoaching Wielerbond Vlaanderen
Opstartvergadering MTB jeugdcoaching Wielerbond VlaanderenMaarten Gybels
 
Victor romano c.i 22270210 ecuela 70 electricidad mencion mantenimiento
Victor romano c.i 22270210 ecuela 70 electricidad mencion mantenimientoVictor romano c.i 22270210 ecuela 70 electricidad mencion mantenimiento
Victor romano c.i 22270210 ecuela 70 electricidad mencion mantenimientovictor romano
 

Viewers also liked (14)

Point Zero
Point ZeroPoint Zero
Point Zero
 
Figuring It Out: Who is Supporting TSA Now & Who Will Support It In The Future
Figuring It Out: Who is Supporting TSA Now & Who Will Support It In The FutureFiguring It Out: Who is Supporting TSA Now & Who Will Support It In The Future
Figuring It Out: Who is Supporting TSA Now & Who Will Support It In The Future
 
Power of Open SDN- The Vendor Neutral Approach to Optimizing Your Network 09...
Power of Open SDN- The Vendor Neutral Approach to Optimizing Your Network  09...Power of Open SDN- The Vendor Neutral Approach to Optimizing Your Network  09...
Power of Open SDN- The Vendor Neutral Approach to Optimizing Your Network 09...
 
Luirro IN
Luirro INLuirro IN
Luirro IN
 
Maximize Your Revenue. Feed More People.
Maximize Your Revenue. Feed More People.Maximize Your Revenue. Feed More People.
Maximize Your Revenue. Feed More People.
 
Kushyfoot
KushyfootKushyfoot
Kushyfoot
 
Sesa Presentation 2015
Sesa Presentation 2015Sesa Presentation 2015
Sesa Presentation 2015
 
Rhino Freedom
Rhino Freedom Rhino Freedom
Rhino Freedom
 
agricultura Presentacion luirro............
agricultura Presentacion luirro............agricultura Presentacion luirro............
agricultura Presentacion luirro............
 
Opstartvergadering MTB jeugdcoaching Wielerbond Vlaanderen
Opstartvergadering MTB jeugdcoaching Wielerbond VlaanderenOpstartvergadering MTB jeugdcoaching Wielerbond Vlaanderen
Opstartvergadering MTB jeugdcoaching Wielerbond Vlaanderen
 
Powerful Storytelling
Powerful StorytellingPowerful Storytelling
Powerful Storytelling
 
Victor romano c.i 22270210 ecuela 70 electricidad mencion mantenimiento
Victor romano c.i 22270210 ecuela 70 electricidad mencion mantenimientoVictor romano c.i 22270210 ecuela 70 electricidad mencion mantenimiento
Victor romano c.i 22270210 ecuela 70 electricidad mencion mantenimiento
 
TSM-Heroes
TSM-HeroesTSM-Heroes
TSM-Heroes
 
Uses of Computer
Uses of ComputerUses of Computer
Uses of Computer
 

Similar to Chap10

Standard coding practices
Standard coding practicesStandard coding practices
Standard coding practicesAnilkumar Patil
 
Reactive Performance Testing
Reactive Performance TestingReactive Performance Testing
Reactive Performance TestingLilit Yenokyan
 
Programming with C++
Programming with C++Programming with C++
Programming with C++ssuser802d47
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopMax Kleiner
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programmingJuggernaut Liu
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...DevDay.org
 
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnitymazenet
 
Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...
 Tips for Writing Better Charters for Exploratory Testing Sessions by Michael... Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...
Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...TEST Huddle
 
Abstract An overview of the whole report and what it is about..docx
Abstract An overview of the whole report and what it is about..docxAbstract An overview of the whole report and what it is about..docx
Abstract An overview of the whole report and what it is about..docxbartholomeocoombs
 
Troubleshooting as Your Kafka Clusters Grow (Krunal Vora, Tinder) Kafka Summi...
Troubleshooting as Your Kafka Clusters Grow (Krunal Vora, Tinder) Kafka Summi...Troubleshooting as Your Kafka Clusters Grow (Krunal Vora, Tinder) Kafka Summi...
Troubleshooting as Your Kafka Clusters Grow (Krunal Vora, Tinder) Kafka Summi...confluent
 
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxssusere336f4
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGEINTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGERathnaM16
 

Similar to Chap10 (20)

Variables
VariablesVariables
Variables
 
12.6-12.9.pptx
12.6-12.9.pptx12.6-12.9.pptx
12.6-12.9.pptx
 
Standard coding practices
Standard coding practicesStandard coding practices
Standard coding practices
 
Core java
Core javaCore java
Core java
 
Evaluation
EvaluationEvaluation
Evaluation
 
H evaluation
H evaluationH evaluation
H evaluation
 
Reactive Performance Testing
Reactive Performance TestingReactive Performance Testing
Reactive Performance Testing
 
Programming with C++
Programming with C++Programming with C++
Programming with C++
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_Workshop
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
 
Introduction To Programming (2009 2010)
Introduction To Programming (2009 2010)Introduction To Programming (2009 2010)
Introduction To Programming (2009 2010)
 
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnity
 
VB PPT by ADI PART2.pdf
VB PPT by ADI PART2.pdfVB PPT by ADI PART2.pdf
VB PPT by ADI PART2.pdf
 
Design smells
Design smellsDesign smells
Design smells
 
Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...
 Tips for Writing Better Charters for Exploratory Testing Sessions by Michael... Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...
Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...
 
Abstract An overview of the whole report and what it is about..docx
Abstract An overview of the whole report and what it is about..docxAbstract An overview of the whole report and what it is about..docx
Abstract An overview of the whole report and what it is about..docx
 
Troubleshooting as Your Kafka Clusters Grow (Krunal Vora, Tinder) Kafka Summi...
Troubleshooting as Your Kafka Clusters Grow (Krunal Vora, Tinder) Kafka Summi...Troubleshooting as Your Kafka Clusters Grow (Krunal Vora, Tinder) Kafka Summi...
Troubleshooting as Your Kafka Clusters Grow (Krunal Vora, Tinder) Kafka Summi...
 
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptx
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGEINTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
 

Recently uploaded

Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 

Recently uploaded (20)

Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

Chap10

  • 1. General Issues in Using Variables Chapter:10
  • 2. Contents • ■ 1 Data Literacy 1.1 Data Literacy Test • ■ 2 Making Variable Declarations Easy 2.1 Implicit Declarations 2.2 Explicit Declarations ■ 3 Guidelines for Initializing Variables 3.1 Guidelines for avoiding initialization problems: • ■ 4 Scope • ■ 5 Persistence • ■ 6 Binding Time • ■ 7 Relationship Between Data Types and Control Structures • ■ 8 Using Each Variable for Exactly One Purpose • 8.1 General Considerations In Using Data ii 1/29/2016 Chp:10 General issues in using varibale
  • 3. Data Literacy Defination: Data literacy is the ability to read,create, and communcate data as infomation and has been formally described in varying ways. 1.1 1/29/2016 Chp:10 General issues in using varibale
  • 4. Data literacy Data literacy Terms Abstract data type literal Array local variable bitmap lookup table boolean variable member data B-tree pointer character variable private container class retroactive synapse double precision referential integrity elongated stream stack enumerated type string Floating point Structured Variable Heap Tree Index Typedef integer Union Linked List Value Chain Named Constant Variant 1.2 These are some Common Terms that use in programming language 1/29/2016Chp:10 General issues in using varibale
  • 5. Making Variable Declaration Easy Two types of Declaration occur 1. Implicit Declaration (use in visual Basic,Fortron,PHP) 2. Explicit Declaration (use in java,C++) 2.1 1/29/2016 Chp:10 General issues in using varibale
  • 6. Making Variable Declaration Easy Implicit Declaration: • Some languages compiler implicitly declare, which means that you can use every variable without Declaration. You can remove this requirement and permit explicit declaration. • In implicit declaration variable automatically convert to that type which type of value assign to that variable. 2.2 Explicit Declaration: • Most of the language use explicit declaration, which means that you can not use any variable without Declaration. You should declare the type of variable before use it .After this compiler assign the memory to that variable according to that type. • In explicit declaration user should follow the type of variable that he declare otherwise compiler give error Message. 1/29/2016 Chp:10 General issues in using varibale
  • 7. Making Variable Declaration Easy Explicit Declaration is Recomended. 2.3 Which one is the best implicit or explicit?? 1/29/2016Chp:10 General issues in using varibale
  • 8. What do you do if you program in a language with implicit declarations? Some suggestions: 1. Turn off implicit declaration 2. Declare all variables 3. Use naming conventions 4. Check Variable names 2.4Making Variable Declaration Easy 1/29/2016Chp:10 General issues in using varibale
  • 9. Guidelines for Initializing Variables Improper data initialization is one of the most fertile sources of error in computer programming. 3.1  Reasons:  The variable has never been assigned a value.  Part of the variable has been assigned a value and part has not.  The value in the variable is outdated . 1/29/2016Chp:10 General issues in using varibale
  • 10. Following are guidelines for avoiding initialization problems:  Initialize each variable as it's declared.  Use const/final when possible.  Pay attention to counters and accumulators.  Initialize a class's member data in its constructor.  Check the need for re-initialization.  Take advantage of your compiler's warning messages  Check input parameters for validity .  Use a memory-access checker to check for bad pointers.  Initialize working memory at the beginning of your program. 3.2Guidelines for Initializing Variables 1/29/2016Chp:10 General issues in using varibale
  • 11. Scope “Scope” is a way of thinking about a variable’s celebrity status: how famous is it? • It refers to the area to which your variables are known and can be referenced throughout a program. • A variable with limited or small scope is known in only a small area of a program • A variable with large scope is known in many places in a program 4.1 1/29/2016Chp:10 General issues in using varibale
  • 12. Scope  We can measure scope by:  Span. It is a method of measuring how close together the references to a variable are.  Live Time. The total number of statements over which a variable is live 4.2 1/29/2016Chp:10 General issues in using varibale
  • 13. Scope 4.3  Measuring span and life time 1. a = 0; 2. a++; Life time = (4-1 +1) = 4 3. a+= 10; Average span = (0+0+0)/3 = 0; 4. a = 3; 1. a = 0; 2. b= 1; Life time = (4-1 +1) = 4 3. c = 0; Average span = 2/1 = 2; 4. a = b + c; 1/29/2016Chp:10 General issues in using varibale
  • 14. Scope 4.4  Why we try to restrict live time?  You can concentrate on a smaller section of code.  Code more readable.  reduces the chance of initialization errors .  Easy to modify. 1/29/2016Chp:10 General issues in using varibale
  • 15. Scope 4.5 1/29/2016Chp:10 General issues in using varibale
  • 16. Scope 4.6  Initialize variables used in a loop immediately before the loop .  Don't assign a value to a variable until just before the value is used.  Break groups of related statements into separate routines .  Begin with most restricted visibility, and expand the scope if necessary .  Keep both span and live time as short as you can. Guideline for minimizing Scope: 1/29/2016Chp:10 General issues in using varibale
  • 17. Persistence 5.1  Persistence is life span of a piece of data.  Problem: When you assume variable is persist but it's not .  Solution:  Set variables to "unreasonable values" when they doesn’t persist.  Use assertions to check critical variables.  Declare and Initialize all data right before it's used. 1/29/2016Chp:10 General issues in using varibale
  • 18. Binding Time 6.1  The time at which the variable and its value are bound. The later you bind, the more flexibility you get and the higher complexity you need . titleBar.color = ReadTitleBarColor( ) titleBar.color = 0xFF; titleBar.color = TITLE_BAR_COLOR; Run Time Compile Time Code-Writing Time 1/29/2016Chp:10 General issues in using varibale
  • 19. Relationship Between Data Types and Control Structures • Data types and control structures relate to each other in well- defined ways that were originally described by the British computer scientist Michael Jackson • Jackson draws connections between three types of data and corresponding control structures: 1. Sequential data 2. Selective data 3. Iterative data 7.1 1/29/2016Chp:10 General issues in using varibale
  • 20. Using Each Variable for Exactly One Purpose • Use each variable for one purpose only it’s sometimes tempting to use one variable in two different places for two different activities. Usually, the variable is named inappropriately for one of its uses or a “temporary” variable is used in both cases (with the 8.1 // Compute roots of a quadratic equation temp = Sqrt( b*b - 4*a*c ); root[0] = ( -b + temp ) / ( 2 * a ); root[1] = ( -b - temp ) / ( 2 * a ); ... // swap the roots temp = root[0]; root[0] = root[1]; root[1] = temp ; 1/29/2016Chp:10 General issues in using varibale
  • 21. Using Each Variable for Exactly One Purpose 8.2  Avoid hybrid coupling. Double use is clear to you but it won't be to someone else.  Make sure all declared variables are used. 1/29/2016Chp:10 General issues in using varibale
  • 22. Checklist: General Considerations In Using Data : 8.3 Initializing Variables  Does each routine check input parameters for validity?  Does the code declare variables close to where they're first used?  Does the code initialize variables as they're declared, if possible?  Are counters and accumulators initialized properly and, if necessary, reinitialized each time they are used?  Does the code compile with no warnings from the compiler? 1/29/2016Chp:10 General issues in using varibale
  • 23. Checklist: General Considerations In Using Data Cont.. 8.4 Other General Issues in Using Data  Do all variables have the smallest lift time possible?  Are references to variables as close together as possible?  Are all the declared variables being used?  Are all variables bound with balance between the flexibility and the complexity associated?  Does each variable have only one purpose?  Is each variable's meaning explicit, with no hidden meanings? 1/29/2016Chp:10 General issues in using varibale
  • 24. 1/29/2016Chp:10 General issues in using varibale

Editor's Notes

  1. 1.The first step in creating effective data is knowing which kind of data to create. 2. A good repertoire(Range) of data types is a key part of a programmer’s toolbox. 3. “Data Literacy Test” will help you determine how much more you might need to learn about them.
  2. The term implicit means when compiler automatically do that work without user knowledge. The Term explicit mean when user do that work without depending on compiler
  3. The most common disadvantage of using the implicit declaration is readability and does not recommended in a language that have pointers because it cause a lot of trouble in readability and if any mistake occur regarding to type then compiler doesnot point out that mistake . Explicit declaration requires you to use data more carefully which is the main advantage of using this declaration.
  4. Implicit declaration: Some compilers allow you to disable implicit declarations. For example, in Visual Basic you would use an Option Explicit statement, which forces you to declare all variables before you use them. Declare all the variables: As you type in a new variable, declare it, even though the compiler doesn’t require you to. This won’t catch all the errors, but it will catch some of them. Naming conventions: Establish a naming convention for common suffixes such as Num and No so that you don’t use two variables when you mean to use one. Check Variable names: Use the cross-reference list generated by your compiler or another utility program. Many compilers list all the variables in a routine, allowing you to spot both acctNum and acctNo. They also point out variables that you’ve declared and not used.
  5. “Scope” is a way of thinking about a variable’s celebrity status: how famous is it? Scope, or visibility, refers to the extent to which your variables are known and can be referenced throughout a program. A variable with limited or small scope is known in only a small area of a program—a loop index used in only one small loop, for instance. A variable with large scope is known in many places in a program—a table of employee information that’s used throughout a program, for instance.
  6. Are they bound together when the code is written? When it is compiled? When it is loaded? When the program is run? Some other time? Code time : if this 0xFF changes, it can get out of synch with 0xFFs used elsewhere in the code that must be the same value as this one.
  7. Sequential data translates to sequential statements in a program Sequences consist of clusters of data used together in a certain order, as suggested by Figure 10-2. If you have five statements in a row that handle five different values, they are sequential statements. If you read an employee’s name, Social Security Number, address, phone number, and age from a file, you’d have sequential statements in your program to read sequential data from the file. Selective data translates to if and case statements in a program In general, selective data is a collection in which one of several pieces of data is used at any particular time, but only one, as shown in Figure 10-3. The corresponding program statements must do the actual selection, and they consist of if-then-else or case statements. If you had an employee payroll program, you might process employees differently depending on whether they were paid hourly or salaried. Again, patterns in the code match patterns in the data. Iterative data translates to for, repeat, and while looping structures in a program Iterative data is the same type of data repeated several times, as suggested by Figure 10-4. Typically, iterative data is stored as elements in a container, records in a file, or elements in an array. You might have a list of Social Security Numbers that you read from a file. The iterative data would match the iterative code loop used to read the data.
  8. hybrid coupling :The value in the variable pageCount might represent the number of pages printed, unless it equals -1, in which case it indicates that an error has occurred. the integer is moonlighting as a boolean