Programming logic is a quick description of the flow of your program.
A very simple program logic may be
IF ITEM_PRICE < BANK_BALANCE THEN
Before we write the program above we need to identify what is data and what is language associated with the programming language.
Data would be BANK_BALANCE (that is a number) and ITEM_PRICE is a number too.
“IF” and “END IF” are commands available in this program. When dealing with data you can assign the data to a variable name, for example your bank balance (a number) can be saved in the variable MyBankBalance and your credit card balance can be saved in a variable called MyCreditCardBalance.
There are different types of variables used in Visual Studio 2010 – Visual Basic.
Bits: 0 or 1 (True or False)
Byte: -128 to 127
String: any text you can think of.
Short: -32,768 through 32,767.
Long: -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807
Decimal: -79,228,162,514,264,337,593,543,950,335 through 79,228,162,514,264,337,593,543,950,335
There are other types but you can read about them here: http://msdn.microsoft.com/en-us/library/ae55hdtk.aspxIf you have to choose one type of variable choose a string as it can hold almost anything.
With numbers try and use the variable with the smallest maximum to save using too much memory (e.g. If you were creating a variable to hold ones age use a Byte, if you were creating a variable to hold a bank balance use a Decimal over an integer mostly because Decimals allow decimal points where Integers round off anything after a decimal point.
Now what we have our programming logic decided our programming variables how can we optimize my program. Let’s say we want to check our primary bank balance then our secondary bank balance if the primary bank balance does not have enough money. If we duplicated the code that checks the bank balance that would work but the code would get twice as big. What we need to do is move the code that checks the bank balance into a FUNCTION called “CHECK_BANK_BALANCE” and pass in the name of the bank account to check. No we can check 1, 2 or 2000 bank balances without duplicating code.
The new code might look like
IF ITEM_PRICE < CHECK_BANK_BALANCE(BANK_ACCOUNT_NUMBER) THEN
The code above is not perfect, we do not have a breakdown of the check price function but pseudo code allows you to flesh out the structure of your program before you start coding.
Another alternative to using a function may be to use a “Sub” (Subroutine), A subroutine is like a function but it does not return any data. You could use a sub routine to deduct an amount from a bank balance and not return the bank balance when done.
- Pseudo code allows you to flesh out your program. If you have an idea just write our the pseudo code, review and optimise it. When you are happy with the flow, choose a suitable software language and start turning the pseudo code into real code.
- Variables are used to hold data.
- There are variables for text, numbers etc.
- Use FUNCTIONS instead of duplicating code.