You are on page 1of 8

Faculty of

Management
Studies and
Commerce
P.G.G. Lanka
This documents Briefs about different
categories of programming and basics about
computer programming

Department of It

Faculty of Management
Studies and Commerce

University of Sri
Jayewardenepura

Sri Lanka

3/1/2014
Faculty of Management Studies and Commerce March 1, 2014

“It’s not at all important to get it right
the first time. It’s vitally important to
get it right the last time”

-Andrew Hunt and David Thomas-
Faculty of Management Studies and Commerce March 1, 2014

Computer Programming &
Programming Languages
Contents
1 Introduction to programming .............................................................................................................................. iii
1.1 What's a Program........................................................................................................................................ iii
2 Programming Languages ..................................................................................................................................... iv
2.1 Generations of Programming languages...................................................................................................... v
2.1.1 Machine language ............................................................................................................................... v
2.1.2 Assembly language .............................................................................................................................. v
2.1.3 High level languages ........................................................................................................................... vi
2.1.4 The organization of the programming languages. ............................................................................. vi
Faculty of Management Studies and Commerce March 1, 2014

1 Introduction to programming
Programming is the process of writing instructions for computers to produce software for users. It's the
combining of minute details to form a cohesive whole. More than anything, it is a creative and problem-
solving activity. The problem solving aspect of programming will become self-evident as we move
forward. For now, I'd like to talk about the creative side.

At a high level, it's obvious that creating software requires creativity. You are building something for
people to use. It must therefore be clever without being complex. It must be intuitive and elegant. What
isn't obvious to most people is that creativity plays an equally important role at the micro level of building
software. Every instruction that you type requires consideration. In this respect, I've always likened
programming to writing a book or painting a picture. Ultimately you have a finished product, but it's the
sentences and the strokes, and how they are combined, which is where the book, painting or program
truly comes to life.

I sincerely believe that programming is a beautiful thing. However, I warn you that learning to program
isn't trivial. You should be able to learn the basics with relative ease. Unfortunately, going from these
basics to being able to write a useful program isn't easy. In fact, it can be quite frustrating. I tell you this so
that you know what to expect, not to discourage you. How far you take this journey is up to you, this is
but a start.

1.1 What's a Program
You already know what a program is. You use an email program, surf the web in a browser and interact
with various websites every day. You text, take pictures, and check the weather on your phone. A
program is the output, or goal, of programming.

Much like a book is made up of chapters, paragraphs, sentences, phrases, words and finally punctuation
and letters, so too is a program broken down into smaller and smaller components. For now, the most
important is a statement. A statement is analogous to a sentence in a book. On its own, it has structure
and purpose, but without the context of the other statements around it, it isn't that meaningful.

A statement is more casually (and commonly) known as a line of code. That's because statements tend to
be written on individual lines. As such, programs are read from top to bottom, left to right. You might be
wondering what code (also called source code) is. That happens to be a broad term which can refer to the
whole of the program or the smallest part. Therefore, a line of code is simply a line of your program.

I think this would be a good time to introduce our first little program. There are more concepts and terms
to learn, but it will be useful to have something to visualize.

deck = ["2 of Hearts", "3 of Hearts", "4 of Hearts", "5 of Hearts"]
shuffled_deck = shuffle(deck)
first = shuffled_deck.first
print first
Faculty of Management Studies and Commerce March 1, 2014

Although it's rather short, there's a lot going on here. We won't go into any of this in great detail. For now
what's important is that our program is made up of four lines of code and that the program is read from
top to bottom. The purpose of this program is to pick a random card from a partial deck.

The first line collects a limited number of cards into a container, our deck. Next, we shuffle the deck.
Finally, we pick the first card (which at this point could have any value) and print it out on the screen. You
might be tempted to analyze this deeper. For example, maybe you are curious about the meaning of the
square brackets [] in the first line of code. Or maybe you're wondering about the implication of the equal
sign =. Those are all things we'll eventually cover. For now, this is a program made up of four lines of code
which create a deck, shuffles it, picks the first card and prints it.

There are a lot of ways to write this program. The approach shown above is similar to how it works in the
real-world, which makes it easy to understand. This is where creativity, at a micro level, comes into play. A
good programmer wants to write code which is understandable to other programmers (and to his or her
future self), which is correct (or bug free), and which performs efficiently. Balancing these three aspects of
programming is fundamental. But there's no shortcut to mastering this, one must learn through
experience.

2 Programming Languages
We have an idea of what a simple program looks like: a collection of lines of code. But that's still quite
vague, so let's peel away the layers.

When you write a program you do so using a programming language. A programming language defines
the syntax that you use to write your program. In our above example, we used square brackets [] to group
together our cards. A different programming language might insist that you use parenthesis (). We used
print to output the picked card, while another language might use echo . You could say that different
programming languages are like different spoken and written languages. The same book written in
different languages tells the same story; much like a program written in different programming languages
would have the same purpose. However, programming languages tend to be more similar than dissimilar
and a more accurate comparison might be to dialects.

Programming languages define more than just the syntax, but for now, that's all we'll concern ourselves
with. Thankfully even though some languages are vastly different than others, most share a lot of
common ground, so that once you know your first language, other languages are much easier to pick up.

The processor in your computer, or smartphone, doesn't know anything about a deck, card or even about
printing something on the screen. These processors speak a basic language and require detailed
instructions on what to do and how to do it. Writing our above sample in this low-level language might
require 50 or more individual statements, none of which is obvious to read or write. This means that on
the one hand, you have programming languages that humans can understand, on the other you have
languages that computers understand. What's needed is a translation process to go from the code that
we write, to the code that a computer reads. This process is known as compiling your code. A compiler
Faculty of Management Studies and Commerce March 1, 2014

takes your high-level program as input and outputs a low-level program which your computer will
understand.

Even as your knowledge progresses, you'll probably never have to know the details of assembly or
compilers. They are both advanced topics which an increasingly rare number of programmers focus on.
Why bring it up at all then? First, because learning to program is more than learning the correct sequence
of statements to write down. It's also about understanding, even at a high level, the metamorphosis of
your code from what you write to what ends up actually being executed. Secondly, and more importantly,
it introduces the important topic of abstraction.

We've already seen that the code we'll write and the code that the CPU will execute aren't the same
thing. The details of assembly are abstracted away from us by the compiler. This is only one of many
layers of abstraction. These layers of abstraction help programmers deal with the ever-increasing
complexity of programming. It's abstraction that makes it possible for us to write a few understandable
lines of code to shuffle a deck, without having to worry about the various building blocks which others
have provided for us; like, how does shuffle randomly mix up our deck? But abstractions aren't perfect,
and ignorance isn't always bliss. Sometimes a lower level concept will break through the abstraction.
Sometimes we'll need to get our hands dirty to achieve what we want.

The point is that while we'll focus on writing programs using modern techniques, know that there's entire
foundation which makes it all possible. Sometimes, those underlying elements will become visible, say by
means of a cryptic error message. Also, rather than sugar-coating what programming is, you now
hopefully have a more meaningful sense of it beyond simply being a list of written statements for the
computer to follow.

2.1 Generations of Programming languages

2.1.1 Machine language
Machine code or machine language is a set of instructions executed directly by a computer's central
processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or an ALU
operation on a unit of data in a CPU register or memory. Every program directly executed by a CPU is
made up of a series of such instructions.

Numerical machine code (i.e. not assembly code) may be regarded as the lowest-level representation of a
compiled and/or assembled computer program or as a primitive and hardware-dependent programming
language. While it is possible to write programs directly in numerical machine code, it is tedious and error
prone to manage individual bits and calculate numerical addresses and constants manually. It is therefore
rarely done today, except for situations that require extreme optimization or debugging.

Almost all practical programs today are written in higher-level languages or assembly language, and
translated to executable machine code by a compiler and/or assembler and linker. Programs in
interpreted languages such as BASIC, MATLAB or Python are not translated into machine code; however,
their interpreter (which may be seen as an executor or processor) typically consists of directly executable
machine code (generated from assembly and/or high level language source code).

2.1.2 Assembly language
An assembly language is a low-level programming language for a computer, or other programmable
device, in which there is a very strong (generally one-to-one) correspondence between the language and
Faculty of Management Studies and Commerce March 1, 2014

the architecture's machine code instructions. Each assembly language is specific to a particular computer
architecture, in contrast to most high-level programming languages, which are generally portable across
multiple architectures, but require interpreting or compiling.

Assembly language is converted into executable machine code by a utility program referred to as an
assembler; the conversion process is referred to as assembly, or assembling the code.

Assembly language uses a mnemonic to represent each low-level machine operation or opcode. Some
opcodes require one or more operands as part of the instruction, and most assemblers can take labels
and symbols as operands to represent addresses and constants, instead of hard coding them into the
program. Macro assemblers include a macroinstruction facility so that assembly language text can be pre-
assigned to a name, and that name can be used to insert the text into other code. Many assemblers offer
additional mechanisms to facilitate program development, to control the assembly.

2.1.3 High level languages
In computer science, a high-level programming language is a programming language with strong
abstraction from the details of the computer. In comparison to low-level programming languages, it may
use natural language elements, be easier to use, or may automate (or even hide entirely) significant areas
of computing systems (e.g. memory management), making the process of developing a program simpler
and more understandable relative to a lower-level language. The amount of abstraction provided defines
how "high-level" a programming language is. Examples of high-level programming languages include Java,
Lisp, R, Python, Visual Basic and Ruby.

The first high-level programming language designed for computers was Plankalkül, created by Konrad
Zuse.[2] However, it was not implemented in his time, and his original contributions were largely isolated
from other developments (it influenced Heinz Rutishauser's language "Superplan").

In the 1960s, high-level programming languages using a compiler were commonly called autocodes.
Examples of autocodes are COBOL and Fortran.

2.1.4 The organization of the programming languages.
1. The language that is closest to hardware is machine language. High level languages are the
farthest from hardware as illustrated in Figure 1:Figure 2 : Arrangement of Programming
Languages.

Appendix

Computer languages have evolved into four generations now. The term computer language denotes a
high-level language like C, and C++. They have a unique set of keywords that the program understands.
The first generation computer languages were written as 0s and 1s (binary) but it was difficult to
interpret, resulting in errors. The second generation computer languages were simpler, involving
percentages and symbols. The third generation languages like C, C++, and Java indicated the evolution of
programming that was typically tough to write but people were more inclined to learn them. 50 years
back, computer programmers were writing codes. Now, new technologies are emerging and developing at
a very rapid speed. Today, there are more than 2000 documented programming languages. Here’s a look
at some of the most relevant computer languages
Faculty of Management Studies and Commerce March 1, 2014