Sunday, April 17, 2011

Basic Control Structures

Four basic control structures in modern computer programming are a Sequence, a Selection, a Loop, and a Branch.  They all provide different ways for computers to follow programming languages.  In layman’s terms, they are maps for a computer to follow when reading code.  They tell computers where to go next.  Control Statements provide instructions on which statements to execute first and what path of statements to follow depending on the conditions provided in the present Control Structures.

A.  Sequence
 - The sequence control structure is the simplest of all basic control structures.  In a sequence, statements are executed in order, one after another, as the sequence states.  It is simply a series of statements with no decision making, looping, or branching.  Sequences are like a straight line.  There can be as many statements as you would like in a sequence as long as they are executed one after the next in the order determined by the programmer that wrote the Sequence. 

B.  Selection (Decision, If Then/Else) – A Selection Control structure is a structure that provides a decision when a question is asked.  Selection is limited to a true or false / yes or no statement.  When a question proves to be true then a statement or a sequence of statements will be executed.  When a question proves to be false a different statement of sequence of statements will be executed.  The If Then/Else statement is similar.  If something is true than a certain statement or sequence will be executed, if it is false than nothing will be executed and that statement or sequence will be skipped.  The Case Control structure is presented when you need an option for more than two alternative results.  It is basically an extended form of the Selection structure.

C.  Loop (looping, iteration) – A loop is a control structure that executes statements repeatedly.  Loops contain three basic parts:  a loop termination decision (determines when the loop will terminate), the body of the loop (the statements that are repeated in the loop), and a transfer to the beginning of the loop (returns control to the top of the loop, beginning a new iteration).  The two basic types of loops are the Pre-test Loop and the Post-test Loop.  A Pre-test Loop executes the loop termination decision first.  If conditions are favorable to execute the body of the loop, those statements are executed followed by a transfer to the beginning of the loop (the loop termination decision).  A Post-test Loop executes the body of the loop first, followed by the loop termination decision.  If conditions are favorable a transfer to the beginning of the loop is executed, followed by an iteration of the body of the loop.
                                        Pre-Test Loop                                                                        Post-Test Loop
















D.  Unconditional Branch (GOTO) – A Unconditional Branch Control Structure or GOTO Statement is a simple statement.  There is no decision to be made.  Basically it instructs the computer to jump to a specified label or line of code unconditionally (no matter what).  Most high-level languages use the GOTO instruction followed by a destination to perform this operation.  Similarly, a Conditional Branch Control Structure provides the same GOTO instruction but it is based on a Boolean (true/false) condition.  If the condition is true the GOTO instruction is followed, if the condition is false it does not.  The constructs of modern programming and the Control Structures listed above virtually eliminate the need for GOTO statements.  Today, GOTO statements are mostly required when writing error-handling code.

Wednesday, April 13, 2011

Data Structures, Data Types, and Data Representation


Global Variable – a variable that can be accessed by all modules and functions at any time.  It is not confined to a single block.  Global variables are commonly kept to a minimum because the more there are bug isolation is more difficult.

Local Variable – a variable that is confined to a single block.  Local variables are only accessible from the function or block of which it is declared to. 

Elementary Data Types
•Character – a single byte of information, either a single letter, number, or symbol
•String – a contiguous set of alphanumeric data that doesn’t contain numbers
                        used for calculations
•Integer
- a whole number or natural number, not a decimal or fraction
•Floating
- a number whose decimal can be placed anywhere relative to the
significant digits of that number
•Boolean
- a yes or no, true or false

Data Identifier (name) – a name that is assigned to a field or variable that identifies your data.

Its Data Type – part of a data identifier that classifies or identifies what type of data that various data is. 

Its Memory Address – an identifier for a memory location.  It relates the exact place in a computers memory that certain data is stored.

The Actual Data – is the data that can be manipulated depending on its type.  It is what all pointers point to.

A Variable – A symbolic name given to a value that can be changed or modified.

Literal – any data that is typed by a programmer and remains unchanged when translated into machine code.  An example would be a text message displayed on the screen or a constant numerical value used for calculation purposes.

Constant – any fixed value in a program such as error messages, dates, minimum and maximum amounts, etc.

Number Base Systems – a way to represent numbers where the base is the total amount of unique symbols used to represent numbers.

BASE 2 – A number system also known as binary.  It is “based” on two “numbers” or electrical states (on and off).  It is what every computers uses to operate, internally.

BASE 10 – A number system consisting of 10 digits (0, 1, 2 , 3, 4, 5, 6, 7, 8, 9).  It is the most widely used numerical system by modern civilizations.  Also known as decimal.

BASE 16 – A number system based on 16 numbers (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and (A, B, C, D, E, F) made to represent numbers 10-15.  Also known as Hexadecimal.

Floating Point – A method for storing and calculating numbers where the significant digits are stored in a separate place as the location of the radix or decimal point.

Decimal Data Representation – An exact type of numerical data that can hold a maximum of 38 digits, with the radix in any position

Direct Addressing - A memory address pertaining to data that directly identifies the storage location without using an intermediate reference.

Relative Addressing – A memory address pertaining to data that represents some distance from the base address.

Data Types and Data Abstraction – Data abstraction allows the handling of data bits in meaningful ways and is the basic motivation behind data type.  Data abstraction is a focused representation of an item or items.

•File
- a common denominator of storage containing a collection of bytes stored as an individual entity.
•Record
- a group of related fields that store data about a subject.  A collection of records makes up a file.
•Array
- an arrangement of data elements in a particular order.  An array can hold multiple variables.
1.Single Dimension
- also known as a vector, a vector array is like a list.
2.Multi dimension
- also known as a matrix, a matrix array arranges elements in a row and column form

Language Statements – a statement is the smallest element of imperative programming languages.  Imperative programming languages use a sequence of one or  more statements to form a program.
A. Natural Language Statements/Grammar and Logic
- statements using a natural language (a human language)
B. Artificial Language Statements/Syntax and Semantics
- statements using symbols that correspond to instructions in a programming language
C. Input/Output Statements
- a statement telling the computer where the input is coming from how to compute it and where to send the output
D. Assignment Statements
- used to assign a value to a variable
E. Program Design Language (PDL) - Meta Language
- a language used to make a statement about a statement in another language.
1.Syntax Diagrams
- a diagram that explains how the syntax of a language is used, each diagram has a beginning and end point, and shows all possible paths between these two points.
2.BNF
(Backus-Naur Form)- A notation technique used to describe the syntax of a language, mostly for exact descriptions of languages, probably used in the language’s manual.
F. Elementary Language Statements and Structured Language Statement
- elementary language statements are statements in a programming language at a basic level.  Structured language statements are statements that are paired together in order to minimize error.
1.Assignment and Unconditional Statements
- Assignment and Unconditional statements are statements that produce the same result unconditionally.
2.Selection and Looping Statement
- a selection statement is a statement that chooses to perform different actions or to perform no action, depending on the data it’s given.  A looping statement will repeatedly perform an action if the statement remains true, once the statement is false the action ceases.

Expressions Components – parts of a expression which include specific values, constants, variables, operators, and functions
A.  Operators, Operands and Results
- operators specify what operation to perform.  Operands specify what data is to be manipulated.  Results are what you get when operands are manipulated by operators.
            1.Unary
- when one operand is manipulated by and operator
            2.Binary
- when two operands are manipulated by an operator
B.  Simple Types

            1.Arithmetic
- using numerical values
            2.Logical
- using mathematical logic
            3.Relational – uses a model such as a spreadsheet to relate data
C.  Result

            1.Unconditional (Not Boolean)
- any result besides true or false
            2.Conditional (Boolean)
- A result of true or false


Sources:



Wednesday, March 30, 2011

Source Code vs. Executable Code

Source code and executable code are two terms for different levels of computer code.  They could both mean different things depending on the context they are spoken in.  Source code is generally the code given to a compiler or interpreter to create object code or target code.  In short it is the input code, while object or target code is the output.  Source code is generally a high-level language.  Computer code can go through several transformations before it is turned into machine code that is directly readable by the computer’s processor.  Therefore, the object code or target code of one device could be the source code of another.

Executable code is code that is directly executable by a computer’s processor.  Usually, it is machine code, an array of 1’s and 0’s that a computer can understand depending on the organization of these 1’s and 0’s.  However, in a general sense, executable code can also be a file containing instructions for an interpreter, such as bytecode or scripting language.

An Interpreter is an application that translates a higher-level computer language to a lower one and executes it at the moment the program is run.  Relating this to say a music program, it’s like hitting the space bar on a song you’ve recorded.  You instantly get to hear every track you’ve recorded, along with all the effects, automation, etc.  You can use this to listen to your work in progress and make tweaks to your song (program) in order to make it better and fix any flaws (bugs).

A Complier on the other hand does basically the same thing.  It translates your program from the high level language that you’ve written it into a lower one but it doesn’t do it in real time.  Instead it takes time to interpret your code and outputs object or target code.  Once completed you have your program but transferred to a different computer programming language.  In my mind this relates to a music program as an offline bounce to disk.  This is when you believe you have recorded everything you need to record, made all the edits you need, added all the effects you want, and completed all automation on every track.  When you are done with everything you can do to your song (program), you bounce it to a two track.  You choose the file format you would like your song to be converted into, the program then runs through the song and turns your multi-track project into a two-track stereo version, which can be played by any music player or burnt to a Compact Disc.

Assemblers take assembly language and convert it into machine code a computer’s processor can understand.  Assembly language is unique to each processor in language, but most use the same instruction statements that are used to define program operations.  Assembly language is the closest language to machine code.  Assemblers are used to squeeze the last bit of performance out of a processor by working near machine code level.  Because of this I relate it to the mastering process in music.  Once you have mixed all tracks of your multi-track recording and performed an offline bounce, creating a stereo two-track.  Mastering is the next step in which you make small tweaks to the equalization and compress the two-track to bring out every bit of feeling in your music.  This is similar because it squeezes every last bit of performance out of your two-track.  Also your mixed two-track before mastering is the closest representation of your song before it is finished, just as assembly code is one step away from machine code.

Wednesday, March 23, 2011

NetBeans with BlueJ or Visual Basic


When choosing an IDE (Integrated Development Environment) and GUI (Graphic User Interface) language for developing a small game, there are many different options.  Two of the most prominent Integrated Development Environments for GUI development are the NetBeans IDE BlueJ Plugin and the Visual Basic IDE.

Visual Basic is an object based and event driven programming language.  The Visual Basic language was derived from BASIC and allows programmers to create simple GUI applications and more complex applications.  Programming can be done by visually arranging components and controls. Components and controls are organized on forms using a drag and drop technique.  These components and controls contain default attributes and actions making a simple application easy to produce without writing many lines of code.  To create more complex applications these default attributes and actions can be modified by rewriting the code associated with them.  Visual Basic can create executable files, AxtiveX controls, and DLL files.  There are many small games available for free online written with Visual Basic, from poker games, RPG’s, tetris, minesweeper, etc.

NetBeans is an IDE used for developing with Java, JavaScript, Python, Ruby, C, C++, and other languages.  NetBeans is written in Java and can be used on any operating system with a Java Virtual Machine installed including Windows, Mac OSX, and Linux.  The GUI design tool is a drag and drop based GUI builder.  BlueJ is an IDE for Java and is primarily used for educational purposes but is also suitable for small application development.  BlueJ is now available as a plug-in inside the NetBeans IDE.  It assists BlueJ users in the transition to using NeatBeans, a more versatile and professional IDE.

Both Integrated Development Environments would be good for developing a Graphic User Interface for a small game.  Yet, each has some advantages depending on the circumstances of your project.  If you are proficient in Visual Basic I would stick with that.  Many simple games are written in Visual Basic. They can be easily created, edited, and compiled into an executable file.  The Visual Basic IDE’s user interface allows a developer to create a GUI with little to no actual code writing.

The NetBeans IDE’s BlueJ Plug-in also has its advantages.  NetBeans can be ran on any operating system because it is a Java based application.  Like Visual Basic, NetBeans has a very simple user interface.  The implementation of its drag and drop capabilities make it easy to use with little code writing necessary.  BlueJ allows a developer to see a clear layout of the application being written and its GUI.  Also with NetBeans you can utilize many different programming languages.

As an owner of a MacBook, I would choose to use the NetBeans IDE with the BlueJ plug-in.  My choice is mainly because it works with the OSX operating system, but I also like its ease of use and that it can help me transition to using the rest of the NetBeans IDE for more professional software development.  Visual Basic seems like it would be great for the job at hand (developing a GUI for a small game), but I like that NetBeans is able to create more advanced and professional software as well.

Monday, February 21, 2011

Object-Oriented Programming Languages

The following programming languages are some of the most commonly used object-oriented languages.  They are all similar in some ways and different in others.  Some are derived from the C language, some from Pascal.  Some incorporate Smalltalk, others do not.  Some are multi-paradigm languages.  Each language is different and has its advantages and disadvantages.  The program you are writing and its needs determine which language would best facilitate it.

JAVA
Java derives most of its syntax from C programming language.  Although it shares syntax with C it has a simpler object model and fewer low-level facilities.  Java uses a compiler to transfer Java programming language into Java bytecode, which can be interpreted by any Java Virtual Machine.  This enables Java programming language to be read by any computer regardless of the computer’s architecture.  The Java Virtual Machine acts as an interpreter for your computer and translates the bytecode into machine code readable by your computer.  This enables Java programming to be written once and run anywhere.  Due to its ability to be ran on any computer Java is currently one of the most popular programming languages.  It is used for application software and web applications.

C++
One of the most popular programming languages ever created is the C++ language.  C++ was derived from C with classes added to it.  C++ has many uses including: writing systems software, application software, device drivers, embedded software, high-performance server and client applications, hardware design synthesis, and video game software. 

Python
Python is a multi-paradigm programming language.  It permits the use of object-oriented programming, structured programming, functional programming, aspect-oriented programming, and many other paradigms with the use of extensions.  Languages such as C, C++, and Java are incorporated into Python.  Python is a scripting language that emphasizes code readability, simplicity, and ease of use.  Although C and C based languages are incorporated in Python, Python’s primary language abandons the C language for more readable commands.  Python utilizes dynamic typing and automatic memory management.  Python is a scripting language for web applications that is used by many large organizations including YouTube, Google, Yahoo!, CERN, and NASA.  It also is used for 3D animation packages and 2D imaging programs.

Objective-C
Objective-C is an object oriented programming language used primarily for Macintosh’s OS X and iOS operating systems.  Objective-C is a reflective language meaning that it can observe and modify its own structure and behavior in runtime.  Objective-C adds a Smalltalk style of messaging to the C programming language. Objective-C defers some decisions until runtime that C++ would make at compile time.  These decisions are known as dynamic dispatch, dynamic typing, and dynamic loading.

Delphi
Delphi is an object oriented, visual programming environment.  It is used to develop 32-bit and Microsoft.net applications that can be used on Windows and Linux operating systems as well as on the Internet.  Delphi has many different revisions, most currently Embarcadero Delphi XE, and is still evolving to complement evolving computer technologies.  Delphi allows you to build applications faster with pre-built components and a drag and drop visual design.  Many applications are written in Delphi including Skype and FL Studio (formerly Fruity Loops).

Ruby
Ruby is a general purpose, multi-paradigm, programming language that supports object-oriented, dynamic, functional, imperative, and reflective paradigms.  It utilizes syntax inspired by the Perl programming language with Smalltalk like features.  Ruby also uses a dynamic type system and automatic memory management like Python’s programming language.  Ruby is mainly used to create interactive web pages.

Wednesday, February 16, 2011

Interpreters and Compilers


Compilers and interpreters are programs that translate high-level programming languages or source code such as C++, Java, Pascal, Python, and Objective C into low-level languages such as machine code, and assembly language and vice versa.  While both types of programs do basically the same thing, the way they work is different.  Compilers will translate a whole program at once and create a file from your chosen programming language, which is executable by your operating system.  Interpreters translate your chosen programming language line by line.  It translates each line and runs those instructions before moving on to the next line.  Usually, compilers are used for more advanced programming languages such as C++ and Pascal, while interpreters are used for more basic languages such as JavaScript and Basic.

Compilers turn source code into machine code and save an executable file as the result of this process.  You can then open the executable file and your computer will run your program.  Compilers produce programs that can run quickly and compilers also can spot syntax errors as they are compiling and translating data.  Downsides can be a lengthy compile time and although compilers find errors, it still doesn’t mean your program will be completely free of errors.  A compiler’s complexity depends on the syntax of the language you are compiling.  A C compiler is much simpler than a compiler for C++ or C#.

Interpreters execute source code directly.  They do this by executing written high-level languages line by line.  The plus side to interpreters is that you could run programs without waiting for lengthy compile times to complete.   The problem is that they only store the machine code in memory instead of a separate executable file like a compiler does.  This makes distribution a problem because you would have to distribute your source code along with an interpreter that can convert your source code into machine code.  The original reason interpreters were invented is because compilers were so slow.  Nowadays, compilers are much faster and interpreters are mostly used for running scripted language and for learning purposes.

Interpreters and Compilers for BASIC, PASCAL, C, and C++ can easily be found with a simple Google search.  Simply search, “interpreter or compiler (whichever you are looking for) for a programming language and your operating system.”  There are tons of free interpreters and compilers out there for all of these languages.  For a Mac you get a free program with your operating system called XCode.  Although I haven’t used it yet I believe that it only compiles Objective C language.  To use XCode you need a Mac with an Intel processor, Mac’s Snow Leopard operating system, and you need to be registered as an Apple developer, but this is easy to do.  It’s just an online registration process and it’s free.  You can download XCode from Apple’s website or install it from your operating system install disk.

A few places I found with many compilers and interpreters are:

Once you have your interpreter or compiler, all you need is a text editor to write your code.  When your code is written, open your saved text file of your code and watch it come to life!

Monday, February 7, 2011

Common Programming Paradigms and the Language of the Future

Today there are many different Computer Programming Languages.  These languages are different, but use similar techniques called paradigms.  Deciding which language is best to use when writing your program is incredibly important.  To do this, find out what paradigms you would need to utilize to properly operate your program, and find a language that uses those paradigms.  Also using a commonly used language can be to your advantage.  Following, are four of the most common paradigms that programming languages use, and some advantages and disadvantages of each.

Object-Oriented Programming Languages are programming languages that use objects (independent entities which contain data and can respond to messages).  OOP is widely used, most commonly with the C++ and Java languages.  The advantages to using OOP include:  They are easier to learn, understand, manage, and maintain; objects can be derived from classes (a collection of objects of similar type) making similar objects easier to write; and OOP’s are easier to test and debug.  This is possible because if there is a problem with one or multiple objects, those objects can be independently re-written.  Otherwise a program would have to be re-written as a whole, taking much more time and effort.  OOP also does a good job of modeling the real world.  This is because ideas are organized like the real world with similar items (objects) grouped into categories (classes).

Although Object Oriented Languages are easier to manage and maintain, thus less expensive in the long run, there is a much higher upfront cost.  Thus it is used more for programs that are large and expected to be updated in the future.  OOP’s are best used for programming large applications.  For many small programs OOP gives no advantages over other languages and would require more time to write.  In addition OOP requires more memory to run, so if you are trying to write a small fast running program, OOP languages are the worst choice for your program.

Procedural Programming also known as imperative programming contains a series of steps for a computer to carry out.  Procedural Programming Languages utilize a small amount of memory, are simple in structure, and are easily implemented with compilers and interpreters.  The simplicity of Procedural Programming Languages makes it unusable when writing more complex programs.  It is considered to be less productive than other paradigms.  Procedural Programming carries out one process at a time, so when you are writing programs which require parallelization (two processes being completed at once) Procedural Programming languages are unable to carry this out.

Functional Programming Languages are computer languages that are treated by computers as mathematical functions.  It was derived from lambda calculus, by forming programs designed by the composition of functions.  Functional Programming avoids mutable data (objects that can be modified after it is created).  The earliest functional programming language was LISP, although it does contain non-functional elements.  LISP was pre-eminent in the development of Artificial Intelligence programs.  Advantages of Functional Programming are that programs can be easily understood, functions are reusable, and large programs containing thousands of functions are possible because the functions have no side effects.  Downsides to Functional Programming include efficiency (relating to it’s use of CPU and memory), difficulty doing input-output, and that some aspects of problem solving can’t be performed in a functional manner.

Logical Languages, including PROLOG (the most prominent Logical Programming Language), use predicates and rules of inference to determine an output.  Logical Languages are good at reasoning about programs, have well understand semantics, and can lead to concise solutions to problems.  Although Logical Programming can reason about programs they have trouble understanding and debugging large programs.  They also are slow in their execution and have a limited view of the world (only understands it’s predicates and rules of inference).

Of all the programming languages available today I think Objective C will be used frequently in the future.  It is used mainly for Mac’s OSX and iOS software.  There has been a surge in Objective C’s use in the past few years due to Apple’s iPhone and the high use of it’s apps.  This will only expand now that Verizon has the right to sell iPhones, ending AT&T’s exclusivity rights to the highly popular iPhone.  Python seems to be another language that is on the rise recently.  Many large corporations use Python including Google, Yahoo!, and YouTube.

Sources: