DEV Community

Cover image for Introduction to computer programming for coders
Fabala Dibbasey
Fabala Dibbasey

Posted on • Updated on • Originally published at fabulouscoders.hashnode.dev

Introduction to computer programming for coders

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.

ASCII-Table-wide.svg.png
Image Source

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 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
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
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
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

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

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'))

Enter fullscreen mode Exit fullscreen mode

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.

Don't forget to like, share with those it will help and finally lets connect on Twitter and LinkedIn

Top comments (0)