Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson Objectives Aims Key Words

Similar presentations


Presentation on theme: "Lesson Objectives Aims Key Words"— Presentation transcript:

1 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

2 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?

3 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

4 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.

5 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.

6 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.

7 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?

8 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

9 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

10 Have at it

11 Have at it

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

13 Have at it

14 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


Download ppt "Lesson Objectives Aims Key Words"

Similar presentations


Ads by Google