Software Development

  Lecture Notes

Programming Languages

Introduction

A Brief History

Examples of Programming Languages

Which is the Best Programming Language?

Choosing a Programming Language


Introduction

Objectives

This guide will help you to understand: -  

·  why the many different programming languages were developed

·  how different programming languages are suitable for different tasks.


A Brief History

Many different programming languages have been developed over the years. However, when the first electrical digital computers were created in the 1940's, they were programmed using machine language code. To give you an idea of machine code, let's look at an example. The following machine code adds the value in memory locations 0000 and 0001 and places the answer in location 0010. In other words, it adds two numbers.

0001 0000 0011 0001 0000 0010 0100

(0001 0000) means load contents of 0000 into the accumulator

(0011 0001) means add contents of 0001 to the accumulator

(0000 0010) means store the accumulator value in memory location 0010

(01000) means halt

As we can see, machine code is cumbersome to write, so a more human-readable form of machine language code was developed and it was called Assembly. The example below shows how two numbers would be added together using Assembly.

mov ax, [si]; this means load [si] into ax

add [bx], ax; this means add to [bx]

We can see that Assembly uses more human-friendly words, such as mov (means move) and add. However, as with machine code, programmers must still deal with low-level details such as CPU register allocation. As a result, it is still difficult to write and maintain large programs using assembly language. So, during the late 1950's, the first human-friendly programming language was invented and it was called FORTRAN.

Human-friendly programming languages are known as high-level languages. High-level languages are easier to write and understand than lower-level languages and allow applications to be developed much more quickly. The drawback is that a high-level language has to be converted (compiled) to machine code before it will run. Also, low-level languages such as Assembly invariably run faster.

Anyway, after FORTRAN appeared, many more high-level languages were developed, each with their own grammar and syntax, (just like the many human languages.) One of the most popular languages that emerged during the 1970's was the C programming language; developed by AT&T Bell Laboratories. An object-orientated form of C called C++ was developed as an extension to C during the early 1980's. Visual Basic and Java were also developed around this time. Finally, with the growth of the World Wide Web, scripting type programming languages such as Javascript and PHP were developed, allowing code to be executed through web browsers. These days there are a vast number of different programming languages to choose from and new languages are being developed every day.

Here are some of the many programming languages -->>

Assembly, Pascal, COBOL, Lisp, Basic, Prolog, C, C++, Java, Visual Basic, VB.Net, Delphi, C#, Prolog

Here are some scripting languages -->>

Javascript, Perl, PHP, ASP, VBScript, Bash, DOS, Python

~~Activity~~

Activity A

What type of programming language are you?

What type of programming language are you? Are you slow, quick, sturdy, old-fashioned or just plain weird? Find out by answering questions on this site.

When you have finished, you can look at a the different possibilities.

 


Examples of Programming Language

Many different programming languages have been developed over the years. Here is a short description of some of the most popular languages.

C is one of the oldest of programming languages. It became extremely popular because it was so powerful and allowed programmers to control computer hardware at an extremely low level. Thus, many Operating Systems were written in C; for example, Windows, Unix, Linux. As one of the most pervasive of languages, there are even benefits to learning C today. Many scripting languages such as PHP use C type syntax, making them easy to learn if you already know C. Today, the successor to C is C++, which is an object-orientated version of C.

Visual Basic is a Microsoft product which was first released in 1991. It succeeded the BASIC programming language of the 1980s. It was developed to suit the Windows environment with it's event-driven graphical user interface. An event-driven language is organized around a series of events. Each time an event happens (for example, a mouse click), an event-driven program responds with a procedure associated with that event. The latest form of Visual Basic is VB.Net, which has a more object-oriented focus. Due to the predominance of the Windows Operating System, VB.Net has become extremely popular.

Java is an object-oriented programming language developed by Sun Microsystems in the early 1990s. Learning Java is critical if you are non-Microsoft. The beauty of Java is that it is the most portable of programming languages. If you need to write an application that runs on different types of systems, Java is probably the best choice.

PHP is an open-source, server-side, cross-platform, scripting language, especially well-suited for Web development as it can be embedded into HTML pages. Unlike JavaScript, PHP code is executed on the server and the results are sent to a user's browser. Server side scripting languages like PHP are commonly used whenever a connection to a database is needed. For example, any e-commerce site that stores customer and product information in a database will use some form of server-side scripting to access the database.

JavaScript is a scripting programming language that runs in the Web browser on the client side. JavaScript is similar to Java but has a simplified set of commands. It is easier to code than Java and doesn't have to be compiled into machine code before being run by a browser. Javascript is used extensively on the Web to validate forms, create cookies, detect browsers and interact in many other ways with users.

~~Activity~~

Activity C

Javascript Clock Example

To create your own JavaScript clock...

  1. Copy the code below into notepad.
  2. Save the notepad file as "clock.html", including the quotes.
  3. Double-click the file to open the HTML file in the browser

The code is between the dotted lines below
.....................................................

<html>
<head>
<title>Javascript Squares</title>
<SCRIPT LANGUAGE="JavaScript">
function runClock() {
var d,h,m,s;
d = new Date();
h = d.getHours();
m = d.getMinutes();
s = d.getSeconds();
if (h <10) h="0" + h;
if (m < 10) m="0" + m;
if (s < 10) s="0" + s;
var clocklocation = document.getElementById('digitalClock');
clocklocation.innerHTML= h + ":" + m + ":" + s;
window.setTimeout("runClock();",1000);
}
</SCRIPT>

</head>

<body onload="runClock();">
<p>My first Web page with a JavaScript clock.</p>
<div ID="digitalClock" STYLE="font-size: 30px"></div>
</body>

</html>

.....................................................

Note: The actual JavaScript code is shown in red. Everything else is pure HTML. If you removed all the JavaScript, you would be left with a standard HTML web page.

 


Which is the Best Programming Language

People often ask 'Which is the best programming language?' However, there is no simple answer to this question.

If you are learning a language for the first time, then Pascal or VB is a good choice since they are relatively easy to learn and you will learn the fundamentals of programming. Fundamentals of programming are concepts that apply to all languages, and learning them will make it easier for you to learn other languages. Although Pascal and VB are good beginners languages, there is nothing stopping you from using them for writing commercial software, except you should realise that they are not the strongest languages around. Today, the main drawback of both Pascal and VB is that they are not Object Orientated. Object Oriented Programming (OOP) is a programming method that was developed during the nineties. OOP is well suited to graphical windowing applications because of the ease with which you can reuse code. Examples of OOP languages are Java, C++ and VB.Net.

If you are a Web Developer, then there are many web scripting languages to choose from. Some scripting languages, such as JavaScript, execute in the user's browsers. Others, such as PHP, ASP, Cold Fusion, JSP, can interact with databases and these tend to execute while still on the server, before transferring the results to the user's browser. This is quite common with e-commerce sites. Personally, I like PHP since it is flexible and powerful. Moreover, it is open source (which means it is free), and will run on many different types of web servers.

Another popular language used on the web is Java. Java applets are fairly common found on the Internet because they can run on just about every different type of client system going; - Windows, MAC, Unix, Linux and many other. Java can also be used for writing desktop applications. The main drawback with Java is that it is slow.

Just for the record, HTML is not actually a programming language. It is a layout language. You use HTML to tell a browser how a web document should be layed out. You cannot write programs with HTML.

Finally, even if you are not a programmer, it still may be useful for you to learn a scripting language. Let's suppose you are a Systems Administrator, then you would be advised to learn one or more system scripting languages. Scripting enables you to automate tasks such as backups, login procedures, and helps you manage systems in so many different ways. On Unix/Linux based systems you would want to learn Perl or Bash or even C, (since C is the language these operating systems are written in.) On Windows based systems, learning DOS scripting or VBScript would be useful.

There is one point to remember always, never get fixated on one or two languages. Today, Java, C++ and VB.Net are popular. In 10 years time, other new languages will be the 'in thing'. One thing is for sure, programmers and systems administrators will encounter many different languages over the course of their careers.

~~Activity~~

Activity C

DOS Command-Line Scripting Example

DOS is a command-line environment, and batch files are scripts capable of automatic task execution thus providing additional power in controlling system processes.

To see an example of command-line scripting...

  1. Copy the code below into notepad.
  2. Save the notepad file as "name.bat", including the quotes.
  3. Double-click the file to run the program

The code is between the dotted lines below
.....................................................

@echo off
set /p _name=Enter your name:
echo.
echo Hello %_name%!
echo.
set _name=
pause

.....................................................

To see a second example of command-line scripting...

  1. Copy the code below into notepad.
  2. Save the notepad file as "count.bat", including the quotes.
  3. Double-click the file to run the program

The code is between the dotted lines below
.....................................................

@echo off
echo This program counts from 0 to 9
echo.
pause
set _number=0
set _max=10
:Start
if %_number%==%_max% goto end
echo %_number%
set /a _number=_number + 1
goto start

:end
set _number=
set _max=
echo.
echo All Done
pause

.....................................................
 

 

Choosing a Programming Language

Software is a very competitive business. A company that gets software written faster and better will, all other things being equal, put its competitors out of business. So, when a client wants an application to be developed, how does one decide on the best programming language to use?

There are a number of considerations when choosing the most appropriate language for a job. You also have to consider programmer productivity, development cycle, portability, efficiency, maintainability, tool support, and software and hardware interfaces. The choice should also be made based on overall goals. There is no "best" programming language; the suitability of a language depends on the problem to be solved for the client.

Here are a few basic things to consider when choosing a programming language to meet a user's needs:-

  • Is the program going to be online
  • Is it going to run on one particular system only or does have to be portable.
  • Does it need to link to a database
  • Is it going to be a small or large program
  • Does it need to be run critically fast
  • Is it going to be a modular program that will link to other modules.
  • Does it need a GUI

After clarifying the points above, you would then consider the advantages and disadvantages of each language in turn and hopefully find the most suitable.

Language Advantages Disadvantages

Assembly

If you need a fast program Assembly is the way to go. Since the code is close to machine language, a program written in Assembly will run faster compared to when it's written in a high-level language.

Assembly is difficult to learn .

Code is not very portable between different systems.

Developing a program can take a long time


Visual Basic

Code is human-friendly

Can quickly create GUI's

Relatively easy to learn

Code is not portable to non-Windows systems.

Not as powerful as some other languages such as C or C++


C/C++

Code is human-friendly

Relatively portable between different operating systems.

More difficult to learn than VB.

Code is only portable if the standard API's are used


Java

Code is human-friendly

Extremely portable between different operating systems.
This is why you find so many Java applets on the Internet.

Fairly difficult to learn.

Slow code execution compared to other languages because it is only half-compiled to machine code. This is what makes it portable.


Javascript

A scripting language, typically embedded into web pages for interaction with users.

Easier to learn than Java

You frequently have to add extra code so that the code works in the different web browsers.

Only useful for web programming


PHP

A scripting language, typically embedded into web pages and usually linked to a server-side database.

Similar to C, so if you know this language then PHP is easy to learn

The code can become muddled up with HTML and so it is not easy to make design changes to the web site.

Only useful for web programming.

As we can see from the table, different languages are good for different things. Some languages are well suited to certain kinds of tasks while they are unsuitable for others tasks. Some languages produce programs that run fast, such as Assembler or even C. Some languages can produce programs that run on a variety of platforms, such as Java.

If you are writing desktop software, there will be a strong bias toward writing the application in the same language as the operating system. On Unix and Linux systems this would be C or C++. On modern Windows based systems, this may be VB.Net. However, a lot of software is now written to work on the web and so scripting languages are also a big thing.

Every client and every program is different. Choosing the correct programming language to use is extremely critical. Of course, you may not always get the choice if your task consists of modifying or extending an existing application.


Fini
 

 

 

   

  Unit Information

Assessment

Syllabus

Scheme of Work

Notes &Tutorials

Assignments

Quizzes

Books & Things

Links