logo: cubicbay interactive courses for Python and data science education

Introduction to Python — Preface

Coding for dummies or how to think about code like a programmer.

The Decoding
CodeX
Published in
5 min readAug 21, 2021

--

Welcome to the Introduction to Python course at cubicbay and congratulations to starting this journey! Learning to code might easily be one of the most important decisions you can make.

  1. If you only pick up a little bit of coding and develop an understanding of the fundamentals, it will positively impact your life, no matter if you are a nurse, run a corner store or practice law. You will be able to fix your own problems, communicate better with technical people and heck: Maybe even write a little script that automates boring parts of your work.
  2. If you take it further and become a programmer, you will be able to build software, that impacts millions of people, from the comfort of your couch. You will have access to a world of infinite leverage for your creativity and ideas.
  3. If you are financially motivated — no judgement passed — programming has got you covered. If you know how to code well, you will quite quickly earn more money than you need, while solving little riddles and writing a few dozen words an hour.

If any of the above spoke to you, let’s go!

TL;DR

After this article you will understand that a computer program usually works by:

  • Putting all data (images, numbers, etc.) in the computer’s memory
  • There it can access it quickly in order to make changes to the data
  • The program sends instructions, on how to change data, to the processor
  • The processor executes these instructions, whereby it changes the data
  • The result is again stored to memory

If none of that is new for you, feel free to skip the preface and go straight to lesson 1.

The computer from a programmer’s perspective

The following text aims to convey, in plain English, how a computer works and how it executes a program. We will also get to know some basic terminology, that will make it easier to talk about the course and coding in general.

When you are programming, it is very useful to think about your computer in terms of the RAM (memory) and its CPU (processor). If this is foreign to you, don’t worry.

Let me explain.

RAM (Random Access Memory)

Photo by Possessed Photography on Unsplash

The RAM is a type of data storage, just like your hard drive. It however allows to read and write data much much faster than your hard drive does.

The RAM is also referred to, in short, as the “memory”. It quite literally acts like the short-term memory of your computer. If you for example open an image in a photo editing program, the program will load the image from the hard drive to the memory. There the program can access and edit the image really quickly.

Only, if you hit the save button the new image will again be written to the hard drive.

If the RAM is so much faster, why not get rid of the hard drive and only use RAM, you asked? Although this is possible, it would be too expensive. The speed of the memory makes it much higher priced, when compared to hard drives. That is why consumer pcs usually have many more GBs of hard drive storage than they have in RAM.

To sum it up: Computer programs put all data (images, numbers, etc.) in the computer’s memory. There they can access it quickly when they want to make changes to it.

CPU (Central Processing Unit)

The CPU, or “processor” for short, is the part of your computer that programs use when they make changes to data.

Previously, we saw that a photo editing software will load an image to the computer’s (short-term) memory. For example, if the software is used to create a greyscale image, it does that using the computer’s processor.

Photo by ANKUR MADAN on Unsplash

You can think of it in the following way:

The program provides the processor with the image from memory along with the information of how to compute the greyscale value for a given pixel. Then the processor rushes at lightning speed to execute the instructions of the program.

One by one, it stores a new grey pixel for each pixel of the original image until it has built a complete copy in shades of grey. Then it stores the copy memory, next to the original image.

Did you ever wonder how a photo- or text editing software can allow you to “Undo” something you did? That’s it!

The software will simply keep previous versions of your image in memory, and it allows you to switch back and forth between them.

Summary: Programs send instructions, on how to change data, to the processor. The processor executes these instructions, whereby it changes the data. The result is again stored to memory.

The Flow of Data in a Program

Up until here, we have seen that programs load data to the computer’s memory and use the processor to change the data. This chain of events is visualized in the image below.

Data flow figure by cubicbay
Figure 1 Data flow in and out of memory by cubicbay

The program runs from top to bottom and from left to right. Each line is run,
one after the other, just about the same way you read the code. Data is loaded from memory, processed and stored back to memory again and again.

In practice, these chains of operations can get long. Very long.

The good news is that, until far beyond the basics, all computer programs operate in the same way.

They start, shovel data from memory into the processor and back until they run out of tasks or are shut down.

That sounds too easy to be true?

I am happy to tell you, that it is that easy. Sure, the computer can get much more complicated than that. However, like a race car driver that races only using a few paddles, a gearshift, and the steering wheel, you can write incredibly useful code without thinking about the engine that executes it.

Congratulations! You have come full circle and computer programs and their relation to the memory and the processor.

You are now ready to start the first lesson of the Introduction to Programming course. There you will learn how to create variables and put data into the computer’s memory.

If you liked this article, check out cubicbay and follow me for more learning resources plus news from the world of science and programming!

--

--

The Decoding
CodeX
Writer for

The Newsletter that Makes You Smarter about Machine Learning, Startups, and the Data Economy