hans-peter plag october 16, 2014 session 3 programming languages data types and variables ...

14

Upload: evangeline-doyle

Post on 29-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Hans-Peter Plag October 16, 2014

Session 3Programming LanguagesData Types and Variables

http://www.mari.odu.edu

Expressions and OperatorsFlow Control Statements

Interpreter-based languages: are translated into machine code every time a script is executed (at run time).Compiler-based languages: are translated into machine code, then linked into an executable file. Can be executed afterwards (many times).

Interpreter-based languages: - syntax check, check of logic at run time- translation into machine code at run time reduces speed

Examples: - Linux/OS9 script (shell scripts) - PHP - Pearl - Javascript - Python

Compiler-based languages: - syntax check by compiler; check of some logic by compiler- compilation only once- linking checks libraries and compatibility with operating system- executable much faster than scripting language

Examples: - Fortran - C - C++ - Java

Steps:- write code in an editor- compile -> object code (binary)- link -> executable (binary)- test/validate

Steps:- write code in a shell/editor- execute (test/validate)

See more examples at: http://en.wikipedia.org/wiki/Comparison_of_programming_languagesSee also: http://en.wikibooks.org/wiki/Computer_Programming/Hello_world

See more examples at: http://en.wikipedia.org/wiki/Comparison_of_programming_languages

Fortran (2000): • originally based on ANSI Standards, now ISO standards: compilers are reliable• very good for numerical processing• also good for handling of text variables/strings• clear program control structures• subroutines and functions• very good tools for testing, validation, error detection • not good for interactions with the operating system or a GUI

There is a lot of code available in Fortran; mainly Fortran77 but also increasingly Fortran90/95/2000

C/C++: • based on ISO standards, latest is C++2014• very good for numerical processing• not that good for handling of text variables/strings• clear program control structures• procedures• reasonable tools for testing, validation, error detection • good for interactions with the operating system, less for a GUI• C++ very good for object-based programming

PHP: • no standard, de fact standard set by the interpreter• “hypertext preprocessor” • very good for web applications, generation of html code• can be used for stand-alone graphical applications using a command-line interpreter (CLI)

Python: • no standard• handles variable types dynamically• no limit to range of numbers• excellent file handling

How different is the syntax of languages?See: http://en.wikibooks.org/wiki/Computer_Programming/Hello_world

Data Types:Single-value:- Integer Numbers- Floating-point numbers- Logical/Booleans- Text/StringsCompound/collections:- Arrays- ObjectsResources/Handles- links to external resources (e.g. files)NULL data type- has no value

Variables: depends on programming languageFortran:Variables need to be declared before being used; some implicit declarationsinteger, integer*2/*4/*8; same for complexreal, real*4/*8/*16 logical, logical*1/*2/*4 character*narrays: type name(n1:m1, ..., nN,mN)Examples:integer nmax,nadd,nlinesparameter (nmax=1000,nadd=100,nlines=10)real*8 y(0:nmax),x(0:nmax,5)complex*8 z(nmax)character addresses*80(0:nadd,nlines)

Variables: depends on programming languagePHP:Variables are declared by usage (except for static variables)$a = 1;$b = “MARI”;$person[0] = “Jim”;$person[1] = “Smith”;$person[3] = “Norfolk”;$address[‘Name’] = “Jim Smith”;$address[‘City’] =”Norfolk”;

See more examples at: http://en.wikipedia.org/wiki/Comparison_of_programming_languages

Scope of Variables: depends on programming languageMany languages have local and global variables, depending on the declarationFortran has local variables and common blocks