Download presentation
Presentation is loading. Please wait.
1
Which Language is Better?
A compiled language, C++, compared to an interpreted language, Matlab.
2
Interpreted vs. Compiled
In computer science, interpret means to execute, while compile means to translate into the language of the computer (also known as, the “machine”). C++ is a compiled language. Matlab is an interpreted language (so is Java).
3
Compiled vs. Interpreted
program compiler running on computer machine code Computer interprets output input Matlab program translator running on computer pcode Interpreter, which runs on computer, interprets output input
4
Declared Variables vs. Undeclared Variables
C++ requires that every variable be “declared” before it is used (like Java). Declaration gives its name and “type”. Use before assignment gives random result. Matlab does not require declaration. Variable’s type is determined by its use. Use before assignment causes error.
5
Two example programs that do the same thing
One program is written in C++. One is written in Matlab.
6
// C++ program to calculate // weighted average void main(void) {
int N, i; float weights[3], sum_weights; float grades[3], sum, average; N = 3; cout << "Please input 3 grades: "; for (i = 0; i<N; i++){ cin >> grades[i]; } cout << "Please input 3 weights: "; cin >> weights[i]; sum = 0; sum_weights = 0; for (i = 0; i <N; i++){ sum += grades[i]*weights[i]; sum_weights += weights[i]; average = sum/sum_weights; cout << "Weighted average = " << average << endl; % Matlab program to calculate % weighted average grades = input('Please input 3 grades: '); weights = input('Please input 3 weights: '); average = sum(grades.*weights)/sum(weights); fprintf('Weighted average = %f\n', average);
7
Reasons for both approaches
Compiling emphasizes program speed Declaring variables gives the compiler more information for optimization. The source code is translated into “native” machine code (i.e., language of the computer). Interpreting emphasizes programming speed Freedom from variable declaration simplifies programming. The interpreter can give detailed debugging information.
8
Reasons for both approaches
SUMMARY: Compiled programs run faster. Interpreted programs are written faster. Another advantage to C++: For big programs (>10,000 lines), C++ makes it easier to employ disciplined programming techniques that reduce programming errors.
9
Which language is better?
For large programs that will be run by people who do not understand programming—C++ is best. For small engineering programs that will be run by people who do understand programming—Matlab is best.
10
Which language is better?
CONCLUSIONS: The language that best fits the task is the best language for that task. Until the task is specified, no language is better than any other.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.