After discussing this stuff for the 3rd time in IRC, here is my introduction to how computers/programming work at a basic level. (please comment any glaring errors).
There are particles called electrons which move through wires as a charge
There are other things that can be placed along wires like capacitors, diodes resistors etc.
we won't cover how these work, but just take it that they do things that change the properties of the circuit formed
you can place these things in orders to make a gate
this takes 1 or more electrical currents as input
and outputs another signal (or lack thereof)
a signal is a high voltage (1), or low voltage (0)
eg
a not gate reverses the input
not 0 => 1
and 1 1 = 1
nand = not and
with this nand gate, you can make any other gate
you can arrange these gates into a thing called a flip-flop
http://en.wikipedia.org/wiki/Flip-flop_(electronics)
which when a signal is passed through, changes output between 0 and 1
this effectively allows us to store information in an electric circuit
your computer is made up billions of these flip flops
so, using Boolean logic (the logic associated with gates) you can essentially make any program into an electric circuit
obviously for anything greater than something that computes addition you need something to handle this
so we have a cpu
this takes input as a signal, and performs operations on things called registers, these registers store information in bits
a bit is a single 0 or 1, and come in groups of 8,16,32 or 64. Thus we have so-called '32 bit computers'
the cpu can perform a range of operations on these registers, such as addition, logical and, logical not etc.
you run long streams of high/low voltages into the CPU and this causes it to perform the aforementioned operations
you probably don't want to have to do this again and again
so we have a thing called memory
which is also gates that store data in bits
this data constitutes programs
data travels between memory and the cpu registers via the bus
memory, requires a constant electric current to keep the data in memory (like we discussed in flip-flops)
this is why your computer cannot run without an electric current going through it. It needs that current to keep a collection of programs called the operating system in memory
obviously, we need to store these programs someplace when the computer has no current through it, this is called permanent storage, and is usually a hard disk drive, or tape drive
so we load our programs from the non-volatile storage (hard drives etc.)
into volatile storage (memory, registers)
we could write all our programs as a sequence of 1's and 0's
this sequence of 1 and 0's is called machine code, but is time consuming and non-intuitive to write
So we have another language called assembly, which is basically synonyms for the primitive CPU operations like and, not, xor move etc
This language is then "assembled" into machine code by an assembler
Assembler is slightly more convenient than machine code because of the synonyms
but, it's still pretty bad
so, when computers were still new, people recognized this and decided to make programming languages that can be compiled (converting from language into another, eventually down to machine code)
on the one hand people wanted to use the logic set out by Church, Turing et al
thus the language Lisp was born
http://en.wikipedia.org/wiki/Lisp_(programming_language)
on the other hand
people wanted a language that followed more closely to how a computer operates
thus imperative languages like Fortran where born
http://en.wikipedia.org/wiki/Fortran
people thought they could do better so more and more languages where born to express these programs.
this is why we use high level languages
in the end
everything runs as a high and low voltage going through a cpu
---------------------------------------------------------------------------------------
The motivation for high level languages such as c/c++/java/fortran/python
There are 4 main paradigms in programming
imperative, this follows along with the way in which a computer processes data, step by step, one at a time
eventually, all programs are compiled into something that follows this idea
Object oriented
Is useful (questionably) for large projects where code needs to be managed. It centres around interacting objects. An object is an instance of a class (like a blueprint). Classes can be based off other classes etc, but eventually this too is reduced to imperative machine code.
examples are Java/Python etc.
functional programming is more function oriented
wherein, there are inputs, functions which process this input and an output is produced
examples are Haskell, lisp, scheme, F# etc.
These languages are useful because it is easier to reason about them and their correctness
since they are so close to math, you can basically translate a complex mathematical algorithm straight into a runnable program
these are useful in things like data processing and scientific computing and maths dickery
declarativelanguages are ones where you ask a question, and an answer is returned that (hopefully) solves that problem
these are useful in databases and logic problems, such as constraint satisfaction problems
http://en.wikipedia.org/wiki/Constraint_satisfaction_problem
Sunday, September 18, 2011
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment