Wednesday, March 25, 2009

Difference Between Runtime & Compile Time

Computer programs execute in two distinct stages.


The inner workings of a computer remain a mystery to the typical user, who relies on the work of programmers to tell the computer what to do. The programmer must understand the way the computer expects to receive commands and the two stages of program execution -- compile time and runtime -- in addition to other concepts.


Compile Time


Compile time translates code from human language to machine language.


The first stage in the execution of a program, compile time, involves the translation from language that humans understand, or source code, to language that computers understand, or machine code. Source code contains words you recognize, numbers in decimal format and organizational groupings that make it easier to comprehend the flow of instructions. The compile time stage completes when the new program is an executable file.


Runtime


Runtime occurs as the computer executes the program.


The computer uses the instructions that compile time produces to execute the program. During runtime, the computer reads from the translation of the source code to accomplish the tasks the programmer has incorporated into the code. Every time someone executes the program, he does so in runtime.


Difference


Runtime and compile time make up two different stages of processing.


Compile time takes place only once, translating the source code into an executable file. The executable file can initiate runtime any number of times without ever needing to revisit compile time unless the program requires changes. Most users of programs experience only runtime.


Compile Time Errors


Compile time errors occur before your program becomes executable.


Errors can occur during both stages of program execution. Compile time errors, or syntax errors, exist in the source code. Examples include misspelled commands, incorrect order of operations, variable type mismatching and omission of necessary elements. A programmer can detect compile time errors quite easily because they're syntactical rather than logical. The compiler will generally point out a compile time error and either explain or give clues about fix them. If the compiler successfully produces an executable file from your source code, your program contains no compile time errors.


Catastrophic Runtime Errors


Runtime errors can cause your program to crash.


Runtime errors occur while a program executes. Catastrophic runtime errors cause a program to crash and stop execution prematurely. Examples include restricted memory access and division by zero. The statement x / y is correct syntactically, but if y contains the value 0 at runtime, it will crash the program. A programmer may find catching catastrophic runtime errors difficult because they usually occur only under certain conditions.


Logical Runtime Errors


Runtime errors can cause unintended behavior.


A logical error does not cause the program to crash, but makes it run in a way that the programmer did not intend. Consider a program with a menu of options that expects the user to enter the option number she desires. If the user enters a letter, the program, expecting a number, converts it to a numeric value and sends the user to one of the menu options. The program executes as though nothing is wrong instead of telling the user that she entered an invalid option.







Tags: source code, executable file, time errors, errors cause, program crash, your program