What is computer? and it's relation to programming - PROGRAMMING FOR BEGINNERS: All Concepts Explained (2016)

PROGRAMMING FOR BEGINNERS: All Concepts Explained (2016)

1. What is computer? and it's relation to programming

Programming can not exist if there were no computers available. Computers are by definition programmable devices, which can be programmed to perform various kinds of tasks. Computers are devices for which programs are written. So, it is essential for any programmer to have some knowledge about computers; the level of knowledge needed to be successful programmer depends on what kind of programming you do; for example, if you write programs that precisely control hardware, such as drivers or operating systems, then you need to know about computers more than you would if you were just some program user. The following sections provide you with the basic informations about computer hardware.

1.1 Memory

Memory is very important device in computer, and in programming world also. Every program that runs on computer uses some amount of memory space. Memory is used to temporarily store data created by programs and Operating Systems. Memory devices are faster than storage devices, and they can store data as long as electricity is provided; what that means is that data stored in memory devices is destroyed when computer is powered off. Memory is also used for security reasons; for example, data which is private and needs to be destroyed on computer power off can be stored in memory.

There are two major types of memory, although other types also exist but are not common. The most common (and important for both computer and for programming world) type of memory is called Random Access Memory (RAM for short). It is separate device in all computers which can be replaced with same type of RAM but with larger memory capacity, for example. RAM was and has much small amount of storage capacity than hard disk, which is primary storage device for computers. For comparison, typically at this time of writing hard disk capacity can be 500 Gb while RAM capacity can be only 4 or 8 Gb. Low level programming languages allow to precisely access and read data from RAM. It is important to know that many books and materials refer to RAM when they write "memory". RAM has memory locations, which are identified by their specific addresses and can store small amounts of data, but several memory locations can be used simultaneously to store large amounts of data.

Another common type of memory is cache. Cache is faster than RAM and also has much small storage capacity than RAM, because producing materials for creating cache memory devices are expensive. Cache memory is not available as separate device in computer, it is located inside CPU. Compared to RAM, it is used for storing somewhat specific types of data, such as storing next instruction which CPU should execute. It helps CPU calculate faster because it is physically located very near to CPU and can provide data needed by the CPU in a very fast speed.

1.2 Central Processing Unit (CPU)

Central Processing Unit (for short, commonly called CPU) is a part of computer responsible for all calculations. CPUs are available in various speeds and at various prices. Today, there are very fast and powerful CPUs that can be used to run calculation intensive programs quite easily.

1.3 Storage devices

Storage devices are used for permanently storing digital data (i.e. 0s and 1s). Storage devices differ from RAM and other memory devices in two ways: they are faster, and they store data permanently instead of until power is on, like memory devices. There are several kinds of storage devices (hard disk, USB flash drive, optical disc etc.), and different technologies are used for storing digital data, such as flash and magnetic technologies; but, it is essential to know that they are all designed to store same kind of data - digital data. Programming languages have functions to save data as files on storage devices.

1.4 Files and folders

Computer files are essentially string of 0s and 1s, which can represent some kind of information; for example: image, audio, video, text or other kind of information. Files can be of any size, any combination and amount of 0s and 1s can be called file. Files have name and extension, such as "book.pdf". Here, "book" is file name and .pdf is extension, which defines file type (what kind of data is saved in file).

Files are available in either text or binary format. Text files contain only plain text data (i.e. only characters). Binary files contain any kind of data (i.e. string of any combination of 1s and 0s).

Folders, also called directories are used to organize files and folders. Folder can contain one or more files and/or folders.

What is programming?

Programming is a process of writing instructions for the computer devices to perform. The instructions are written by humans, which are called computer programmers (or programmers in short). Written instructions are called programs, or software. Words "program", "application" and "software" mean same thing and are used interchangeably in this book. Today many people are using programming for professional work or just for hobby (more on that in the section "Where programming is used"). The practice of programming was first developed as the first programmable computers created. In the past, before programmable computers, computers were able to perform just one specific task. That was because they were designed so that their instructions could not be changed. Later, mathematician John von Neumann created what is known as stored-program concept. This idea of this concept is that computers can be built so that different instruction can be written for them, and computers could follow what was written as an instruction. These made computers programmable, which means humans could write different instructions to computers and they should follow instructions. Then engineers built computers using this theory. Today's computers are built using stored-program concept, so they are programmable.

Where and how programming is used

Programming is used in many different environments, is very popular occupation, especially in the present time and will probably become even more popular by today's trends.

Obviously, programming is used in developing any kind of software (games, audio editing, photo editing...) for desktop and handheld computers, but this is not all as you might know. Programming is also used in developing applications for embedded computers, which are computers embedded in larger accessories and transportation machines, such as fridges, cars, trains, plains etc. Even some robots laboratories use embedded computers. To program these embedded computers, some special programming languages are used.

Who uses programming and who can use it

In the past, when first computers were first introduced, it was very difficult to write computer programs and only people with technical knowledge could write programs for computers. Computers were physically much larger (about size of one room) and were not available for ordinary people, they were used primarily for scientific works. Also, there were not high level programming languages developed yet, and programmers had to write programs in low level programming languages, which was additionally difficult and time-consuming task. And lastly, first computers were much slower than computers available today.

But nowadays, situation is completely changed. Today anyone with a computer and software development tools (or programs) has everything to write programs. Anyone can have the tools to program computers (not only PCs, also handheld computers such as Android devices) even without having to pay anything assuming they have computers and free software development tools. Or, you can buy some professional software development tools (for example Microsoft Visual Studio IDE) with more features and better quality than free tools (note that it is not necessary to pay for software development tools, often free tools can do more than you need).

In short, it does not matter who you are to be able to program computer. Programming can be your hobby or work. It can also be your money making business - you can sell software in any place of the world - for example from your website through download and some kind of online payment methods (PayPal, Credit Card etc.). Programming is practical and real activity (or craft) and anyone can do it of course in case of knowing programming.

Algorithms

Collection of specific steps for accomplishing some kind of task is called an algorithm. There are many kinds of algorithms created and used today, such as text compression and encryption algorithms. When you write programs, you essentially write algorithms; because of this, algorithms are fundamental concepts in programming. Essentially, programming is practice of writing algorithms in some kind of programming language.

When you invent some kind of algorithm, you need to convert it to real programming commands for the computer to be able to execute your algorithm. There might be several different algorithms for accomplishing the same task, but it is desired to create algorithms that accomplish tasks in minimal time possible and with minimum technical (RAM amount, CPU resources etc.) requirements. This is called algorithm efficiency.

What is programming language?

Programming language is defined as a combination of predefined specific rules and specific keywords which can be used to assemble some kind of program if language rules are followed. Some people might not understand this concept by this definition, so think of it using this example program written in Python programming language:

print("hello world")

All this program does is that it displays "hello world" on screen. Here, "print" is a programming language keyword. Keywords are built in programming languages. They have specific functions. If we write this code as:

print"hello world")

or as

prinaaat("hello world")

then this program could not be run, because there are syntax errors. Syntax errors are results of programming language rule violations. In the first example, there is a missing "(" sign. In the second example, there is written "prinaaat" instead of "print". When writing programs, there should not be even single syntax error or program would not run or compile. Fortunately, syntax errors are easy to trace because source code editors automatically detect them.