Compiled vs. Interpreted
I don’t get asked very often but every once in a while a client will ask me, “What’s the difference between a complied or interpreted language?” The answer is pretty complicated, but this article will take a very high level look at the question. Like most of my articles, this is intended for clients and developers alike, but it is geared for providing information to people that don’t have a background in development. For that reason some of this information my not be completely in depth, and should be considered a very high level look.
The first step
The first step in learning the difference is to know how computers work. So lets say we make a simple program.
c = a + b print c
Now this is just pseudo code, and not really in any language, but it will work for our example.
Computers can’t understand those instructions. They don’t get it. It’s easy for us people to understand, but computers are totally lost. They need much simpler instructions, that do much more complicated things. I could write the the exact instructions needed to do that, but it would just be several pages of gibberish, and not readable by us. For example adding a and b can take about 48 seperate instructions not counting getting the values for a and b.
So back in human land, us programmers use a “language” to write in that is easier to read, write, and understand. That language needs to be changed into a language the computer can understand. When and how that translation takes place is the difference between compiled and interpreted languages.
Compiled languages do their “translation” one time. They get “compiled” and the resulting file (executable) can more or less be passed directly to the computer for execution. This is not exactly true, as the OS gets involved etc. etc., but it’s close enough.
Interpreted languages get “translated” at run time (that is when you try to do something) and then passed to the computer. There is always a Interpreter, that sits between the code, and the computer to “translate” the code.
A great analogy is speaking to someone that speaks a language you don’t. You can prepare a document ahead of time. If you have that document translated and send the translated version on to the recipient, that would be considered “compiled”. If instead you read that document (in your language) at a large meeting, and a translator takes what you say, and translates it for the audience, that would be considered “interpreted”.
A Brief look at the translator
So just like out translator example above, source code gets “translated” into computer language. Compiled code is translated one time, and Interpreted code is translated each time it’s needed (spoken in our analogy). The main difference here is that a compiled language doesn’t need a translator at every destination. The interpreted path, requires a translator at every conference. In computer land, the analogy holds true. A complied executable doesn’t need an interpreter every time it’s run. A interpreted code would need a interpreter every single time it’s run.
Which is better, Compiled or Interpreted?
That’s really the important question. The answer is neither. They each have things they are good at and things they are bad at. For example Compiled languages are faster. They only need to be “translated” one time, so you save on that translation. Interpreted languages on the other hand are great for portability (ability to run on several different platforms).
As an aside, these goods and bads are generalizations. There are examples of code that break these rules on both sides.
Complied languages are:
- Use less memory
- Have fewer dependencies (normally)
- Generally have better paths to connect to hardware.
- Easier to deploy on several platforms
- Better code maintenance options (generally)
- Better access to “Meta-Programming”
- Better at Dynamic Variables (usually)
For examples, Your OS Kernel is written in a compiled language. That gives it better access to hardware then an Interpreted language could hope for. But is also means that your kernel has to be compiled again for every single different platform that it will run on. For example you can’t run windows on a PPC mac.
Compiled languages are usually worse at:
- Portable code
- Memory allocation
- Dependency management
Interpreted Languages usually struggle with:
- memory consumption
- Code Obscurity (making it hard for others to read your code)
When to use each?
With the goods and bads, there are some decent lines on when to use each. Websites are almost always Interpreted. It takes a little bit more memory, but means you don’t have to compile different versions for different servers.
Likewise, Desktop games are generally compiled. In an area where speed is paramount, compiling just makes sense.
iOS apps are compiled. Android apps are Interpreted.
There are several differences
There are several difference between Interpreted languages and compiled languages but they are basically just two ways of translating near human speak to computer speak. Each has it’s advantages and disadvantages. In the end, the “right tool for the job” depends on the job.
Coteyr.net Programming LLC. is about one thing. Getting your project done the way you like it. Using Agile development and management techniques, we are able to get even the most complex projects done in a short time frame and on a modest budget.
Feel free to contact me via any of the methods below. My normal hours are 10am to 10pm Eastern Standard Time. In case of emergency I am available 24/7.
Phone: (813) 421-4338