Saturday, August 7, 2010

Programming Languages / Layers of Abstraction

Winston requested I do a post on programming languages. And I have been considering how to go about doing this for over a week now, and I think I've got a decent way to explain it. To fully understand the subject would take a whole book, as this subject overlaps heavily with how human thought works. To avoid have to read a whole book just take my word for it that programming and layers of abstraction very closely mirror how the brain works. I know, it's hard to just trust me on this one, and if you don't believe me, then just go read Godel, Escher, Bach by Douglas Hofstadter. But that is probably 750 pages more than your interested in reading. So here we go.....
Layers of Abstraction
A computer is merely a sophisticated combination of circuits which can determine either the presence or lack of electric current. So the basic unit of information in a computer is the bit, which is a 1 or a 0, on or off. But one bit isn't enough to accomplish anything, so 8 bits are grouped into the fundamental data unit called a byte. A byte provides 2^8, or 256 combinations. So here is the lowest layer of abstraction,: feeding a computer a series of 1s and 0s. Well, this makes programming pretty difficult, expecting humans to give a computer thousands of 1s and 0s so that it will do what you want. Because this is too difficult, computer chips are designed to natively support machine language. This machine language is still incredibly tedious, and we lazy humans expect an easier way to program our computers because machine language requires many hours of effort to program even the most minute tasks. Here is machine language:

   6      5     5     5     5      6 bits
[  op  |  rs |  rt |  rd |shamt| funct]  R-type
[  op  |  rs |  rt | address/immediate]  I-type
[  op  |        target address        ]  J-type

 So we invented assembly languages. These languages are more effective and quicker but must first be converted back into machine language before they can be run.
For some time people were willing to deal with assembly language and the conversion process it required because it was still alot faster than writing 00101110101000101111101010001011, even though it looked like jibberish, here is an example:

.list
.org $9D95 - 2
  .db t2ByteTok, tAsmComp
Main:
  b_call(_ClrLCDFull);

So then people decided to make symbolic languages, which required more conversion but were much simpler to write in. The first of these had to be made independentlyfor all models of computers but looked something like this:

10 INPUT "What is your name: ", U$
20 PRINT "Hello "; U$
30 INPUT "How many stars do you want: ", N
40 S$ = ""
50 FOR I = 1 TO N
60 S$ = S$ + "*"
70 NEXT I
80 PRINT S$
90 INPUT "Do you want more stars? ", A$
100 IF LEN(A$) = 0 THEN GOTO 90
110 A$ = LEFT$(A$, 1)
120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30
130 PRINT "Goodbye "; U$
140 END
A very big improvement from assembly language. Overtime these languages have become even more sophisticated. I am currently taking a course in the Java programming language so here is a simple java program:
public class NameMaker
{
 private String fullName;
 public NameMaker(String firstName, String lastName)
 {
  fullName = firstName + lastName;
 }
 public String getFullName
 {
  return fullName;
 }
}
public class NameTester
{
 public static void main(String[] args)
 { 
  String name1 = "John";
  String name2 = "Doe";
  NameMaker name3 = new NameMaker(name1, name2);
  System.out.println(name3);
 }
}

Im sorry for the crazy font issues, but this is all for now, in the comments let me know what follow ups i need to write, because i realize this is only the beginning but im not sure what the best path to take would be, i will judge that by your responses.

1 comment:

  1. Thank you Matthew. I think that helped me, but I am still wondering what those different conversations in machine, assembly, symbolic, and programming languages mean. Could you translate for us? What would those rows of numbers and letters accomplish on a computer?

    ReplyDelete