Tuesday 18 November 2014

Suitability of Procedural Languages for Graphical Applications

Procedural Languages are suitable when programming Graphical Applications but they are not the most common languages to use to program Graphical Applications as event driven languages and object orientated languages are more suitable. Event driven languages require an event to happen which is usually a click of a button or a click of a key on a keyboard. Event driven languages usually use graphical applications as the user will probably want a visual display to show a response of the action they did. Object Orientated languages also produce objects that the user can use so you would expect them to use graphical applications for the user to use. Object Orientated languages contain data and functions which will be graphically shown to the user so Object Orientated languages are very suitable for programming Graphical Applications. So even though event-driven and object orientated programming are very suitable for producing graphical applications, procedural are not very suitable. The reasons why procedural languages are not very suitable for graphical applications, is that procedural is about procedures that happen to functions in the code, ie a calculator is mainly procedural programmed as it only requires to show numbers and text and shows the results of functions with text, not graphical images.
As you can see, the example to the left is a binary/hexadecimal converter. As it is a procedural, the code executes line after line. As you can view, there is hardly no graphics at all to this program just three labels and two text boxes. This is a perfect example of why procedural programs are not very suited to graphics and do not need alot of objects in them to function.












Suitability of Event Driven Languages for Non-Graphical Applications

Event-driven languages are very suitable for non-graphical applications. They are also very suitable for graphical applications also but in this blog I am going to explain why they are suitable for non-graphical applications. There alot of electrical systems that everyone uses and could be classed as an event-driven program.

For example, a microwave can be classed as an event driven system; you press a button or turn the timer-knob and the microwave starts heating up your food. This is an example of event-driven application as you get an action from an event. As this event driven system, is fully functional and does the necessary requirements then this makes event driven languages suitable for non-graphical applications.
Another example of why event driven languages are suitable for non-graphical applications are electric/touch hobs. An electric touch hob needs the user to touch the buttons on the hob for the hob to change temperatures. Once the button is touched, the application running the hob would need to make an action happen, due to the event created by the user.


So even though event driven languages are usually used to code graphical programs, such as windows forms or PC operating systems, event-driven languages can be used to create non-graphical applications like a microwave and a hob in the examples above.

Key Features of Event Driven Programs.

Event Driven Paradigm

 Event-driven programming is a programming paradigm which is used when events occur. These events are usually from the user, such as mouse clicks and keyboard clicks. The paradigm makes it easy for the programmer to code the applications as there are two stages to every section of the code, the event that has happened and the action that happens when the event occurs. Once they have coded one section of code to make one event and action happen, they can easily move onto coding the next section.

Examples of event-driven languages

One example of an event-driven language is Visual Basic. Visual Basic allows programmers to make windows form applications which includes alot of graphics for the user to interact with which makes event driven programming very suitable for producing graphical applications.

Another example of an event-driven language is Python. Python is a language which is very simple to use when programming using the event-driven paradigm. There is a large amount of libraries to use when coding in python which makes it general purpose which can be used to code a variety of applications.

Pre-defined Functions

A pre-defined function is a function that is already there to use when coding in a language.
An example of a pre-defined function is StartsWith() which lets you find the character which is first in a particular string. 
Example
String sLocation;
sLocation = “Middlesbrough”;
if (sLocation.StartsWith(“M”) ) {   System.out.println(“You live in a very nice place”);      }
The code above shows the application creating a string called sLocation, setting sLocation as a place, then there is an if statement depending on if the string starts with the letter M.
Another example of a pre-defined function is println() which lets you display the line of text on the screen
Example
System.out.println(“ Hello there, this is a printed line”);


The code above shows the application printing the line of text . The text that is printed is the one placed in the speech marks.

Programming Libraries

A programming library is a library that contains files and functions which can be used in the project you are developing.
An example of a programming library is Swing. The code to import the Swing library into java is:
Import javax.swing.*;

Once you have imported swing, you can use functions like JOptionPane which can load up question messages where users can input text.

Modularity

Modularity in programming is where you split the program into key sectors or different parts. The code for each part does not rely on the other parts code. If you write all your program code in one part then it will not be efficient as some code may have to change which will affect other code. However if you modulated your code so that everything is set into different parts then your code will be more effective.

Global Variables

A global variable is a variable that can be used in all parts of your program. 

"Public Class GlobalVariables                               
                                              
    Public Shared UserName As String = "Tim Johnson"
    Public Shared UserAge As Integer = 39
End Class"

  http://stackoverflow.com/questions/14423568/how-to-have-a-global-dictionary-in-vb-net-wpf-application-to-save-data-from-diff - code reference 



This is an example of 2 global variables declared in visual basic. A global variable is declared in a public class so all forms can use the variables. The first one is declared as a string and is equal to “Tim Johnson”. The second declared variable is an integer which is equal to 39.

Local Variables

A local variable is a variable created which can only be used and defined in the part of the program where you have created it. 

" int iNumber = 10;
   String sNumberinwords = "Ten"
   char cCharacter = 'a'
"
This is an example of creating 3 local variables, an integer, a string and a character. As these are not in a global module, these can only be used in this one section of your application.

Service Orientated 

Service orientated is part of event driven programming. This is where you require a service to happen when you create an event. For example, when you plug in a keyboard or mouse to a USB slot, the operating system will install the drivers needed for the external devices to work. This service is ran in the background.

Time Driven

Time Driven programming is creating programs with timers on them. The programmer would set the amount of time you have to wait for the application to do something. The programmer would have to set the event that would happen after a period of time. For example, dimming the screen is a time driven program as after a certain amount of time, the screen will dim, if set to.

Events

Events in programming are actions that happen. This could be an action caused by a condition that has been met or not met, like an if statement. In event-driven programming though events usually execute due to changes in the mouse position or which keys have been pressed on a keyboard. Once you type something on a keyboard, an event will happen on the computer.

Event Handlers

Events Handlers are the parts of a program that checks to see if an event has happened and if it has then the event handler executes the piece of code which corresponds to the action of the event.

Trigger Functions

For event handlers to manage the actions and consequences of an event, a trigger function needs to occur to describe to the event handler what kind of event has happened. A trigger function occurs when the event has finished.

Parameter Passing

Parameters are the information which variables hold. This could be a Boolean, string or an integer. Parameter passing is when different classes and function swap the parameters over so that they can all use them.

Procedures

Procedures in programming are routines which hold a series of steps and instructions. A procedure can be called to execute in your program. Procedures are the physical implementation of modularity. A procedure will begin and end with the series of instructions inside of them. For example,
Reference : http://pascal-programming.info/lesson7.php
Procedure DrawLine; 
{This procedure helps me to 
 avoid the repetition of steps [1]..[3]}
Var Counter : Integer;

Begin
 textcolor(green);
 For Counter := 1 to 10 do
  Begin {Step [1]}
   write(chr(196)); {Step [2]}
  End; {Step [3]}
End;
Begin
 GotoXy(10,5);
 DrawLine;
 GotoXy(10,6);
 DrawLine;
 GotoXy(10,7);
 DrawLine;
 GotoXy(10,10);
 DrawLine;
 Readkey;
End.

The example above is a program that can draw a line. The procedure is how to draw a line. The begin and end are the actual actions that are going to be executed. The first begin is a loop and another begin is nested in the first one. Then the procedure ends. Then the new begin and end run.




Event Driven Operating Systems

You can create applications and software using three types of programming, procedural, object-orientated and event-driven. The type of programming paradigm I will be explaining in this blog is the event-driven paradigm. Operating Systems are applications which allow you to operate your software and hardware which is inside of your computer. Operating Systems can be referred to as an event driven program. An event driven programming is when the application runs constantly and depends on events happening in order to execute code and functions. These events can happen automatically when timed or manually when the user clicks,types or says something.

An example of why an operating system can be classed as an event driven operating system is when you click on the browser icon to load the browser. This example can be used on the majority of operating systems including Windows, Linux and Android.

For example, when on the android operating system. You tap on the browser icon and the browser will load. This is an event driven operating system as it waits for an action to commence.


This is an example of event driven operating systems. The desktop screen will remain constant until the user interacts with the system causing a consequence. Due to the tapping of the chrome icon in the example, the Chrome Browser will load.










Another example of how operating systems are classed as event-driven is the downloading/saving of a file. When you click the save button or the download button on either a browser or on a local application, it causes the file to be written to a sector in a hard drive.

An example of this event happening is shown in the Linux operating system, Ubuntu. It tells you the file name and location and gives you the option to cancel the download or add the file to your computer. If you click the add button then you are triggering the event of saving the file.



A final example of how an operating system may be viewed as an event-driven program is the dimming of a display. Events are usually made or influenced by the user but some events can happen automatically. For example when an operating system is and has been ran for a certain length of time, the screen may dim and eventually turn its display off. This event happens at the time when the operating system is set to do. If your operating system is set so that your display dims after 30 minutes and then turns itself off after 1 hour, these are events happening over a period of time.
The example of a windows operating system dimming the display is shown below.


The example above shows the event of the operating system being started, then left for 30 minutes, then the screen turning itself off after 1 hours use.






Monday 10 November 2014

Key Features of Procedural Programs

Procedural Programming Paradigm

Procedural Programming is a paradigm which programmers use to create a structured program. Procedural Programmed applications tend to use procedures (routine of steps) to collaborate and run effectively.

Examples of procedural  languages

One example of a procedural language is C. C or versions of the C programming languages allow the programmer to create steps for the program to follow and carry out. It executes each bit at a time. The code to run a function has to look at what the function does and once you have the code for what it does then it will execute and continue onto the next step. C is one of the most popular languages and has similar programming language derivatives such as C++ which is used in android programming.

Another example of a procedural language is Pascal. Pascal was invented around the time of when personal computers were first made.  Pascal is a high-level language, like C so the code has to be translated so the computer can understand and execute it.

Pre-defined Functions

A predefined function is a function that is already there to use when coding in a language.
An example of a pre-defined function is StartsWith() which lets you find the character which is first in a particular string. 
Example
String sLocation;
sLocation = “Middlesbrough”;
if (sLocation.StartsWith(“M”) ) {   System.out.println(“You live in a very nice place”);      }
The code above shows the application creating a string called sLocation, setting sLocation as a place, then there is an if statement depending on if the string starts with the letter M.
Another example of a pre-defined function is println() which lets you display the line of text on the screen
Example
System.out.println(“ Hello there, this is a printed line”);


The code above shows the application printing the line of text . The text that is printed is the one placed in the speech marks.

Programming Libraries

A programming library is a library that contains files and functions which can be used in the project you are developing.
An example of a programming library is Swing. The code to import the Swing library into java is:
Import javax.swing.*;

Once you have imported swing, you can use functions like JOptionPane which can load up question messages where users can input text.

Modularity

Modularity in programming is where you split the program into key sectors or different parts. The code for each part does not rely on the other parts code. If you write all your program code in one part then it will not be efficient as some code may have to change which will affect other code. However if you modulated your code so that everything is set into different parts then your code will be more effective.

Global Variables

A global variable is a variable that can be used in all parts of your program. 

"Public Class GlobalVariables                               
                                              
    Public Shared UserName As String = "Tim Johnson"
    Public Shared UserAge As Integer = 39
End Class"

  http://stackoverflow.com/questions/14423568/how-to-have-a-global-dictionary-in-vb-net-wpf-application-to-save-data-from-diff - code reference 

This is an example of 2 global variables declared in visual basic. A global variable is declared in a public class so all forms can use the variables. The first one is declared as a string and is equal to “Tim Johnson”. The second declared variable is an integer which is equal to 39.

Local Variables

A local variable is a variable created which can only be used and defined in the part of the program where you have created it. 

" int iNumber = 10;
   String sNumberinwords = "Ten"
   char cCharacter = 'a'
"
This is an example of creating 3 local variables, an integer, a string and a character. As these are not in a global module, these can only be used in this one section of your application.

Procedures

Procedures in programming are routines which hold a series of steps and instructions. A procedure can be called to execute in your program. Procedures are the physical implementation of modularity. A procedure will begin and end with the series of instructions inside of them. For example,
Reference : http://pascal-programming.info/lesson7.php
Procedure DrawLine; 
{This procedure helps me to 
 avoid the repetition of steps [1]..[3]}
Var Counter : Integer;

Begin
 textcolor(green);
 For Counter := 1 to 10 do
  Begin {Step [1]}
   write(chr(196)); {Step [2]}
  End; {Step [3]}
End;
Begin
 GotoXy(10,5);
 DrawLine;
 GotoXy(10,6);
 DrawLine;
 GotoXy(10,7);
 DrawLine;
 GotoXy(10,10);
 DrawLine;
 Readkey;
End.

The example above is a program that can draw a line. The procedure is how to draw a line. The begin and end are the actual actions that are going to be executed. The first begin is a loop and another begin is nested in the first one. Then the procedure ends. Then the new begin and end run.

Parameter Passing

Paramters are the information which variables hold. This could be a boolean, string or an integer. Parameter passing is when different classes and function swap the parameters over so that they can all use them.
if - an 'if' in programming is a statement used to start a condition and a consequencing action. A condition is set and if the condition is true then you will run code to perform an action. For example,
if(iNumber == 10){System.out.println("Your Number is 10")}; is a piece of code which uses an if statement, in this case if the number is equal to 10 then display the text "Your Number is 10".

else - an 'else' in programming is a piece of code which allows an action to be performed if the an if statement is false. For example, you can add an else statement to the example code above. Eg.
if(iNumber == 10){System.out.println("Your Number is 10")};
else{System.out.println("Your Number is not 10"); }
Now the code has two actions, one if the condition is true and one if it is false.

else if - an 'else if' statement is used to create multiple if statements in one section of a program. For example,  if(iNumber == 10){System.out.println("Your Number is 10")};
 else if(iNumber == 13){System.out.println("Your Number is 13")};
 else if(iNumber == 15){System.out.println("Your Number is 15")};
else{System.out.println("Your Number is not 10,13 or 15"); }
means that if the number is 10 then say your number is 10, if your number is 13 then say your number is 13 and if your number is 15 then say your number is 15, if it is not any of them then say your number is not 10,13 or 15.
for -  a 'for' is a loop which can be used in programming. It is used when you know how many times you want a particular action to repeat itself. For example,
you set and create a variable in the first section of your brackets so you could create an integer called iNumber and it is equal to 1. The next part of the bracket would be, when to stop the part of the program so you could say stop the program when iNumber is equal to 5 and the last part of the bracket you would set it to what happens to the integer each time it loops, so you could say iNumber = iNumber + 2. Your code would look like
for(int iNumber = 1; iNumber = 5; iNumber = iNumber +2){'your action would be set in these curly brackets};
Everytime the code loops, 2 will be added to iNumber so 1 +2 = 3 which is not equal to 5 so loop again. So iNumber is equal to 3 so 3 + 2= 5 which is the desired number so the prgram would stop.
int - int is used to create a variable which is an integer (a whole number). For example the code, '
int iNumber' creates an integer variable which is called iNumber.
char - char is used to create a variable which is a character (one letter, number or symbol). For example the code,'char cCharacter1; creates a character called cCharacter1.
String - String is used to create a variable which is a piece of text. For example, the code,'String sWord' creates a string called sWord and can be set to a line of text or a word.
Double - double is used to create a variable which is a number which can have decimals in it. For example, the code,'Double dPrice' creates a double variable called dPrice and can have decimals such as '1.56'.
Boolean- A boolean is a variable that can either be true or false. For example, the code, 'Boolean bOver50' creates a boolean called bOver50 and that can either be true or false so you can or cannot be over 50.





Modular Elements Are Important

Why are modular elements important in procedural programming?

Procedural Programming is a programming method which is used to create structured applications. Modular Elements or Modules are sections of code which execute a different function. Modular Elements run individually in each section of code, so when these modular elements are put together in a sequence, running one after another, they will create a structured program. Even though these sections of code work together, they do not rely on each other as some parts of the code may change another part. You can have a class to perform a large function but modularity is important as it takes the little steps from the large function and uses and manipulates the little steps.

Here we have the humanbeing class.

The code to the side shows the steps how to create a human being in java. You have to set some attributes to a person. In this case you set the Name, Sex,Origin,Height, Weight, Skin Colour and Age. All of these attributes have been set to have a parameter.





Even though we have set these variables to have a certain parameter, we can also use these variables in another class to do something else.

 We have set the varible sName to 'Nathan'. We can use the setName function which makes teh sName parameter,'Nathan', to equal sNewName. So even though we used a function called setName, we could use this function to do something else.


Modularity is not just incorporated in programming languages. Modularity can also be used to show the steps in the real world. For example, Modularity can be used to show the steps of going to school. You can say that the thing you are doing is going to school. However, the actual things that you are completing are the steps which take you there. The following steps show you how you might get to school;

  1. You need to wake up/get out of bed
  2. You need to eat your breakfast
  3. You need to wash yourself
  4. You need to get dressed
  5. You need to gather your school belongings
  6. You need to leave the house
  7. You need to travel to school
  8. You have now got to school.