Tuesday, September 13, 2011

Evolution and History of Programming Languages

To build programs, people use languages that are similar to human language.  The results are translated into machine code, which computers understand.
Programming languages fall into three broad categories:
         Machine languages
          Assembly languages
          Higher-level languages

The Evolution of Programming Languages -
Machine Languages
         Machine languages (first-generation languages) are the most basic type of computer languages, consisting of strings of numbers the computer's hardware can use.
         Different types of hardware use different machine code.  For example, IBM computers use different machine language than Apple computers.

The Evolution of Programming Languages - Assembly Languages
         Assembly languages (second-generation languages) are only somewhat easier to work with than machine languages.
         To create programs in assembly language, developers use cryptic English-like phrases to represent strings of numbers.
         The code is then translated into object code, using a translator called an assembler.

The Evolution of Programming Languages -
Higher-Level Languages
Higher-level languages are more powerful than assembly language and allow the programmer to work in a more English-like environment.
Higher-level programming languages are divided into three "generations," each more powerful than the      last:
         Third-generation languages
         Fourth-generation languages
         Fifth-generation languages

Higher-Level Languages -
Fourth-Generation Languages
         Fourth-generation languages (4GLs) are even easier to use than 3GLs.
         4GLs may use a text-based environment (like a 3GL) or may allow the programmer to work in a visual environment, using graphical tools.
         The following languages are 4GLs:
o   Visual Basic (VB)
o   VisualAge
o   Authoring environments                          

Higher-Level Languages -
Fifth-Generation Languages
         Fifth-generation languages (5GLs) are an issue of debate in the programming community – some programmers            cannot agree that they even exist.
         These high-level languages would use artificial intelligence to create software, making 5GLs extremely difficult to develop.
         Solve problems using constraints rather than algorithms, used in Artificial Intelligence


Programing Languages by category 


Interpreted Programing Language:
Interpreted languages are programming in which programs may be executed from source code form, by an interpreter.
  •      Ant
  •      APL
  •      J
  •      Lisp  
  •      Lush
  •      MUMPS (an ANSI standard general purpose language
  •      Python
  •      S-Lang
  •      VBScript
  •      Windows PowerShell (Microsoft .NET-based CLI)

Procedural Programing Languages
Procedural programming languages are based on the concept of the unit and scope (the data viewing range of an executable code.
  •      Alma-0
  •      BASIC (BASICs are innocent of most modularity in (especially) versions before about 1990)
  •      C
  •      C++
  •      C#
  •      COBOL
  •      Combined Programming Language (CPL)
  •      D
  •      DASL
  •      Eiffel
  •      Fortran  
  •      Java
  •      Pascal 
  •      RPG

Scripting Programing Languages
  •      AppleScript
  •      ColdFusion
  •      Javascript
  •      F-Script
  •      Frink
  •      Game Maker Language (GML)
  •      JASS
  •      MAXScript
  •      Perl
  •      PHP (intended for Web servers)
  •      R
  •      S-Lang

Types of Programing Languages

Interpreted language
  is a programming language in which programs are 'indirectly' executed ("interpreted") by an interpreter program. This can be contrasted with a compiled language which is converted into machine code and then 'directly' executed by the host CPU.

Advantages of interpreting a language
Interpreting a language gives implementations some additional flexibility over compiled implementations. Features are often easier to implement in interpreters than in compilers include (but are not limited to):
   • platform independence (Java's byte code, for example)
   • reflection and reflective use of the evaluator (e.g. a first-order eval function)
   • dynamic typing
   • smaller executable program size (since implementations have flexibility to choose the instruction code)
   • dynamic scoping


Disadvantages of interpreted languages
The main disadvantage of interpreting is a much slower speed of program execution compared to direct machine code execution on the host CPU. A technique used to improve performance is just-in-time compilation which converts frequently executed sequences of interpreted instruction to host machine code.

APL (programming language)
  • (named after the book A Programming Language)[5] is an interactive array-oriented language and integrated development environment which is available from a number of commercial and non-commercial vendors[6] and for most computer platforms.
  • It is based on a mathematical notation developed by Kenneth E. Iverson and associates
  • is used in scientific,[10] actuarial,[9] statistical,[11] and financial applications where it is used by practitioners for their own work and by programmers to develop commercial applications. It was an important influence on the development of spreadsheets, functional programming,
BASIC
  • (an acronym which stands for Beginner's All-purpose Symbolic Instruction Code) is a family of high-level programming languages designed to be easy to use.
  • -    The original Dartmouth BASIC was designed in 1964 by John George Kemeny and Thomas Eugene Kurtz at Dartmouth College in New Hampshire, USA to provide computer access to non-science students.
  • The eight design principles of BASIC were:
    • Be easy for beginners to use.
    • Be a general-purpose programming language.
    • Allow advanced features to be added for experts (while keeping the language simple for beginners).
    • Be interactive.
    • Provide clear and friendly error messages.
    • Respond quickly for small programs.
    • Not to require an understanding of computer hardware.
    • Shield the user from the operating system.
COBOL
is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments.

Grace hopper – the mother of cobol language.
IBM – International Business Machines

Procedural Programming Language
derived from structured programming, based upon the concept of the procedure call.
  • Procedures, also known as routines, subroutines, methods, or functions  simply contain a series of computational steps to be carried out.
PASCAL
Pascal was designed in 1968/9 and published in 1970 by Mr. Niklaus Wirth.
Brief description

Wirth's intention was to create an efficient language (regarding both compilation speed and generated code) based on so-called structured programming, a concept which had recently become popular. Pascal has its roots in the ALGOL 60 language, but also introduced concepts and mechanisms which (on top of ALGOL's scalars and arrays) enabled programmers to define their own complex (structured) datatypes, and also made it easier to build dynamic and recursive data structures such as lists, trees and graphs. Important features included for this were records, enumerations, subranges, dynamically allocated variables with associated pointers, and sets. To make this possible and meaningful, Pascal has a strong typing on all objects, which means that one type of data cannot be converted or interpreted as another without explicit conversions. Similar mechanisms are standard in many programming languages today. Other languages that influenced Pascal's development were COBOL, Simula 67, and Wirth's own ALGOL W.

Pascal, like many programming languages of today (but unlike most languages in the C family), allows nested procedure definitions to any level of depth, and also allows most kinds of definitions and declarations inside procedures and functions. This enables a very simple and coherent syntax where a complete program is syntactically nearly identical to a single procedure or function (except for the keyword itself, of course.)

Java
•    Java is a programming language originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform
What is the function of the program?
•    It is intended to let application developers "write once, run anywhere". Java is currently one of the most popular programming languages in use, particularly for server-client web applications.

SCRIPTING PROGRAMMING LANGUGES
A scripting language, script language or extension language is a programming language that allows control of one or more applications. "Scripts" are distinct from the core code of the application, as they are usually written in a different language and are often created or at least modified by the end-user. Scripts are often interpreted from source code or bytecode, whereas the application is typically first compiled to native machine code.
Early script languages were often called batch languages or job control languages. Such early scripting languages were created to shorten the traditional edit-compile-link-run process.

PERL
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular amongst programmers.
    *CGI – Computer Graphic Interface

 Advantages:
* Portability: Perl code that doesn't use system specific features can be run on any platform, and these days almost every operating systems support it. So, for example, if you write an utility that renames files in a complete directory tree according to some rule, you will be able to run it on Windows and Unix (Linux, Solaris, AIX, BSD, etc), and probably Mac OS too. But if you write an utility that changes file permissions, you might run into problems, because file permission are implemented differently on different systems.

* String processing and especially Regular expression support: Perl is a winner in everything related to string processing. Its regular expression support is the most versatile in existence and seamlessly integrated into the language. (In fact, it is so good, that Perl has set a new standard for regular expression, which is now emulated in many other programs and languages).

* CPAN: has a huge collection of free and reusable Perl code for many purposes - Science, system administration, Mathematics, Biology, foreign languages, database access, networking, etc.

* It is a beautiful language that combines the best features from many other languages and is very easy to learn if you approach it properly. But that's also a matter of taste.

Disadvantages:
*You can't easily create a binary image ("exe") from a Perl file. It's not a serious problem on Unix, but it might be a problem on Windows. There are some utilities which can do it, but they are neither free nor portable.

*If you want to run your program on a different computer, you can't always be sure that Perl is installed everywhere. It is common enough on most modern Linux and Solaris installations, although some system administrators choose to not install it for various reasons. On Windows, though, it is not so common and you need to install it. The installation is easy to get and free, but it needs to be done before you can run anything.

*Moreover, if you write a script which uses modules from CPAN, and want to run it on another computer, you need to install all the modules on that other computer, which can be a drag.
 
PHP
 is a general-purpose scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. It also has evolved to include a command-line interface capability and can be used in standalone graphical applications. PHP can be deployed on most web servers and as a standalone interpreter, on almost every operating system and platform free of charge. A competitor to Microsoft's Active Server Pages (ASP) server-side script engine and similar languages, PHP is installed on more than 20 million websites and 1 million web servers.
PHP was originally created by Rasmus Lerdorf in 1995. The main implementation of PHP is now produced by The PHP Group and serves as the de facto standard for PHP as there is no formal specification. PHP is free software released under the PHP License which is incompatible with the GNU General Public License (GPL) due to restrictions on the usage of the term PHP.
 
JavaScript
JavaScript is a prototype-based, object-oriented scripting language that is dynamic, weakly typed and has first-class functions. It is also considered a functional programming language like Scheme and OCaml because it has closures and supports higher-order functions.
JavaScript is an implementation of the ECMAScript language standard and is primarily used in the form of client-side JavaScript, implemented as part of a web browser in order to provide enhanced user interfaces and dynamic websites. This enables programmatic access to computational objects within a host environment.
JavaScript's use in applications outside web pages—for example in PDF documents, site-specific browsers, and desktop widgets—is also significant. Newer and faster JavaScript VMs and frameworks built upon them (notably Node.js) have also increased the popularity of JavaScript for server-side web apps.
JavaScript uses syntax influenced by that of C. JavaScript copies many names and naming conventions from Java, but the two languages are otherwise unrelated and have very different semantics. The key design principles within JavaScript are taken from the Self and Scheme programming languages.
 
AppleScrip
AppleScript is a scripting language created by Apple Inc. and built into Macintosh operating systems since System 7. The term "AppleScript" may refer to the scripting system itself, or to particular scripts that are written in the AppleScript language.
AppleScript is primarily an inter-application processing system, designed to exchange data between and control other applications in order to automate repetitive tasks. AppleScript has some limited processing abilities of its own – basic calculation abilities, and some more intricate text processing tools – and is extensible, allowing the addition of scripting additions which add new functions to the language itself. Mainly, however, AppleScript relies on the built-in functionality of other applications and processes to handle complex tasks.
AppleScript has some elements of object-oriented programming, particularly in the construction of script objects, and some Lisp-like natural language processing tendencies, but does not strictly conform to either category.

GML
Game Maker Language (GML) is a scripting language developed for use with a computer game creation application called Game Maker. It was originally created by Mark Overmars to supplement the drag-and-drop action system used in Game Maker. However, in the latest versions, all the drag-and-drop actions translate to GML rather than being separate from it.
GML is heavily integrated with the Game Maker environment. Usually, elements such as sprites and sounds are all organized within the Game Maker IDE (though they can also be loaded from external files). Game Maker's architecture is designed to handle such things as event detection, level design, and object configuration without the need to code them manually, minimizing code verbosity with intuitive interface features.

FrinkFrink, named after the fictional mad scientist Professor John Frink, is a calculating tool and programming language designed by Alan Eliasen. It is built on the Java Virtual Machine and incorporates features similar to Java, Perl, Ruby, Smalltalk, and various BASIC implementations. Its main focus is on the fields of science, engineering, physics, text processing, and education.
One of the distinguishing characteristics of Frink is that it tracks units of measure through all calculations. This allows all values to contain a quantity and its units of measure. Frink understands how different units of measure interrelate, such as a length cubed is a volume, or power multiplied by time is energy. Different units of measure can be mixed in calculations, and Frink automatically ensures that the calculations lead to a result with the expected dimensions.

Wednesday, June 22, 2011

Adding and Subtracting binary numbers


Adding binary numbers

Adding binary numbers is very similar to adding decimal numbers, first an example:


 Let's look at the above example step by step:

1 + 1 = 0 (carry one)
1 + 1 (+ the carry) = 1 (carry one)
0 + 1 (+ the carry) = 0 (carry one)
1 + 0 (+ the carry) = 0 (carry one)
1 + 0 (+ the carry) = 0 (carry one)
0 + 1 (+ the carry) = 0 (carry one)
1 + 0 (+ the carry) = 0 (carry one)

The last carry is placed at the left hand side of the result giving: 10000010

reference: helpwithpcs.com

Subtracting Binary Numbers

The most common way of subtracting binary numbers is done by first taking the second value (the number to be subtracted) and apply what is known as two's complement, this is done in two steps:
  1. complement each digit in turn (change 1 for 0 and 0 for 1).
  2. add 1 (one) to the result.
note: the first step by itself is known as one's complement.

By applying these steps you are effectively turning the value into a negative number, and as when dealing with decimal numbers, if you add a negative number to a positive number then you are effectively subtracting to the same value.

In other words 25 + (-8) = 17, which is the same as writing 25 - 8 = 17.

An example, let's do the following subtraction 11101011 - 01100110 (23510 - 10210)
spr
note: When subtracting binary values it is important to maintain the same amount of digits for each number, even if it means placing zeroes to the left of the value to make up the digits, for instance, in our example we have added a zero to the left of the value 1100110 to make the amount of numerals up to 8 (one byte) 01100110.
spr
First we apply two's complement to 01100110








which gives us 10011010.

Now we need to add 11101011 + 10011010, however when you do the addition you always disregard the last carry, so our example would be:









which gives us 10000101, now we can convert this value into decimal, which gives 13310

So the full calculation in decimal is 23510 - 10210 = 13310 (correct !!)

reference: helpwithpcs.com