Variables


We were asked to explore the term we have chosen and try to really understand what it does/means. I think explaining the term Variable and what it encompasses can best be described by answering the three following questions. Each new question moves into a deeper understanding of the term, the first I knew before I started this project the second two moves much further.
What: What is a variable?
A variable is a word or letter/s that represents a number. This number can be changed or updated as the application plays out, thus the name
Why: Why use a variable?
A variable is used to represent a changing number (for example: the distance between mouseX, mouseY  and the centre of the screen) using an long equation could do the same job though however variables can easily repeat an equation many times using less space and making the code more comprehensible in the same process. To summarize: A variable can be used to organise (esp. if using long or complicated equations or lots of code) your code, this can make it more comprehensible and thus easier to edit later or easier for someone unfamiliar with your code to edit it. Similarly it can be use to make your code less comprehensible and thus harder for someone else to mess with your code – if you are that way inclined.
Where: Where should I put a variable instead of using an array or class or something?
This is a question about how a variable relates to others in processing and comparing what would be the most effect of the two. As such, it takes a certain amount of intuition and understands of the nature of variables, as described above, but I will give a small explanation that will most likely have exceptions. A variable should be used anywhere where the code is slightly complex/long  ( if the amount of code used decreases with the use of the variable than you are on the right track, although is not necessary) and uses equations that update or change, so long as a class wouldn’t use less code to do the same thing.

No comments:

Post a Comment