|
| |
Introduction
Most programming languages share a common set of features.
The purpose of this discussion is to provide an overview of general
principles found in programming languages.
Language Fundamentals
Program Structure and Organization
 | Most programs are constructed around:
 | Data declarations - local and global |
 | Functions that return values to calling agents. |
 | Subroutines that do some work but do not return values. |
 | Functions and subroutines may be built-in to the programming language. |
 | Programmers create functions and subroutines to implement an
application; typically these are built from existing and other user-defined
elements. |
 | Depending on the language, a pre-defined function or subroutine name is
the starting point for program execution. |
|
 | Program structure:
 | Links to other files that have supporting information such as additional
functions. |
 | Commenting code: most programming environments allow you to add
"English" comments to a program. |
|
 | Language/character sets: a character set for development (many use
ASCII text), and a character set for delivery. |
 | Identifiers and keywords: words and expressions that are
"off-limits" to user-defined functions and subroutines, for example:
 | if, then |
 | for, do, next |
 | dim, var |
 | single, double, float |
 | Note: keywords are specific to a language and do vary. |
|
 | Source code management: programs are written into files called
source code. Source code files are written with a variety of tools
including:
 | Text editors |
 | Integrated development environments (IDE) that include tools for
creating and manipulating program graphical objects. |
|
 | Program delivery:
 | Compiled: source programs are compiled to object files, linked,
and executable machine language programs are created. These are
typically operating system specific. Compiled programs tend to be
faster and use memory and processing resources more efficiently. |
 | Script: "English" code is evaluated and executed on the fly.
Tend to be slower than compiled but are easy to develop and deploy. |
 | Intermediate (e.g., byte code): source code is partially compiled
and executed via a run-time engine. |
|

Data Types
Data typing enable computers to manage elements of information (data) within
the confines of the limited computer memory resources.
Data typing tends to be "strong" or "weak":
 | Strongly typed languages (e.g., C, Java, etc.) require that you
declare variables before you use them. This enables efficient memory
management. |
 | Weakly typed languages (e.g. JavaScript, VBScript, and Visual
Basic) do not require that you declare variables before you use them.
The benefit is rapid development, but the downside is a loss in efficiency
(they generally require more memory to manage data and more processing to
figure things out). |
Data types cover the variety of ways that we represent and use data in the
real world:
 | Numbers
 | Integers |
 | Real numbers |
 | Amount of memory (i.e., number of bytes) determines the size of the
data, for example:
 | 2 bytes: integer, range: -32,768 to 32,768 |
 | 8 bytes: double/floating point, range: -1.79769313486232E308 to -4.94065645841247E-324 for negative values;
|
|
|
 | Strings/characters
 | Characters in a character format (e.g., ASCII). |
 | Single to large sets of characters. |
 | Typically one character = one byte. |
|
 | Boolean
 | True and False |
 | Some languages use a single 0 (false) or 1 (true); others have an
explicit Boolean data types. |
|
 | Void/null
 | Non-value assigned to a variable |
|
 | Other data types:
 | Date/time |
 | Currency |
 | Object |
 | BLOB (binary large object, e.g., graphics) |
|
 | Variant
 | "Universal" data type capable of holding numbers, strings, etc. |
|
 | Constants: built-in terms that have pre-defined values. |
 | Arrays
 | Single and multi-dimensional structures of data. |
 | Typically arrays are defined prior to use (size and data types). |
 | Some languages allow you dynamically re-dimension an array, others do
not. |
|
 | Variable declaration
 | Most languages require variables to be declared before use. |
 | Declaration: name of the variable and type. |
 | Most languages will initialize a variable before it is assigned a value,
e.g., a number initializes to 0 or a string to an empty string. |
 | May also include initializing the value of the variable. |
|
 | Variable scope
 | Local scope: variable exists within the lifetime of a function or
subroutine. |
 | Global scope: variable available to entire application for duration of
the program lifetime. |
|

Expressions and Operators
Math and logical operations are the heart of computer programs. They
enable the data to be manipulated, compared, stored, and processed.
 | Math operators
 | Basic arithmetic capabilities including addition, subtraction,
multiplication, and division. |
 | Basic math symbols used in most languages (+, -, *, ?). |
 | Precedence for algebra must be considered, e.g.,
 | 1 + 3 * 2 = 7 -- multiplication precedes addition. |
 | (1 + 3) * 2 = 8 -- use parenthesis to change precedence. |
|
 | May include advanced capabilities (e.g., exponent, modulus division,
increment, and decrement) |
|
 | Assignment operators
 | Enables variables to be set to a value. |
 | Typically represented by equal sign: = |
|
 | Relational operators
 | Compare data: equivalency, less-than, greater-than, etc. |
 | Most often deals with numbers; can also deal with text (e.g., "A" is
less than "B"). |
|
 | Logical operators
 | AND, OR, NOT |
 | Often used with relational operators to create complex program logic. |
|

Control Statements
if computers were limited to math operations, they would be called
calculators! Control statements enable data to be evaluated and processed.
 | If (expression) - then (action)
 | Most common method used in program operations to handle choice-based
reasoning (if-then logic). |
 | Typically consists of:
 | if (expression) - an expression that can be evaluated to a
true/false state by evaluation. |
 | then (action) - the action is one or more statements to be
accomplished if the if-expression is TRUE. |
 | else (action) - one or more statements to be accomplished if
the if-expression is FALSE. |
 | else-if (expression) - expressions are evaluated as encountered
- assumes prior expressions are evaluated in sequence. |
|
 | Evaluation expressions may be complex logical operations: e.g., if (a <
b AND c > d OR e = 5)
 | Short-circuit action may occur is "a" is not less than "b" - i.e., no
reason to continue evaluation; in some systems, all evaluations may be
processed regardless of subordinate logical operations. |
|
|
 | Select/switch
 | Evaluate a variable and then execute actions depending on the values for
each case. |
 | Essentially a form of if-then processing but implementation often makes
it more efficient. |
|
 | Do/While loop
 | Looping process in which a set of action statements are executed until
an evaluation expression evaluates to true. |
 | Loop evaluation may occur at beginning or end. |
 | Many implementations allow premature exit of the loop. |
|
 | For loop
 | Looping mechanism based on the evaluation of a numeric variable. |
 | Variable has starting point, ending point, comparison (equal, greater
than, etc.), and stepping function (increment by one, etc.). |
 | Many implementations allow premature exit of the loop. |
 | Object variations include ability to cycle through a collection of
objects or property elements of an object (for-each). |
|
 | Go To
 | Direct jump to a labeled segment of code (typically within the same
function/sub). |
 | Considered a weak programming practice. |
|
 | Break/exit
 | Various statements can be used to prematurely leave a processing loop,
function, or subroutine. |
 | These are typically combined with if-then expressions to trigger the
statement. |
|

Input/Output
 | Command Line
 | Most basic level of computer interfaces. |
 | Text-based interface. |
 | Based on keyboard and command line via the screen (text only). |
 | Program typically has explicit functions to get/display data; programs
are heavily I/O code dependent. |
|
 | Windows (GUI interface)
 | Based on mouse/keyboard and graphic screen interface. |
 | Event driven metaphor, most programs are driven by clicking, scrolling,
etc.. |
 | Operating system handles display of window elements and user input;
messages are sent to program to deal with user interactions. |
|
 | File I/O
 | Basic file operations: open and close; ability to read, write, or append
data to the file. |
 | Many languages enable you to read/write single to large numbers of
characters. |
 | Reading/writing may be based on set number of characters (fields), lines
terminated by carriage return line-feed sequences), or entire file sets. |
|
 | Database
 | Structured data files. |
 | Typically accessed by intermediate tools and interfaces (e.g., ODBC). |
 | May involve a data manipulation language such as SQL or intermediate
programming interface such as ADO. |
|

Libraries and Support
 | Internal routines
 | Many languages have sets of built-in functions and routines for a
variety of processes including:
 | Advanced string handling (search, replace, locate substrings). |
 | Advanced math (sin, cosine, etc.). |
 | Date/time functions |
 | File operations |
 | Database operations |
 | Advanced I/O functions. |
|
|
 | Program libraries:
 | Built-in libraries providing various processing capabilities. |
 | Additional user-defined, created, and developed libraries. |
|
|