Krista's Coding Corner

25.02.2012

What is programming / coding?

I really would like to separate programming and coding. In this page, I prefer coding over programming because programming is very big and complicated subject. (Also, I’m no programmer even I may be able to code something :) ). Programming (in my opinion!) covers not only coding but program architecture (how different parts of a program are glued together), documenting and so on. Programming really needs brains and vision how things should be done right. Programming is not bound to any specific programming language. Programming is the whole package, not just some typing and eating bananas. (heard of codemonkeys? :D)

Coding then?

A computer is like a ditzy robot: it will do almost anything if you just know how to give commands to it. Or rather think the idea as Harry Potter’s wizarding world: you can do many things if you know how correctly cast spells. Possessing magic abilities mean nothing if you don’t know how to use them. This applies also to coding: many have a computer but not so many can actually use it's potential so well and ever rarer can actually create programs with it.

In short: coding is telling the computer to do things, and a code is like a task list for it.

I like to separate programs inner logic (==what it actually does) and user interface (what it shows to the user on screen). For starters, I must say, that I will not write so much about the interface as I’ll mostly concentrate to the inner logic.

Let’s start from the very beginning, the computers.

If you are reading this, you know quite well what a computer is but do you know how it works?

Well, computers communicate, sort of. You probably know what a telegraph and Morse code is (if you don’t, read Wikipedia: a telegraph, Morse code). With a telegraph we can send Morse code: long and short clicks. Normally if someone would be beeping, we wouldn’t understand him. But with a telegraph we can’t send any normal speech, just those clicks. So, something else had to be invented: Morse code. In Morse code we have beforehand fixed meanings to a different kind of combinations of different clicks.

Example: .... . .-.. .-.. --- -- -.-- -.. . .- .-. .-. . .- -.. . .-.

This is what a computer does, even though they don’t exactly use Morse code. Computer communicates with voltages: no voltage or some voltage. These two different states (having voltage, and not having voltage) are marked with 0 (no voltage) and 1 (voltage). Almost like Morse code, right?

So, computers speak with 0s and 1s, which is also called binary. Of course that is really hard for humans to understand this language, which is a just combination of two numbers. Some clever people then created similar fixed meaning to different combinations of the numbers as Morse did to his clicks; one of them is called Unicode (one famous one is ASCII).

Here is an example to understand the process from voltages to letters:

01101000 01100101 01101100 01101100 01101111 (this is also called binary and can hardly be read by humans)

104 101 108 108 111 (binary converted into decimal numbers aka our normal numbers. We can also do the conversion into some other radix, it doesn’t matter. You just have to have a decoding table to do conversion from the radix chosen to letters.)

hello (in Unicode 104 means h, 101 == e, 108 == l and 111 is o).

If you wish to know ASCII or Unicode better, again, take a look at Wikipedia :) Also, the Braille system for blind people has a bit similar method in it: we have beforehand just decided what means what. A bit like we have decided that one may not walk across the street, if there is a red light or showing the middle finger is offensive (at least in most of the countries). The main idea is that we can make something meaningless into containing actual information just by creating rules. If you think about it, coding is a bit like encrypting (ever played detective?).

Okay, now we have a method to give computers text, and they may also save the text in similar manner: just two different symbols, like CD’s have bumps and smooth surface representing those two different states, and we are set. One could code in similar manner with anything: use cars passing you by that have different colors or with the locations of billiard balls. Just agree on rules.

Letters, how they actually mean anything?

With letters we can write anything but it doesn’t mean that computer gets any real sense from them. That’s why we have even more rules. With rules Binary can be converted into letters and with rules letters create words like in any human language. In this case we just have artificial language called Assembler. Assembler consist of different words which meanings computer can understand because it is wired in that way. (Like French speakers can understand some English words if they study them). For different processors, there are different kinds of Assembler-languages because processors are physically different. That’s why programs normally won’t work with different types of processors.

This wiring could be done by hardwiring but that is not always the case, so it gets quite complicated in this point. Some of the words or commands actually have to be hardwired. By using these hardwired commands, more complicated commands/words are created.

Normally things like adding and subtracting numbers and bit operations are hardwired. Minimum needed bit operations are AND and NOT. In short, AND means that if you have two wires going into AND-block, both giving signal, the AND-block will also give signal. And so on... Maybe in the future I’ll write better instructions to do and understand these simple operations, if you wish to understand them better by yourself, I advise to think all of these operations as in pneumatics. It really will make it a lot easier (or at least to me it makes these more understandable).

Anyway, Assembler is still quite hard and painful to write, so we need to have even more rules! Lower level programming languages are the next levels that are built on Assembler. And then there are even more sophisticated languages which are always more and more like human language.

Assembler-languages are frozen for each type of different processor (that’s why the manufacturer isn’t meaningful but the type is!). Inside processor this assembler is actually transformed into microcode. Then the microcode is executed. What this microcode really is, is always a company secret. That’s why it is hard to say what really happens. But manufacturers use this to create new processors by changing the microcode. It really has a difference how that code works, so getting better microcode means getting better processor even the processors would physically be the same. Mostly not even programmers really need to know about this stuff. This is just really sophisticated stuff Intel and others do.

Commit log

- 26.02.2012 Added links + fixed some typos.

- 01.03.2012 Fixed missing picture...

blog comments powered by Disqus