Language Logic

esse quam videri
Revision as of 16:17, 27 October 2009 by Tyler.kendrick (talk | contribs) (Custom Objects)
Jump to: navigation, search

Programming Club


Contents

Objects

Objects in any programming language are sections of memory in a computer that store data.

Variables

Variables are objects that store data, and are given names, values and sometimes object types. The purpose of variables, are to store data for later use in a program. To do this, the computer's processor takes up a part of its memory and remembers the data you put into the variable.

Examples
Language Type Name Value
C/C++ int name = 0;
JAVA String Name = "Value";
C# string VariableName = "SomeValue";

Pointers

Pointers are created to "point" to parts of the computer's memory and keep track of an object in memory. When a variable is created in one part of a program, and used in a different part, it is common for a pointer to be used in its place; This way, a new variable doesn't have to be created, and less memory is used.

Examples
Language Declaration
C/C++ char* charPTR;
MC++ char^ charPTR;

Referencing

Pointers are references to an object's memory location - which store an object's data. Pointers can change the value of the object it is pointing to, and can keep an updated value from the object.

Examples
Language Referencing
C/C++ char* myVarPTR = &myVar;
MC++ char^ myVarPTR = &myVar;

De-referencing

When a pointer is de-referenced, the original object still retains its data, but the pointer becomes empty, and retains a null(empty) value.

Examples
Language De-referencing
C/C++ char myVar = *myVarPTR;
MC++ char myVar = ^myVarPTR;

Collections

Collections are groups of objects that share an object type, and can be managed as a group. Anytime you are using multiple objects for the same purpose, it is usually preferred to use a collection.

Examples
Language Declaration Initialization
C/C++ char[][2] name = {{"a", "b", "c"} {"d", "e", "f"} {"g", "h", "i"}};
JAVA int[] Name = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
Python L = [1, 2, 3, 4, 5]

Arrays

Arrays are a specific type of collection with a defined amount of items - meaning that it can only hold a maximum number of items.

Single-Dimensional Arrays

Single-Dimensional Arrays are among the most common collections in a program. These type of arrays simply keep an ordered, numbered collection of each object in the array - and are limited by a maximum defined number of objects they can hold.

Examples
Language Declaration Initialization
C/C++ char name[3] = {0, 2, 4};
Visual Basic Dim a() As Double = New Double(3) {0.1, 1.4, 4.3}
C# int[4] VariableName = {0, 1, 2, 3};
Multi-Dimensional Arrays

Multi-Dimensional Arrays are less common, and more complex than their single-dimensional counter-parts. These arrays contain a matrix of objects and are also limited by a maximum defined number of objects they can hold.

Examples
Language Declaration Initialization
Visual Basic Dim a(,) As Double = New Double(3, 2) {{1.0, 2.1, 3.2} {2.1, 1.2, 3.2}}
C# int[4, 2] VariableName = {{4, 5, 6, 7} {0, 1, 2, 3}};
Ada type MyType is array (1..4, 1..4, 1..4) of CHARACTER : MyVariable; PUT(MyVariable(2, 2, 2);
Jagged/Nested Arrays

Jagged Arrays (a.k.a. Nested Arrays) are exponentially more complex than single-dimensional arrays. These arrays contain other arrays that contain data, instead of the data itself. These arrays are also limited by a maximum defined number of arrays they can hold.

Examples
Language Declaration Initialization
C/C++ int jagged[][3] = { {0,1}, {1,2,3} };
Visual Basic Dim a()() As Char = New Char(1)() {New Char() {"a"c, "b"c}, New Char() {"p"c, "q"c}}
C# int[][] VariableName = new int[3][];

Lists

Lists are a specific type of collection with an undefined amount of items - meaning that it can hold as many items as the computer's memory allows. Lists are dynamic, and the size can be changed dynamically.

Examples
Language Declaration Initialization
JAVA List list = new LinkedList();
Visual Basic Dim list = List(Of Int)
C# List<int> list = new List<int>();
Python list = [1, 2, 3, 4, 5, 6]
LinkedLists

LinkedLists are complex structures that contain pointers to an object of the same structure type. The list is created by pointing to a new object of the same type, and creating a list where the pointers create a sequence of objects that they can then iterate through.

Examples
Language Declaration Initialization
C/C++ char name[3] = {0, 2, 4};
Visual Basic Dim a() As Double = New Double(3) {0.1, 1.4, 4.3}
C# LinkedList<int> list = new LinkedList();
Doubly-Linked Lists

Doubly-Linked Lists contain two pointers in a structure. These pointers then point to a new object of the same type, just like linked-lists; However, one pointer will point to the next object in the list, and the other will point to the previous item in the list. This way, the list can be iterated through in both directions.

Circular-Linked Lists

Circular-Linked Lists are most like normal Linked Lists in that they iterate in a single direction, through the use of a pointer to a structure of the same type contained within the structure. The difference, is that the structure contains a pointer to the beginning of the list, once it reaches the end. This way, it will repeat from the beginning of the list if needed.

Custom Objects

All objects listed below are commonly found in programs, and are defined by the programmer.

Functions/Methods

Functions and Methods are the reusable portions of code that tell our program how to interact with the data we give it. They both manipulate, and can return new data as a result of the action. Methods, however, differ from functions because they are contained within objects. A method is an object's way of interacting with data.

Structs/Interfaces

Structs and Interfaces are objects that contain only a single type of data or instructions. Structs are objects that can only contain data and pointers; Interfaces, however, are only able to contain methods and instructions that can be redefined elsewhere in a program (see virtual inheritance).

Classes/Modules

Classes and Modules are objects that contain a variety of data and methods to act as a single object.

Unions

Unions are objects that create multiple objects from the same location in memory.

Namespaces

Namespaces can contain any type of data or instruction. All previously mentioned objects can be contained in, and called from a namespace.

Object Relationships

This section is about the different ways that objects can interact with each other.

Inheritance (Is a...)

Through inheritance, an object can be considered to be another object. For example, a human is a mammal; a mammal is an animal; an animal is a creature; etc.

Wherever you can associate objects with one another with the term "...is a...", you can represent this through inheritance.

Single Inheritance

Single inheritance is the simplest form of inheritance, and allows one object to be considered as another object. For example: A human is a mammal; A mammal is an animal; An animal is a creature. However, through this type of association, objects cannot be considered as multiple types of objects. For example: A human is a mammal; A human cannot be a reptile.

Multiple Inheritance

Through Multiple inheritance, objects can be multiple types of objects. For example: A human is a mammal, AND a biped.

This creates many problems however, because the computer then has to decide, in which situation, the object is considered one object or the other.

Virtual Inheritance

Virtual inheritance occurs when an object inherits from a virtual object - meaning that the object becomes redefined by the derived member when it is inherited.

Polymorphism

Conditional Inheritance

Conditional inheritance is similar to multiple inheritance in that it allows for an object (such as a human) to be considered as multiple objects (like a mammal, AND a biped); However, this type of association requires the programmer to explicitly define the conditions where the object is defined as one or the other.

Containment (Has a...)

Containment occurs one object contains another object.

Encapsulation

Association(Uses a...)

Association occurs when one object uses another object.

Operators

Conditional

Ternary

Ternary operators check conditions, and return data based on the conditions. These operators are cascading as well, meaning they allow you to return another ternary operator.

Coalesce

Coalesce operators are equivalent to Ternary operators, but only check for null types. These operators are cascading as well, which allow you to return another coalesce operator.

Comparative

Greater Than

Less Than

Equal To

Not Equal To

Logical

Logical operators check for comparison types between two objects, such as equivalency, numerical seniority, and

AND

OR

NOT

Bitwise

Bitwise operators perform binary operations on data in a computer program. They can shift data forward and backwards, as well as mask/alter the binary data.

AND

OR

XOR

NOT

LEFTSHIFT

RIGHTSHIFT

LEFTSHIFTZEROS

Mathematical

In any language, a mathematical operator performs a simple mathematical expression on one or two variable types, resulting in a new instance of the object type, populated with the results of the mathematical operation.

Addition

Subtraction

Multiplication

Division

Absolute Value

Exponential

Functional

Lambda

Lambda expressions are usually exclusive to functional programming languages (languages that are optimized for manipulating collections of data objects). These operators create temporary, inline, anonymous methods or functions that apply a given expression to an operand.

Modifiers

Modifiers tell the compiler how the object will be stored; They determine what type of object it will be, where it will be stored, if it can be changed, and how it can be accessed. An object's modifiers are just as important as the data the object stores.

Object Types

An object type determines how the data will be handled; Will it be interpreted as a letter, or a number? Will the number handle decimals or will it ignore them?

There are many different object types, but most are variations of the following objects.

Byte

Bytes are objects that contain binary data up to a maximum value of 256. The data stored in this type is usually unhandled - meaning the programmer may choose how he/she would like to use it.

Integral

Integrals are any whole numbers that are handled using the basic math operators.

Boolean

Boolean values are values that abide by the basic boolean logic - False exists, and true is anything that is not false. (Usually, 0 is false, and anything else is considered true.)

Floating-Point

Floating-Point values are numbers with decimal values that present a number at the end to represent the degree of accuracy.

Decimal

True Decimal data types are typically very large in memory and gather very precise numeric data.

Generic

Generic data types are capable of being handled in any way, and are not limited to a specific data type.

Anonymous

Anonymous data types enable you to create objects without writing a class definition for the data type. Instead, the compiler generates a class for you.

Type Modifiers

Type modifiers tell the compiler how an object can be changed in a program.

Virtual

Virtual types allow for objects to be overridden in derived objects.

Immutable/Mutable

Mutable data types are objects that are subject to change. These are usually the default object types for a statement-based object-oriented language; Where Immutable data types are the standard for functional programming languages - which are data types that cannot be changed after they have been initialized (They have a constant value).

Linkage Specifications

Access Modifiers

Access modifiers define the scope and lifetime of an object in memory. Even though an object may be defined within an object, it is possible to give the object a higher scope and lifetime than the object that contains it.

File

File access objects are only accessible within files that are located in the same assembly.

Method/Function

Method/Function access objects are only accessible within the Method/Function being called, and are destroyed immediately after being used.

Object

object accessible objects are contained within the scope of the containing object, and can be used from within an instance of the object.

Namespace

Namespace accessible objects are available to any other object contained within the namespace.

Global

Global/Static accessible objects are available for use anywhere in a program.

Loops

Loops are methods of executing a function or series of functions, a number of times; This could be infinite or finite, and can even execute the commands only once.

Recursion

Recursion occurs when a method calls itself under specific conditions, resulting in a loop.

Repetition

Repetition occurs when a method is repeated a set number of times, in a consecutive sequence for a variable number of times.

Iteration

Iteration continues a repeated sequence of commands for a constant number of times.

Programming Paradigms