r/learnprogramming • u/sw1sh • Jun 09 '12
Types of programming
So i have been teaching myself Java programming for the last two months,and I understand that it's an Object-Oriented Programming language. But from my time of stalking these forums I've read a lot about functional programming,and other types that I don't really understand. I get that I shouldn't expect to know much outside Java after only 2 months,but I'm just interested in how other languages differ from Java.
I've also read about Haskel,Scala and other seemingly unusual languages,and so my question is:
TLDR - "What are the differences between the programming types?"
215
Upvotes
5
u/kqr Jun 10 '12
It really depends on how deep you want to go, but if we stick to some fairly comfortable level, it is basically like this:
The computer only knows of numbers, so somehow, you must instruct the computer through numbers. The way this is made today is surprisingly simple: Every action the CPU can perform has a corresponding number. When the CPU reads a particular number, it performs the right action. Perhaps a number like 101101 means "add two numbers together" and 11100110 can mean "jump to another location in memory."
These numbers are combined with their respective arguments to form full instructions. For example (and this is very, very simplified) the machine code to add numbers 1 and 6 together might be
First is the code signifying an addition is about to take place, then are the two numbers which are to be added. The addition is performed in hardware, and if you want information on how this works, you will have to learn about logic gates and transistors. We can pretend the result of the addition is automatically stored in some predefined place, where we can fetch it later on if we'd like.
Machine code is just a huge series of these instructions. I wish I could show you a real executable, but they're just so damn long and consist mostly of zeroes anyway (for padding and placeholder values.)
Anyway, if you would study this further, you would find that a hello world program is actually fairly complicated. This is because the computer does not have native instructions for printing something to the screen, so you need a metric shit-tonne of code to produce that result. That code is incuded in
stdioso you don't have to worry about it when writing C code.If you would like a more in-depth look on this, I would recommend learning to code in an assembly language. Assembly is essentially machine code but with words instead of numbers. Because machine code is different between different computers, so is assembly language. The most common type of computer today is the x86 compatible computer. If you want to program assembly directly to your hardware, you'll have to go for x86 assembly.
For learning purposes however, I would not recommend x86 assembly because I think it is ugly, confusing and difficult. I prefer MIPS assembly (which would require a MIPS simulator or something on your computer) because I find it terrifically simple and clean.