Friday 7 June 2013

P3/M2 - Explain the fundermentals of Scripting Language



P3 + M2
Introduction
In this blog I am going explain the fundamentals of scripting languages, and how they differ from programming languages. I am also going to talk about the difference between client side and user side programming. Finally I am going to talk about JavaScript and JQuery.


What is a Scripting Language?
A scripting language is a form of programming that is interpreted. Scripting languages are interpreted one command at a time. The scripting languages are usually written to enhance the features of a website. The features are processed on the server but the script on each page runs off the browser.


Why is it different from a programming language?
Scripting languages are simple languages for simple tasks. For example, scripting languages have loops and if statements just like programming languages but for example you can’t do file operations. These are when you can save to the hard disk and open files, scripting languages cannot do this because it can be dangerous if a coder was to write JavaScript into a web page as they could write code to put your personal files on the browser when you open it. This is why it is better to use scripting languages for simple tasks such as Logins and forums, whereas with a programming language you can write operating systems such as Windows 7, Excel and Komodo Edit. This can’t be done in JavaScript as it is not powerful enough.


What do Scripting Languages interpret?
As mentioned earlier scripting languages are interpreted and example one is PERL, PHP and JavaScript and many others. These scripting languages are just text files and require an interpreter in order for the program to be run, just like someone who can’t speak English needs an interpreter. The web browser such as Internet Explorer or Firefox is the one which translates the HTML AND CSS into webpages and programs that we understand.


Client Scripting Languages
There are two main types of scripting languages specifically for web purposes; however there are other scripting languages out there. Client side scripting allows you to interact within a web page. The code which is needed to process user input is downloaded by the browser.

Example 
On the world wide web JavaScript scripts are client side as they are made by your browser (the client). On the other hand CGI scripts are server side because they run on the Web Server.

<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->
Server Scripting Languages
With server side scripting languages, completing an activity requires you to send the code or information to another server (computer) via the internet. The server runs a program which then processes the information and returns the result back, which is usually on the web page.


Example
For example Google, which is a search engine uses server scripting. When a key word is searched a program on the server searches for a match to that word. If this was to be done with client side, it would require a browser to download the whole search engine and index.

Difference between client and server
The difference between client and server with the client side scripting the response to interaction is usually immediate once the program has been downloaded. It is usually more secure than server scripting as you are not sending any information over the server. The processing speed of the user’s computer will affect client scripting.
On the other hand with server side scripting, complex processes are more efficient because the program is not downloaded to the browser. A down side to server side is that you need to have measures in place for security reasons when sending sensitive data online because it will be travelling through servers. Finally the server side will be affected by the processing speed of the host server.


JavaScript
JavaScript is a programming language which is used to make web pages interactive. It is run on the computer of the user when they go onto a website; this means that JavaScript doesn’t need to be downloaded onto your computer every time you go on a website. JavaScript is popular with making quizzes and polls. JavaScript and Java are completely different computer languages as Java is a programming language e.g. for coding operating systems and JavaScript is a scripting language.


Common Tasks JavaScript is used for
Over the years JavaScript has changed. At first JavaScript interacting with website was mainly limited to interacting with forms, such as giving the user feedback and deleting certain things they did. JavaScript libraries are very big these days, they take common actions and simplify the process. This makes the process of coding much easier and saves a lot of time. There are other scripting languages for the web but mainly for the client side JavaScript is used. JavaScript is like a programming language but it is not as powerful but it is very complex, if you wanted to do something quickly such as a roll over menu, you would have to do a large amount of coding.

Example

<script>
document.getElementByid(“Good Morning”).innerHTML=’hello’;
</script>

What is JQuery.
The main purpose of JQuery is to allow you to have the same effect as JavaScript but with much less code to write. In other words JQuery is a quicker version of JavaScript because it is in the library within JavaScript. Many companies such as Microsoft and Google use JQuery. JQuery is used widely to code for websites and it uses HTML and CSS. As the code is already written in the JavaScript library it makes life much easier for programmers.

Example
<script>

$(document).ready(function(){
  $("p").click(function(){
    $(this).hide();
  });
});
</script>

Client Side and their purposes (Validation, User interface)
The main purpose of client side is the validation and user interface of a web page. For example a form, which has been created, it may have a validity check such as a presence check in the field. It is very important that web pages have validation procedures in place so that error from the users is minimised  For example if someone was filling out a form on a website and they missed out their name field, a validation rule could be a presence check which makes sure that the user enters something in the box. Another validation check could be that the website asks the user to enter a certain number e.g. between 1 and 100. This is called a range check and it makes sure that the user doesn't enter a number that is totally off scale. In terms of the performance of the computer, it can be compromised because validation is done by user’s computer and it is done by their browser.

The user interface of any web page is very important. These days we expect something to happen when we click a button or when we go to another page. An example of this is when we hover over a button on Amazon.com the bottom changes colour and flashes. This is a interaction with the user. Another interaction may be, when the user hovers over a picture the picture changes in a slide show. These interactions on a webpage are important as they attract the user to the website and they make the page more interactive and interesting. Google have a classic interaction which is when we search something the results come up as blue and then when we click the link it flashes red, and when you return to your search results the link you previously clicked stays orange. 

The client side environment used to run scripts is usually a browser. The processing takes place on the end users computer. The code is transferred from the web server to the user’s computer over the internet and run directly in the browser. The scripting language needs to be enabled on the client computer. Sometimes the user may switch the scripting facility off because of security issues. When this is the case a message usually pops up to alert the user when script is attempting to run.

Example of Validation (Presence Check) on Client Side:

(While filling in a form you miss out the D.OB. box)

Error Message: Please Enter Blank Field before continuing. 

The above is an example of filling in a form and the user forgetting to enter a value for the D.O.B box. This then causes an error message and it doesn't let the user continue until they fill it in. This type of validation is called a 'Presence Check'.


###############################################################################
REFERENCE


JQuery Example - 10/05/2013 - http://bit.ly/7sKk95


JavaScript Example - 10/05/2013 - http://bit.ly/cGI3Jk


Scripting Language - 10/05/2013 - http://bit.ly/fX6SLd