Introduction to computer programming for coders
Tags: beginners, programming, codenewbie, computerscience
Published: 2021-08-29 22:04:51

**WELCOME**
In this series of lessons, I am going to take you from absolutely knowing nothing/less about programming/coding to been comfortable with instructing computers to do anything for you.

## Computers?
If you're reading this it means you already have a computer, Phone or PC/Laptop. Now can you answer the question, **what are computers?**
You're right! It's just the device you've with you.
Let's discuss the device in detail. It's powered by electricity, it's capable of taking in data (input), can keep the data (storage), processing the data (algorithms) and finally give out the information (output) and this is in fact the definition of computers.
 
Today computers have reached to a point that human don't only compare them to us but they've declared that computers are smart/intelligent than us.
Those who said that or think so doesn't understand computers.
Computer are stupid even though they can store billions of data (for example 1.5 million books of standard size),  and can perform a billion of calculations per second! (two operations in same time light travels 1 foot).
They existed because of us, they only do what we instructed them to do i.e garbage in, garbage out. This means even if we mistakenly instructed them they'll still carry out the instruction because they cannot realize our mistake.

## Computer Science and Programming
Computer science is fundamentally problem solving. And in this series of lessons, we'll focus on speaking to computers to do tasks for us. Speaking to computers? Ohh yes, Computers speak the language 0s, and 1s just like we human speaks in decimal base for instance, `2021` in computer it's `11111100101`. I did high school math to convert decimal to binary. Each digit in binary represent a bit.

It make sense that computers can represent decimal in binary, What about texts?
## Representation of texts in Computer
People before us have decided base on a standard to map each character (capital and small letters, punctuation) to a number. for instance, `"A"` ==> `65`,  `"B"` ==> `66` and so on. Read more about  [ American Standard Code for Information Interchange.](https://en.wikipedia.org/wiki/ASCII) 

![ASCII-Table-wide.svg.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1630248627025/A7k_L2qsi.png)
 [Image Source](https://commons.wikimedia.org/wiki/File:ASCII-Table-wide.svg) 

Receiving the text `"HELLO"` ==> `"72", "69", "76", "76", "79"` respectively. And in bits it's `01001000, 01000101, 01001100, 01001100, 01001100`. Each letter is typically represented with a pattern of eight bits, or a **byte**.


- 
8 bits == byte
- 
1024 bytes == kilobyte
- 
1024 kilobytes == megabyte
- 
1024 megabyte == gigabyte and so on

However some think it's `1000` instead of `1024` 

There's another standard,  [**Unicode**](https://en.wikipedia.org/wiki/Unicode)  that is an extension to **ASCII**. It contains all those characters like ancient symbols, emojis and many more that do not exist in **ASCII** standard.

Then how images, videos and audios are represented in computers? 
## Images

![newProfile.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1630252691378/jUWisp5RL.jpeg)
I don't know if you can observe that images are just thousands or millions of square boxes called pixels combined.
We can achieve pixels by zooming the image 2000+% like the image shown below

![zoomedImage.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1630254000875/O0xJz20e2.png)
and those square boxes or pixel are nothing but colors. So our concern should be how computers represent colors? 
There were many system of representing colors but the most commonly use is **RGB**. Some amount of red, green and blue can be combine to produce millions of colors. for example, `rgb(23, 116, 223)` will produce the color below.

![pixel.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1630254565152/7pdXBDldW.png)
As you can see, there's numbers mapping to colors. `rgb ==> 23, 116, 223`.
The resolution of an image is the number of pixels there are, horizontally and vertically, so a high-resolution image will have more pixels and require more bytes to be stored.
 
## Videos and Audios

- Videos: If we break videos down, we'll see it contains thousands of images flipping per second to create the motion as in this [Youtube video, flipping](https://www.youtube.com/watch?v=p3q9MM__h-M) 

- Audios uses the concept of sound wave to map sound frequency to numbers.  Read more about [sound representation in computers](https://teachcomputerscience.com/sound-representation/) 

## Programming Languages
Earlier I said that computers only understand `0s and 1s` but imagine if we are to communicate with computer to build a complex system or application like Twitter with `0s and 1s` it will seems impossible not alone **HARD**. The same humans before us has created a languages which are more human friendly. Today, we've more than 500 hundred programming languages. We can use those languages to instruct computers. The `Code` we write in those languages will be compiled/interpreted to `Machine code`, a codes which computers can understand.

Out of 500 plus programming languages, ** What is the best programming language? **
There is no such the best programming language. Each have their strengths and weaknesses and there are Domain specific languages, highly specialized mini-programming languages for example `regular expressions` for string manipulation, and `SQL` for database manipulation.
**Whatever can be compute in one programming language can be compute in other programming language.**

## Computers vs Human being
Let's say you're given a Phone Book which consist of the list of the following names,

`[ Omar, Mamudo, Amie, Fabala, Muhammed  ]`
Assuming each name on the list is on a page and page start from 1.
You can tell a human being to find the name, `Fabala` and you're not going to tell him/her how to go about in retrieving the name, `Fabala` from the phone book.
S/He will have to find an approach to check if `Fabala` is on the Phone Book? and if yes will tell us at which page. This very human being can start searching from left/right of the page and turning one page at a time. This is because human being understand `Declarative Knowledge`. `Declarative knowledge` is a statement of fact like find me the name, "Fabala" from the Phone Book.

Whereas, Computers understand `Imperative Knowledge`, a recipe or how to knowledge. If the same problem, finding "Fabala" from the phone book given to Computer, you need to tell it how to go about in finding the name, "Fabala".


> 
**Instructing Computers to find "Fabala" from the phone Book**
1. Pick up the Phone Book
2. Start from the first page on left side of the Phone Book
3. Check if name on the page is "Fabala", tell us the page number and stop searching
4. Else, Go to the next page and go back to step **3**
5. When no page is left to be search, tell us "Fabala" doesn't exist in the Phone Book 

The steps/approaches we took to find the name is what we called an **Algorithms**, step-by-step instructions for solving problems.
What we did above is representation of our algorithms in precise English and that is what is refer to as `Pseudocode`, representing algorithms in Human Languages.

### Actual code
I do not expect you to fully understand the code below. I just want you to see how `Actual code` is different from the `Pseudocode`


```python
phone_book = [ 'Omar', 'Mamudo', 'Amie', 'Fabala', 'Muhammed'  ]

def find_name (phone_book, name):
    '''
    input: phone book consisting of names, and the name to be search
    output: return the page number of the name if it exist
    else return 'Not existed'
    
    '''
    
    for page in range(len(phone_book)):
        if phone_book[page] == name:
            return 'Page ' + str(page + 1)

    return 'Not existed'

print(find_name(phone_book, 'Fabala'))

``` 
The code above is written in **Python Programming Language** which we're going to use throughout this series to represent our logic but we're going to focus more on problem solving (Programming) than the coding part of it.
 
Thanks for reading and see you in the next topic, [**Algorithms**](https://dev.to/fabaladibbasey/algorithms-with-python-variables-and-conditions-3733).

Don't forget to like, share with those it will help and finally lets connect on  [Twitter](https://twitter.com/DibbaseyFabala) and  [LinkedIn](https://www.linkedin.com/in/fabala-dibbasey-b69a27207/)