How Your Ruby Code Changes the Physical World!


Some basics on how code makes a computer run


March 8, 2015

As students at Dev Bootcamp, the first language I familiarized myself with was Ruby, which was a wonderful, super coder-friendly, high-level language. However, I could complete Dev Bootcamp and still have a shallow understanding of how a language like Ruby actually makes a computer store information and display text and images on the computer. I knew that that computers operate, and have almost always operated in binary language. This means that everything a computer does and stores uses bits, which are each a 1 or a 0. The question remains, however, how does a language that reads like this:

Ruby source code:

if fav_team == "Milwaukee Bucks"
  puts "That's a great team."
else
  puts "That's a good team, but I prefer the Bucks."
end
    

get changed to something that reads like this?

Machine language:
100011010110100110011010
    

First, one must understand that the former is called source-code. Source-code is the code written by programmers of any high-level language (like C, Ruby, and Java.) The latter, binary, is called machine language.

Ruby is an Object-Oriented language, and therefore fits at the top of the diagram. Ruby uses an interpreter, which is a computer program that translates the code into machine language as it runs.

Many languages use compilers, meaning they use a translator to convert the source code to machine language code. Then, they run.

This leaves the question, how what is the actual physical difference between a 1 and a 0? 1 and 0 are actually mathematical abstraction for two different physical states. It is like on-and-off on a high switch. On hard drives it has to do with whether something is magnetic or less magnetic. On a processor it relates to whether a transistor has high or low voltage.

On very early computers, electromechanical switches called relays determined bits. This means that you could actually see whether it was a 1 or a 0 based on the position of the swtich. Then, in the mid-20th century, the current in a vacuum tube determined the value of a bit. However, because it would take hundreds of relatively large vacuum tubes to build a computer, eventually more advanced hardware was built.

This description of how a computer language actually make changes on a computer could go much deeper. But this provides a basic understanding to the beginning programmer how what she works on makes the computer perform actions.