Lesson Objectives Aims Key Words

Slides:



Advertisements
Similar presentations
Lists Introduction to Computing Science and Programming I.
Advertisements

1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Adapted from Dr. Craig Chase, The University of Texas at Austin.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
Lesson 3 Variables – How our Brains Work - Variables in Python.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
Object-Oriented Programming in C++
Prog. techniques. Standard prog. techniques Complex programs can be broken down into simpler parts called “Modules” These come in 2 types,“Procedures”
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
ME 142 Engineering Computation I Using Subroutines Effectively.
Top-down approach / Stepwise Refinement & Procedures & Functions.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Object Oriented Programming Criteria: P2 Date: 07/10/15 Name: Thomas Jazwinski.
04/02/ Procedures Top-down approach / Stepwise Refinement & Sub Procedures.
Controlling Program Flow with Decision Structures.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
Subprograms - implementation. Calling a subprogram  transferring control to a subprogram: save conditions in calling program pass parameters allocate.
Fundamental Programming Fundamental Programming Introduction to Functions.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Module 9: Operator overloading #1 2000/01Scientific Computing in OOCourse code 3C59 Module 9: Operator Overloading In this module we will cover Overloading.
Scope. Scope of Names In a small program written by one person, it is easy to be sure that each variable has a unique name In a large program, or one.
Variable Scope. When you declare a variable, that name and value is only “alive” for some parts of the program  We must declare variables before we use.
Memory Management.
Unit 2 Technology Systems
Lesson Objectives Aims Key Words
User-Written Functions
COMPUTATIONAL CONSTRUCTS
Introduction to Programming
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.
Functions Review.
Functions and Procedures
Character (String) Data
Object-Oriented Programming & Design Lecture 18 Martin van Bommel
The what of variables Variables are the combination of an identifying label and a value, often a literal like 2 or "hello world". The label/identifier.
Chapter 5 Conclusion CIS 61.
Programming – Touch Sensors
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Functions BIS1523 – Lecture 17.
Functions and Procedures
Lesson 16: Functions with Return Values
6 Chapter Functions.
Lesson Objectives Aims Key Words
Lesson Objectives Aims You should be able to:
Object-Oriented Programming Using C++ Second Edition
Lesson 5: Building an App: Clicker Game
Variables Title slide variables.
Arrays
Computer Science Testing.
Programming Logic and Design Fourth Edition, Comprehensive
Writing Functions.
Binding Times Binding is an association between two things Examples:
Lesson Objectives Aims Key Words
Tonga Institute of Higher Education IT 141: Information Systems
Chapter 8 - Functions and Functionality
Tonga Institute of Higher Education IT 141: Information Systems
Modules Programming Guides.
3.2 Working with Data Scope of variables 29/07/2019.
10.2 Procedures Passing Parameters 30/08/2019.
Scope Rules.
Presentation transcript:

Lesson Objectives Aims Key Words The difference between global and local variables When it is appropriate to use local or global Implications of using global variables Key Words

Global and Local Variables We already know that variables are flexible spaces that store data as specific types So what is a local or a global variable?

Global and Local Variables We are obviously excellent coders and know that good code is split into modules (functions/procedures) By splitting our code into these modules it becomes much easier to write, debug and understand our programmes They keep it tidy, organised and efficient

Global and Local Variables We should have some variable good practices nailed already – sensible naming with camelCase, correctly declared type etc! However; with a big solution too many variables can become messy You might want to reuse some simple variable names You might be running out of memory with all of those variables This man represents your variables and the sandwich your memory and sanity. He’s going to eat them both.

Global Variables Global variables are more likely to be altered or changed by accident later on in the programme causing unexpected results. In most languages, global variables are declared outside of any class/function/procedure.

Global Variables A global variable is visible to the entire programme…. There’s absolutely no way that you need constant access to all of your variables throughout the entire programme. That just doesn’t happen! To avoid the absolute mess that global variables cause we use local variables throughout our programme. We refer to a variable’s visibility as its scope.

Local Variables Local variables live inside the function/procedure that they were declared inside. The rest of the programme can’t see them When the function/procedure is finished with, they are cleared; freeing up memory So what if we actually do need to use one of these somewhere else in our programme?

Local Variables No need to panic; you can use local variables in different parts of your programme. You simply have to pass variables between different modules – imagine it like a relay, each runner passes the baton on to the next – our baton contains data Socks and sandals

Local Variables Useful tidbit: functions have to return a value whilst procedures (subs in VB) don’t have to VB.net is object oriented, everything is a separate object. As a result it really doesn’t like doing global variables – you really have to force it This is great for your coursework’s efficiency although you still need to be able to define and explain the difference between the two

Have at it

Have at it

Have at it You can use bullet points this one time to save time!

Have at it

Review/Success Criteria You should know The difference between local and global variables When it is appropriate to use global variables The drawbacks associated with global variables You you you oughta know