Wednesday, April 28, 2010

Opening a door with code

On my drive home from work, I started to think about how programming syntax can be used in applications that apply to everyday life. The concept of everything has a purpose or function was something I read about in Language and Myth by Ernst Cassirer. This concept easily applies to object-oriented programming. Weird, huh? For this explanation I will use some VB pseudo code. Syntactically, when a program is written, it is written in the order in which the events should occur. All objects have methods or actions in which they can perform. For instance, a door can open and close. The door also has properties associated to it. For instance  the door is wood, closed, 6ft tall. So here is how to open a door in code:

If Door.closed = "true"
  Call Door.OpenDoor
Else
  Output "The Door is Already Open!"
End If

If User.Height < Door.Height
  User.GoThroughDoor
Else
  Call User.Duck
  Call User.GoThroughDoor
End If

No comments:

Post a Comment