What is Coding?

Computers today are everywhere, the modern world wouldn’t be so modern without them! They are fast, efficient and they never complain. But all these computers have one BIG PROBLEM, they are like newborns that now NOTHING! We have to tell a computer what to do first in order for them to be useful. And the way that we tell the computer what to do is by writing Code that the computer will execute. But what is Coding? How does Coding Works? Can you learn how to code and is it hard?

Coding is the process of writing structured set of instructions in a programming language. The whole point of writing those instructions is to give them to a computer for execution. And indeed, it is by executing those instructions that a computer knows how to do all the amazing things it can do, like:

  • playing a Youtube video,
  • moving characters in a video game,
  • applying filters to your Instagram photo, etc.

What is the Coding process?

Compiling Process
The programmer writes the code in e programming language like C++.

The code written in C++ can not be executed directly by the computer.

The programmer converts the C++ code into binary code with the help of a program called “Compiler”.

Binary code contains only 0 and 1, it is the only code a computer can execute.

It’s the computer’s processor’s job to execute the binary code.

During the execution of the code the processor tells the other parts of the computer to perform certain tasks, like:

  • tells the monitor to display an image,
  • tells the printer to print a document, etc.

What can Code do?

Every computer program is composed of at least three phazes:

  • Input
  • Processing
  • Output

Input Processing Output

The Input

The input is the information that is entered into the program. It might be in the form of: text, sound, button click, etc;

An example of an input would be when you enter a search phrase on the google search box. In this case the search phrase is the input in the form of text.

The Processing

The processing is the execution phase. The program takes the input and starts executing the coding instructions based on the input. When the program finishes the execution, it produces an output based on the input and the instructions it executed.

For example, after google gets the search phrase as input it starts to search on it’s database for the most relevant websites based on the input.

The output

The output is the information that the program outputs after it finishes the execution.

For example, after the google finishes the search and finds the most relevant websites, it displays the result in the browser’s page.

Algorithms

As we have already said, coding is about teaching the computer how to solve a particular problem.

These are the main steps that needs to be taken for writing the code to solve the problem:

  1. Identify the problem
  2. Find a solution to the problem
  3. Write the solution in code
  • As an example, lets take the problem of finding the largest number in a series of random numbers: 6, 4, 9, 0, 1, 5, 1, 4, 2, 3.
  • This would be a solution to this problem:
    1. Take a variable “max”, that will store the value of the largest number.
    2. Give this variable the value of the first number in the series, max = 6.
    3. Check every other number if it is larger than the value of max.
    4. If the value of that number is larger than the value of max, store that value in max.
    5. When finished checking all numbers, return the value of max.
  • This is how we would write the above steps in code:

int find_max(){
    int nums[10] = {6, 4,9, 0, 1, 5, 7, 4, 2, 3};
    int max = nums[0];
    
    for(int i=0; i<10; i++){
        if(nums[i] > max)
            max = nums[i];
    }
    return max;
}

A group of instructions, like the ones above, that solve a particular problem, is called an Algorithm.

Programming languages

Today, there are hundreds of programming languages, each designed for a specific purpose. But it used to be the case in the early days of computers that programmers would write the code directly into machine language or binary code 0 and 1. As you can imagine, writing code this way can be very tedious and is very hard, if not impossible, to write large programs this way.

To make programming easier, computer scientists, created the first programming language called Assembly. This is a low-level programming language where each instruction is directly converted into binary code.

Coding with assembly instead of machine language makes things much easier. Because now programmers could code using words, which are much easier to remember and understand than binary code. After the code is written, it is put into a program called assembler, which converts the assembly code into machine code.

Since assembly language is closely related to the machine language, different computer architectures and operating systems have different versions of assembly language. This means that the programmer has to rewrite the assembly code for each environment using the respective assembly language for that environment.

This is an example of how assembly code looks like:

section .text
   global _start            ;must be declared for using gcc
	
_start:                     ;tell linker entry point
   mov    al, 5             ;getting 5 in the al
   mov    bl, 3             ;getting 3 in the bl
   or     al, bl            ;or al and bl registers, result should be 7
   add    al, byte '0'      ;converting decimal to ascii
	
   mov    [result],  al
   mov    eax, 4
   mov    ebx, 1
   mov    ecx, result
   mov    edx, 1 
   int    0x80
    
outprog:
   mov    eax,1             ;system call number (sys_exit)
   int    0x80              ;call kernel
	
section    .bss
result resb 1

High-level programming languages

Today we rarely use low-level programming languages like Assembly. Instead, high-level programming languages are preferred like C++, Java, PHP, Python, etc.

High-level programming languages are closer to human language than to machine language. Therefore they are easier to understand and code. These languages are independent of computer architecture of operating system, because they aren’t directly converted to machine code.

This is an example of how a high-level programming language like Java looks like:

public class Test {

   public static void main(String args[]) {
      int x = 30;

      if( x == 10 ) {
         System.out.print("Value of X is 10");
      }else if( x == 20 ) {
         System.out.print("Value of X is 20");
      }else if( x == 30 ) {
         System.out.print("Value of X is 30");
      }else {
         System.out.print("This is else statement");
      }
   }
}

High-level programming languages are grouped into three types, based on the process in which the high-level code is converted into binary code.

  • Compiled languages
  • Interpreted languages
  • Bytecode languages 

Compiled languages are all those languages which have to be converted into machine language, before they can be run by the computer. The conversion to machine language is done with the help of a program called compiler. The main advantage of a compiled language is that it is fast to execute. This languages have to be compiled differently for computers with different architectures, because the machine code is different. Examples of such languages are: C, C++, Go, etc.

Interpreted languages aren’t converted to machine code, instead they are executed with the help of a program called interpreter. The fact that these languages aren’t converted to machine language makes these languages slower than the compiled languages, but also gives them the ability to be machine-independent. Examples of such languages are: PHP, Python, Ruby, etc.

Bytecode languages are in between compiled and interpreted languages. These languages are first compiled into bytecode, which is than executed by a virtual machine that acts like an interpreter. These languages are faster than the compiled languages, but slower than the interpreted ones. They are also machine-independent. Examples of such languages are: Java, C#, etc.

What do programmers do?

Computer programmers translate software design into code that computers can execute, creating the operating systems and software applications that we use every day.

Since computer programmers’ primary responsibility is to write code, they must know at least one programming language. And because different languages are suited to different applications, most programmers learn multiple languages or more versatile languages. Programmers also update code for programs to make them more secure or more functional. They routinely check the code for errors.

 

How to learn to Code?

Learning to code can seem very daunting as you are just starting out. This is because of the unfamiliar syntax and the logic behind. But once you learn the fundamental concepts and familiarize yourself with the syntax and the logic, everything will just feel so much easier.

If you are serious about learning programming, its definitely worth it to spend some time to learn the underlying concepts of how computers work, how is the program stored in memory and executed by the CPU, what are algorithms, data-structures, etc. Learning programming won’t happen over night, so it’s important to have a long term plan. And, when it comes to coding, nothing will teach you better than practice.

The good news about learning programming is that, there are so many resources on the internet, you can even start to learn some basic concepts by downloading an app.

Fore those who are really serious about learning programming and are thinking in long terms, majoring in a Computer Science program is the way to go.

 

 

Filed under: ProgrammingTagged with: ,

No comment yet, add your voice below!


Add a Comment

Your email address will not be published. Required fields are marked *

Comment *
Name *
Email *
Website