6 Replies - 12135 Views - Last Post: 24 April 2011 - 05:50 PM Rate Topic: -----

#1 Parrish   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 13-March 10

What is the difference between an interpreter and a compiler?

Posted 24 April 2011 - 10:05 AM

I am very new to python, I have java experience, but want to learn a new language. So what is the difference between an interpreter and a compiler.

What should I use? Any recommendations on what I should use? Currently I have a python GUI of IDLE.

Another question I have is python mostly all handled at runtime?


Thank you for your time in advance.
Is This A Good Question/Topic? 0
  • +

Replies To: What is the difference between an interpreter and a compiler?

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5510
  • View blog
  • Posts: 14,499
  • Joined: 18-April 07

Re: What is the difference between an interpreter and a compiler?

Posted 24 April 2011 - 11:07 AM

An interpreted language is one which is read at the time of execution and each statement is executed as it is read. It is "interpreted" just like when a person interprets what a person said in one language to another as it is being said.

A compiled language is one which is read, translated into machine code (or bytecode) and then saved into that format to be executed later. This also typically links in other libraries modules etc at the time of compiling (often called linking).

Python is interpreted in that the script is read and executed as it is being read. This is why you can have an error in the script further down and yet it will attempt to run the program until it hits that error. Java is compiled into bytecode (the .class file) and then it is loaded into the JVM when it needs to be ran.

Interpreted languages...

Python, PHP, Javascript, ASP, Ruby and more


Compiled Languages...

C#, Java, C/C++, VB and more


Hope this helps :)

This post has been edited by Martyr2: 24 April 2011 - 11:08 AM

Was This Post Helpful? 1
  • +
  • -

#3 Parrish   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 13-March 10

Re: What is the difference between an interpreter and a compiler?

Posted 24 April 2011 - 11:23 AM

Alright so with that, using IDLE.. to create different projects or so, i just save and open a new file? At the moment I am playing around in one file just testing code as I see it and just trying to get a feel for language the IDE.

I have also been hearing the this is a scripting language, could you maybe point me in the right direction in how to write scripts for python?
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5510
  • View blog
  • Posts: 14,499
  • Joined: 18-April 07

Re: What is the difference between an interpreter and a compiler?

Posted 24 April 2011 - 11:32 AM

Yes, each project typically goes into its own python file with the extension ".py" on the end of it. You can then bring in code from one .py file into another using include commands etc.

Python can be a scripting language, but it can be used in full non scripting contexts. By scripting they typically mean that you can create a file, throw in some commands to do a few actions (like create files, do scheduled tasks etc) like a utility language. But you can write complex fully object oriented programs and applications with it.

One place to start with Python is right at python.org and here is a link to their beginners guide...

Python Beginners Guide - Python.org

You can also find many books in book stores, amazon etc. I just suggest you avoid the big thick Learning Python book (the pink one with the mouse on it) because the author is a bit all over the place with it. Chapter 1 he pretty much tells you topics that are in chapter 10 and chapter 2 he refers you to chapter 6, when you get to chapter 10 he tells you a little more and then refers you to chapter 16 etc. He is always "referring you" to other later chapters.

Good luck with the learning. :)
Was This Post Helpful? 2
  • +
  • -

#5 Parrish   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 13-March 10

Re: What is the difference between an interpreter and a compiler?

Posted 24 April 2011 - 11:45 AM

Thank you, I appreciate it
Was This Post Helpful? 0
  • +
  • -

#6 Parrish   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 13-March 10

Re: What is the difference between an interpreter and a compiler?

Posted 24 April 2011 - 03:12 PM

Alright, using IDLE..

if I save then go back to the same file/project how do I get it to edit it as a continuation what I was doing before? as everything is executed after I hit 'enter'?
Was This Post Helpful? 0
  • +
  • -

#7 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7505
  • View blog
  • Posts: 15,553
  • Joined: 16-October 07

Re: What is the difference between an interpreter and a compiler?

Posted 24 April 2011 - 05:50 PM

View PostMartyr2, on 24 April 2011 - 02:07 PM, said:

A compiled language is one which is read, translated into machine code (or bytecode)


This doesn't happen often, but I'm going to have to disagree with Martyr.

A compiled language is one which ultimately results in machine code. This is mostly C/C++ at this point. Assembly, of course. A compiled language results in binary files that are standalone machine code and may be run without any "runtime" at all.

An interpreted language is one that requires an interpretor to run. Some interpreted languages go through a preprocessing stage that results in something originally called p-code.

Java is responsible for muddying the waters here. Java source is said to be "compiled" into class files. However, this compilation really just generates p-code, or bytecode, that is run in an interpretor, or JVM. Microsoft's .NET follows the same model, compiling assemblies that run inside of the CLR. For Java and .NET, the interpretor is called a virtual machine, but it's still just an interpretor.

Because so many languages claim not to be interpreted, because of a perceived stigma of slowness, you can break up interpreted languages into those that require an intermediary code generation phase to run in their interpretor, and those that are fed straight into their interpretor as text.

Java and .NET require a preprocessing phase. Old BASIC, Javascript, and batch files run as source. Python, curiously enough, runs in both modes, depending on it's packaging.

This post has been edited by baavgai: 24 April 2011 - 05:51 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1