<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Phoenix</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Phoenix"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Phoenix"/>
	<updated>2026-05-09T20:27:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26167</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26167"/>
		<updated>2009-10-15T00:13:33Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1].&lt;br /&gt;
&lt;br /&gt;
== Macros and Code generators ==&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Object-oriented languages ==&lt;br /&gt;
Let us compare the way [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is implemented in the following [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented languages] - [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] and [http://en.wikipedia.org/wiki/C%2B%2B C++].&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the declarations are also the executable statements and since Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic language] and is [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflective] it very well supports [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Ruby provides lot of methods that aids in metaprogramming. Ruby implements [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] through [http://en.wikipedia.org/wiki/Duck_typing duck typing] which is a metaprogramming. Here we will look at the example using the ''instance_eval''. ''eval'' is used to evaluate a string or a block and and the ''instance_eval'' is used to evaluate the object on which it is called upon [5].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[10,20].instance_eval('size')&lt;br /&gt;
&lt;br /&gt;
Output: 2&lt;br /&gt;
&lt;br /&gt;
# ''instance_eval'' used on the array to calculate the average value of an array&lt;br /&gt;
# the pseudo code is given below&lt;br /&gt;
&lt;br /&gt;
[10,20].instance_eval{''use the addition operator using inject''  / ''size''}&lt;br /&gt;
&lt;br /&gt;
Output: 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] also various language constructs that provide [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Some of them are ''[http://apidock.com/ruby/Module/class_variable_get class_variable_get]'', ''[http://apidock.com/ruby/Net/SMTP/send_message send_message]'', ''[http://apidock.com/ruby/Module/const_set const_set]'', ''[http://apidock.com/ruby/Module/const_get const_get]'' etc [5].&lt;br /&gt;
Consider another example [6] as shown below. If the user wants to know what the date and time 2 days ago was, he needs to just type in ''2.days.ago''. This computation is much easier and straightforward in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] as everything is defined as an object. It is similar to defining a ''macro'' where the values are computed based on the input parameter passed.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Display&lt;br /&gt;
  def days&lt;br /&gt;
    self * 24 * 60 * 60&lt;br /&gt;
  end&lt;br /&gt;
  def ago&lt;br /&gt;
    Time.now - self&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
2.days.ago&lt;br /&gt;
Output: ''date-time (a day before)''&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/C%2B%2B C++] has Macros through which act as [http://en.wikipedia.org/wiki/Metaprograms metaprograms] as explained in earlier section. This section shows how [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is done using templates and is known as [http://en.wikipedia.org/wiki/Template_metaprogramming Template metaprogramming]. The [http://en.wikipedia.org/wiki/C%2B%2B C++] [http://en.wikipedia.org/wiki/Compiler compiler] uses the [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] in order to generate the temporary source code ([http://en.wikipedia.org/wiki/Compile-time compile-time] execution). This code is later on merged with the rest of the code and then compiled together as whole. These [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] can output anything like [http://en.wikipedia.org/wiki/Data_structures data structures], constants([http://en.wikipedia.org/wiki/Compile-time compile-time] constants), functions etc [7].&lt;br /&gt;
Consider an example[7] which calculates the factorial of the numbers. This program is return in a normal way and is factorial of a number is calculated at [http://en.wikipedia.org/wiki/Run-time run-time].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int fact(int n) &lt;br /&gt;
{&lt;br /&gt;
    if (n == 0)&lt;br /&gt;
       return 1;&lt;br /&gt;
    return n * fact(n - 1);&lt;br /&gt;
}&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, fact(5)); //fact(5) = 120&lt;br /&gt;
}&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
However, in the code below templates are used. The computation of the factorial of ''5'' is done at compile time and the value is stored. Thus if the [http://en.wikipedia.org/wiki/Run-time run-time] value needs to access this value, it can access it as if it were stored in some table reference.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;int num&amp;gt;&lt;br /&gt;
struct fact &lt;br /&gt;
{&lt;br /&gt;
    enum { ret = num * fact&amp;lt;num - 1&amp;gt;::ret };&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    int val = fact&amp;lt;5&amp;gt;::ret; // returns 120 (5!)&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, val); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Ruby Vs C++ ==&lt;br /&gt;
Though [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] exists in [http://en.wikipedia.org/wiki/C%2B%2B C++] it is not as widely used as it is used in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby]. Most of the programmers might not even exploit the effectiveness of using templates in their programs. [http://en.wikipedia.org/wiki/C%2B%2B C++] does not have run-time extensibility and hence libraries cannot be generated by linking the templates. Hence templates are compiled at compile time and all the other files which use these templates must include the corresponding [http://en.wikipedia.org/wiki/Header_files header files] [8]. Hence code maintainability is difficult with templates. To use metaprogramming, templates or macros should be explicitly defined in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the language constructs itself provide metaprogramming and they are implicitly used and there is no need to explicitly define them. Most of the novice users might not even use templates and thus though metaprogramming exists, it might go unnoticed in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] the constructs are so widely present that the developers end up writing [http://en.wikipedia.org/wiki/Metaprograms metaprograms] even without their knowledge. Some of the [http://en.wikipedia.org/wiki/C%2B%2B C++] compilers might not support templates where as such a problem is not there in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby].&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] enahnces the performance of the programming language and also gives the ability to the programming languages to reduce the redundant code and handles it elegantly.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox &amp;lt;br&amp;gt;&lt;br /&gt;
6. http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
7. http://en.wikipedia.org/wiki/Template_metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
8. http://articles.techrepublic.com.com/5100-10878_11-1050219.html &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
5. [http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf Ruby Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
6. [http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html Ruby Metaprogramming Techniques] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26166</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26166"/>
		<updated>2009-10-15T00:12:29Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1].&lt;br /&gt;
&lt;br /&gt;
== Macros and Code generators ==&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Object-oriented languages ==&lt;br /&gt;
Let us compare the way [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is implemented in the following [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented languages] - [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] and [http://en.wikipedia.org/wiki/C%2B%2B C++].&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the declarations are also the executable statements and since Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic language] and is [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflective] it very well supports [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Ruby provides lot of methods that aids in metaprogramming. Ruby implements [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] through [http://en.wikipedia.org/wiki/Duck_typing duck typing] which is a metaprogramming. Here we will look at the example using the ''instance_eval''. ''eval'' is used to evaluate a string or a block and and the ''instance_eval'' is used to evaluate the object on which it is called upon [5].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[10,20].instance_eval('size')&lt;br /&gt;
&lt;br /&gt;
Output: 2&lt;br /&gt;
&lt;br /&gt;
# ''instance_eval'' used on the array to calculate the average value of an array&lt;br /&gt;
# the pseudo code is given below&lt;br /&gt;
&lt;br /&gt;
[10,20].instance_eval{''use the addition operator using inject''  / ''size''}&lt;br /&gt;
&lt;br /&gt;
Output: 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] also various language constructs that provide [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Some of them are ''[http://apidock.com/ruby/Module/class_variable_get class_variable_get]'', ''[http://apidock.com/ruby/Net/SMTP/send_message send_message]'', ''[http://apidock.com/ruby/Module/const_set const_set]'', ''[http://apidock.com/ruby/Module/const_get const_get]'' etc [5].&lt;br /&gt;
Consider another example [6] as shown below. If the user wants to know what the date and time 2 days ago was, he needs to just type in ''2.days.ago''. This computation is much easier and straightforward in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] as everything is defined as an object. It is similar to defining a ''macro'' where the values are computed based on the input parameter passed.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Display&lt;br /&gt;
  def days&lt;br /&gt;
    self * 24 * 60 * 60&lt;br /&gt;
  end&lt;br /&gt;
  def ago&lt;br /&gt;
    Time.now - self&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
2.days.ago&lt;br /&gt;
Output: ''date-time (a day before)''&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/C%2B%2B C++] has Macros through which act as [http://en.wikipedia.org/wiki/Metaprograms metaprograms] as explained in earlier section. This section shows how [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is done using templates and is known as [http://en.wikipedia.org/wiki/Template_metaprogramming Template metaprogramming]. The [http://en.wikipedia.org/wiki/C%2B%2B C++] [http://en.wikipedia.org/wiki/Compiler compiler] uses the [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] in order to generate the temporary source code ([http://en.wikipedia.org/wiki/Compile-time compile-time] execution). This code is later on merged with the rest of the code and then compiled together as whole. These [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] can output anything like [http://en.wikipedia.org/wiki/Data_structures data structures], constants([http://en.wikipedia.org/wiki/Compile-time compile-time] constants), functions etc [7].&lt;br /&gt;
Consider an example[7] which calculates the factorial of the numbers. This program is return in a normal way and is factorial of a number is calculated at [http://en.wikipedia.org/wiki/Run-time run-time].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int fact(int n) &lt;br /&gt;
{&lt;br /&gt;
    if (n == 0)&lt;br /&gt;
       return 1;&lt;br /&gt;
    return n * fact(n - 1);&lt;br /&gt;
}&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, fact(5)); //fact(5) = 120&lt;br /&gt;
}&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
However, in the code below templates are used. The computation of the factorial of ''5'' is done at compile time and the value is stored. Thus if the [http://en.wikipedia.org/wiki/Run-time run-time] value needs to access this value, it can access it as if it were stored in some table reference.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;int num&amp;gt;&lt;br /&gt;
struct fact &lt;br /&gt;
{&lt;br /&gt;
    enum { ret = num * fact&amp;lt;num - 1&amp;gt;::ret };&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    int val = fact&amp;lt;5&amp;gt;::ret; // returns 120 (5!)&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, val); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Ruby Vs C++ ==&lt;br /&gt;
Though [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] exists in [http://en.wikipedia.org/wiki/C%2B%2B C++] it is not as widely used as it is used in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby]. Most of the programmers might not even exploit the effectiveness of using templates in their programs. [http://en.wikipedia.org/wiki/C%2B%2B C++] does not have run-time extensibility and hence libraries cannot be generated by linking the templates. Hence templates are compiled at compile time and all the other files which use these templates must include the corresponding [http://en.wikipedia.org/wiki/Header_files header files] [8]. Hence code maintainability is difficult with templates. To use metaprogramming, templates or macros should be explicitly defined in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the language constructs itself provide metaprogramming and they are implicitly used and there is no need to explicitly define them. Most of the novice users might not even use templates and thus though metaprogramming exists, it might go unnoticed in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] the constructs are so widely present that the developers end up writing [http://en.wikipedia.org/wiki/Metaprograms metaprograms] even without their knowledge. Some of the [http://en.wikipedia.org/wiki/C%2B%2B C++] compilers might not support templates where as such a problem is not there in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby].&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] enahnces the performance of the programming language and also gives the ability to the programming languages to reduce the redundant code and handles it elegantly. &lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox &amp;lt;br&amp;gt;&lt;br /&gt;
6. http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
7. http://en.wikipedia.org/wiki/Template_metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
8. http://articles.techrepublic.com.com/5100-10878_11-1050219.html &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
5. [http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf Ruby Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
6. [http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html Ruby Metaprogramming Techniques] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26159</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26159"/>
		<updated>2009-10-15T00:00:48Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* Metaprogramming in Ruby Vs C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1].&lt;br /&gt;
&lt;br /&gt;
== Macros and Code generators ==&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Object-oriented languages ==&lt;br /&gt;
Let us compare the way [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is implemented in the following [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented languages] - [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] and [http://en.wikipedia.org/wiki/C%2B%2B C++].&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the declarations are also the executable statements and since Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic language] and is [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflective] it very well supports [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Ruby provides lot of methods that aids in metaprogramming. Ruby implements [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] through [http://en.wikipedia.org/wiki/Duck_typing duck typing] which is a metaprogramming. Here we will look at the example using the ''instance_eval''. ''eval'' is used to evaluate a string or a block and and the ''instance_eval'' is used to evaluate the object on which it is called upon [5].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[10,20].instance_eval('size')&lt;br /&gt;
&lt;br /&gt;
Output: 2&lt;br /&gt;
&lt;br /&gt;
# ''instance_eval'' used on the array to calculate the average value of an array&lt;br /&gt;
# the pseudo code is given below&lt;br /&gt;
&lt;br /&gt;
[10,20].instance_eval{''use the addition operator using inject''  / ''size''}&lt;br /&gt;
&lt;br /&gt;
Output: 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] also various language constructs that provide [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Some of them are ''[http://apidock.com/ruby/Module/class_variable_get class_variable_get]'', ''[http://apidock.com/ruby/Net/SMTP/send_message send_message]'', ''[http://apidock.com/ruby/Module/const_set const_set]'', ''[http://apidock.com/ruby/Module/const_get const_get]'' etc [5].&lt;br /&gt;
Consider another example [6] as shown below. If the user wants to know what the date and time 2 days ago was, he needs to just type in ''2.days.ago''. This computation is much easier and straightforward in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] as everything is defined as an object. It is similar to defining a ''macro'' where the values are computed based on the input parameter passed.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Display&lt;br /&gt;
  def days&lt;br /&gt;
    self * 24 * 60 * 60&lt;br /&gt;
  end&lt;br /&gt;
  def ago&lt;br /&gt;
    Time.now - self&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
2.days.ago&lt;br /&gt;
Output: ''date-time (a day before)''&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/C%2B%2B C++] has Macros through which act as [http://en.wikipedia.org/wiki/Metaprograms metaprograms] as explained in earlier section. This section shows how [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is done using templates and is known as [http://en.wikipedia.org/wiki/Template_metaprogramming Template metaprogramming]. The [http://en.wikipedia.org/wiki/C%2B%2B C++] [http://en.wikipedia.org/wiki/Compiler compiler] uses the [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] in order to generate the temporary source code ([http://en.wikipedia.org/wiki/Compile-time compile-time] execution). This code is later on merged with the rest of the code and then compiled together as whole. These [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] can output anything like [http://en.wikipedia.org/wiki/Data_structures data structures], constants([http://en.wikipedia.org/wiki/Compile-time compile-time] constants), functions etc [7].&lt;br /&gt;
Consider an example[7] which calculates the factorial of the numbers. This program is return in a normal way and is factorial of a number is calculated at [http://en.wikipedia.org/wiki/Run-time run-time].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int fact(int n) &lt;br /&gt;
{&lt;br /&gt;
    if (n == 0)&lt;br /&gt;
       return 1;&lt;br /&gt;
    return n * fact(n - 1);&lt;br /&gt;
}&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, fact(5)); //fact(5) = 120&lt;br /&gt;
}&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
However, in the code below templates are used. The computation of the factorial of ''5'' is done at compile time and the value is stored. Thus if the [http://en.wikipedia.org/wiki/Run-time run-time] value needs to access this value, it can access it as if it were stored in some table reference.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;int num&amp;gt;&lt;br /&gt;
struct fact &lt;br /&gt;
{&lt;br /&gt;
    enum { ret = num * fact&amp;lt;num - 1&amp;gt;::ret };&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    int val = fact&amp;lt;5&amp;gt;::ret; // returns 120 (5!)&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, val); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Ruby Vs C++ ==&lt;br /&gt;
Though [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] exists in [http://en.wikipedia.org/wiki/C%2B%2B C++] it is not as widely used as it is used in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby]. Most of the programmers might not even exploit the effectiveness of using templates in their programs. [http://en.wikipedia.org/wiki/C%2B%2B C++] does not have run-time extensibility and hence libraries cannot be generated by linking the templates. Hence templates are compiled at compile time and all the other files which use these templates must include the corresponding [http://en.wikipedia.org/wiki/Header_files header files] [8]. Hence code maintainability is difficult with templates. To use metaprogramming, templates or macros should be explicitly defined in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the language constructs itself provide metaprogramming and they are implicitly used and there is no need to explicitly define them. Most of the novice users might not even use templates and thus though metaprogramming exists, it might go unnoticed in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] the constructs are so widely present that the developers end up writing [http://en.wikipedia.org/wiki/Metaprograms metaprograms] even without their knowledge. Some of the [http://en.wikipedia.org/wiki/C%2B%2B C++] compilers might not support templates where as such a problem is not there in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby].&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] enahnces the performance of the programming language and also gives the ability to the programming languages to reduce the redundant code and handles it elegantly. &lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox &amp;lt;br&amp;gt;&lt;br /&gt;
[6] http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Template_metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://articles.techrepublic.com.com/5100-10878_11-1050219.html &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
5. [http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf Ruby Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
6. [http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html Ruby Metaprogramming Techniques] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26149</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26149"/>
		<updated>2009-10-14T23:52:14Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1].&lt;br /&gt;
&lt;br /&gt;
== Macros and Code generators ==&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Object-oriented languages ==&lt;br /&gt;
Let us compare the way [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is implemented in the following [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented languages] - [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] and [http://en.wikipedia.org/wiki/C%2B%2B C++].&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the declarations are also the executable statements and since Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic language] and is [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflective] it very well supports [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Ruby provides lot of methods that aids in metaprogramming. Ruby implements [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] through [http://en.wikipedia.org/wiki/Duck_typing duck typing] which is a metaprogramming. Here we will look at the example using the ''instance_eval''. ''eval'' is used to evaluate a string or a block and and the ''instance_eval'' is used to evaluate the object on which it is called upon [5].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[10,20].instance_eval('size')&lt;br /&gt;
&lt;br /&gt;
Output: 2&lt;br /&gt;
&lt;br /&gt;
# ''instance_eval'' used on the array to calculate the average value of an array&lt;br /&gt;
# the pseudo code is given below&lt;br /&gt;
&lt;br /&gt;
[10,20].instance_eval{''use the addition operator using inject''  / ''size''}&lt;br /&gt;
&lt;br /&gt;
Output: 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] also various language constructs that provide [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Some of them are ''[http://apidock.com/ruby/Module/class_variable_get class_variable_get]'', ''[http://apidock.com/ruby/Net/SMTP/send_message send_message]'', ''[http://apidock.com/ruby/Module/const_set const_set]'', ''[http://apidock.com/ruby/Module/const_get const_get]'' etc [5].&lt;br /&gt;
Consider another example [6] as shown below. If the user wants to know what the date and time 2 days ago was, he needs to just type in ''2.days.ago''. This computation is much easier and straightforward in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] as everything is defined as an object. It is similar to defining a ''macro'' where the values are computed based on the input parameter passed.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Display&lt;br /&gt;
  def days&lt;br /&gt;
    self * 24 * 60 * 60&lt;br /&gt;
  end&lt;br /&gt;
  def ago&lt;br /&gt;
    Time.now - self&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
2.days.ago&lt;br /&gt;
Output: ''date-time (a day before)''&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/C%2B%2B C++] has Macros through which act as [http://en.wikipedia.org/wiki/Metaprograms metaprograms] as explained in earlier section. This section shows how [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is done using templates and is known as [http://en.wikipedia.org/wiki/Template_metaprogramming Template metaprogramming]. The [http://en.wikipedia.org/wiki/C%2B%2B C++] [http://en.wikipedia.org/wiki/Compiler compiler] uses the [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] in order to generate the temporary source code ([http://en.wikipedia.org/wiki/Compile-time compile-time] execution). This code is later on merged with the rest of the code and then compiled together as whole. These [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] can output anything like [http://en.wikipedia.org/wiki/Data_structures data structures], constants([http://en.wikipedia.org/wiki/Compile-time compile-time] constants), functions etc [7].&lt;br /&gt;
Consider an example[7] which calculates the factorial of the numbers. This program is return in a normal way and is factorial of a number is calculated at [http://en.wikipedia.org/wiki/Run-time run-time].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int fact(int n) &lt;br /&gt;
{&lt;br /&gt;
    if (n == 0)&lt;br /&gt;
       return 1;&lt;br /&gt;
    return n * fact(n - 1);&lt;br /&gt;
}&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, fact(5)); //fact(5) = 120&lt;br /&gt;
}&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
However, in the code below templates are used. The computation of the factorial of ''5'' is done at compile time and the value is stored. Thus if the [http://en.wikipedia.org/wiki/Run-time run-time] value needs to access this value, it can access it as if it were stored in some table reference.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;int num&amp;gt;&lt;br /&gt;
struct fact &lt;br /&gt;
{&lt;br /&gt;
    enum { ret = num * fact&amp;lt;num - 1&amp;gt;::ret };&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    int val = fact&amp;lt;5&amp;gt;::ret; // returns 120 (5!)&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, val); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Ruby Vs C++ ==&lt;br /&gt;
Though [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] exists in [http://en.wikipedia.org/wiki/C%2B%2B C++] it is not as widely used as it is used in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby]. Most of the programmers might not even exploit the effectiveness of using templates in their programs. [http://en.wikipedia.org/wiki/C%2B%2B C++] does not have run-time extensibility and hence libraries cannot be generated by linking the templates. Hence templates are compiled at compile time and all the other files which use these templates must include the corresponding header files [8]. Hence code maintainability is difficult with templates. To use metaprogramming, templates or macros should be explicitly defined in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the language constructs itself provide metaprogramming and they are implicitly used and there is no need to explicitly define them. Most of the novice users might not even use templates and thus though metaprogramming exists, it might go unnoticed in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] the constructs are so widely present that the developers end up writing [http://en.wikipedia.org/wiki/Metaprograms metaprograms] even without their knowledge. Some of the [http://en.wikipedia.org/wiki/C%2B%2B C++] compilers might not support templates where as such a problem is not there in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby].&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] enahnces the performance of the programming language and also gives the ability to the programming languages to reduce the redundant code and handles it elegantly. &lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox &amp;lt;br&amp;gt;&lt;br /&gt;
[6] http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Template_metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://articles.techrepublic.com.com/5100-10878_11-1050219.html &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
5. [http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf Ruby Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
6. [http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html Ruby Metaprogramming Techniques] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26147</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26147"/>
		<updated>2009-10-14T23:46:16Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Macros and Code generators ==&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Object-oriented languages ==&lt;br /&gt;
Let us compare the way [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is implemented in the following [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented languages] - [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] and [http://en.wikipedia.org/wiki/C%2B%2B C++].&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the declarations are also the executable statements and since Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic language] and is [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflective] it very well supports [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Ruby provides lot of methods that aids in metaprogramming. Ruby implements [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] through [http://en.wikipedia.org/wiki/Duck_typing duck typing] which is a metaprogramming. Here we will look at the example using the ''instance_eval''. ''eval'' is used to evaluate a string or a block and and the ''instance_eval'' is used to evaluate the object on which it is called upon [5].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[10,20].instance_eval('size')&lt;br /&gt;
&lt;br /&gt;
Output: 2&lt;br /&gt;
&lt;br /&gt;
# ''instance_eval'' used on the array to calculate the average value of an array&lt;br /&gt;
# the pseudo code is given below&lt;br /&gt;
&lt;br /&gt;
[10,20].instance_eval{''use the addition operator using inject''  / ''size''}&lt;br /&gt;
&lt;br /&gt;
Output: 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] also various language constructs that provide [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Some of them are ''[http://apidock.com/ruby/Module/class_variable_get class_variable_get]'', ''[http://apidock.com/ruby/Net/SMTP/send_message send_message]'', ''[http://apidock.com/ruby/Module/const_set const_set]'', ''[http://apidock.com/ruby/Module/const_get const_get]'' etc [5].&lt;br /&gt;
Consider another example [6] as shown below. If the user wants to know what the date and time 2 days ago was, he needs to just type in ''2.days.ago''. This computation is much easier and straightforward in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] as everything is defined as an object. It is similar to defining a ''macro'' where the values are computed based on the input parameter passed.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Display&lt;br /&gt;
  def days&lt;br /&gt;
    self * 24 * 60 * 60&lt;br /&gt;
  end&lt;br /&gt;
  def ago&lt;br /&gt;
    Time.now - self&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
2.days.ago&lt;br /&gt;
Output: ''date-time (a day before)''&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/C%2B%2B C++] has Macros through which act as [http://en.wikipedia.org/wiki/Metaprograms metaprograms] as explained in earlier section. This section shows how [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is done using templates and is known as [http://en.wikipedia.org/wiki/Template_metaprogramming Template metaprogramming]. The [http://en.wikipedia.org/wiki/C%2B%2B C++] [http://en.wikipedia.org/wiki/Compiler compiler] uses the [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] in order to generate the temporary source code ([http://en.wikipedia.org/wiki/Compile-time compile-time] execution). This code is later on merged with the rest of the code and then compiled together as whole. These [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] can output anything like [http://en.wikipedia.org/wiki/Data_structures data structures], constants([http://en.wikipedia.org/wiki/Compile-time compile-time] constants), functions etc [7].&lt;br /&gt;
Consider an example[7] which calculates the factorial of the numbers. This program is return in a normal way and is factorial of a number is calculated at [http://en.wikipedia.org/wiki/Run-time run-time].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int fact(int n) &lt;br /&gt;
{&lt;br /&gt;
    if (n == 0)&lt;br /&gt;
       return 1;&lt;br /&gt;
    return n * fact(n - 1);&lt;br /&gt;
}&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, fact(5)); //fact(5) = 120&lt;br /&gt;
}&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
However, in the code below templates are used. The computation of the factorial of ''5'' is done at compile time and the value is stored. Thus if the [http://en.wikipedia.org/wiki/Run-time run-time] value needs to access this value, it can access it as if it were stored in some table reference.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;int num&amp;gt;&lt;br /&gt;
struct fact &lt;br /&gt;
{&lt;br /&gt;
    enum { ret = num * fact&amp;lt;num - 1&amp;gt;::ret };&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    int val = fact&amp;lt;5&amp;gt;::ret; // returns 120 (5!)&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, val); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Ruby Vs C++ ==&lt;br /&gt;
Though [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] exists in [http://en.wikipedia.org/wiki/C%2B%2B C++] it is not as widely used as it is used in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby]. Most of the programmers might not even exploit the effectiveness of using templates in their programs. [http://en.wikipedia.org/wiki/C%2B%2B C++] does not have run-time extensibility and hence libraries cannot be generated by linking the templates. Hence templates are compiled at compile time and all the other files which use these templates must include the corresponding header files [8]. Hence code maintainability is difficult with templates. To use metaprogramming, templates or macros should be explicitly defined in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the language constructs itself provide metaprogramming and they are implicitly used and there is no need to explicitly define them. Most of the novice users might not even use templates and thus though metaprogramming exists, it might go unnoticed in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] the constructs are so widely present that the developers end up writing [http://en.wikipedia.org/wiki/Metaprograms metaprograms] even without their knowledge. Some of the [http://en.wikipedia.org/wiki/C%2B%2B C++] compilers might not support templates where as such a problem is not there in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby].&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1].&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox &amp;lt;br&amp;gt;&lt;br /&gt;
[6] http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Template_metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://articles.techrepublic.com.com/5100-10878_11-1050219.html &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
5. [http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf Ruby Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
6. [http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html Ruby Metaprogramming Techniques] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26142</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26142"/>
		<updated>2009-10-14T23:42:28Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Object-oriented languages ==&lt;br /&gt;
Let us compare the way [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is implemented in the following [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented languages] - [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] and [http://en.wikipedia.org/wiki/C%2B%2B C++].&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the declarations are also the executable statements and since Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic language] and is [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflective] it very well supports [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Ruby provides lot of methods that aids in metaprogramming. Ruby implements [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] through [http://en.wikipedia.org/wiki/Duck_typing duck typing] which is a metaprogramming. Here we will look at the example using the ''instance_eval''. ''eval'' is used to evaluate a string or a block and and the ''instance_eval'' is used to evaluate the object on which it is called upon [5].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[10,20].instance_eval('size')&lt;br /&gt;
&lt;br /&gt;
Output: 2&lt;br /&gt;
&lt;br /&gt;
# ''instance_eval'' used on the array to calculate the average value of an array&lt;br /&gt;
# the pseudo code is given below&lt;br /&gt;
&lt;br /&gt;
[10,20].instance_eval{''use the addition operator using inject''  / ''size''}&lt;br /&gt;
&lt;br /&gt;
Output: 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] also various language constructs that provide [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Some of them are ''[http://apidock.com/ruby/Module/class_variable_get class_variable_get]'', ''[http://apidock.com/ruby/Net/SMTP/send_message send_message]'', ''[http://apidock.com/ruby/Module/const_set const_set]'', ''[http://apidock.com/ruby/Module/const_get const_get]'' etc [5].&lt;br /&gt;
Consider another example [6] as shown below. If the user wants to know what the date and time 2 days ago was, he needs to just type in ''2.days.ago''. This computation is much easier and straightforward in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] as everything is defined as an object. It is similar to defining a ''macro'' where the values are computed based on the input parameter passed.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Display&lt;br /&gt;
  def days&lt;br /&gt;
    self * 24 * 60 * 60&lt;br /&gt;
  end&lt;br /&gt;
  def ago&lt;br /&gt;
    Time.now - self&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
2.days.ago&lt;br /&gt;
Output: ''date-time (a day before)''&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/C%2B%2B C++] has Macros through which act as [http://en.wikipedia.org/wiki/Metaprograms metaprograms] as explained in earlier section. This section shows how [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is done using templates and is known as [http://en.wikipedia.org/wiki/Template_metaprogramming Template metaprogramming]. The [http://en.wikipedia.org/wiki/C%2B%2B C++] [http://en.wikipedia.org/wiki/Compiler compiler] uses the [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] in order to generate the temporary source code ([http://en.wikipedia.org/wiki/Compile-time compile-time] execution). This code is later on merged with the rest of the code and then compiled together as whole. These [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] can output anything like [http://en.wikipedia.org/wiki/Data_structures data structures], constants([http://en.wikipedia.org/wiki/Compile-time compile-time] constants), functions etc [7].&lt;br /&gt;
Consider an example[7] which calculates the factorial of the numbers. This program is return in a normal way and is factorial of a number is calculated at [http://en.wikipedia.org/wiki/Run-time run-time].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int fact(int n) &lt;br /&gt;
{&lt;br /&gt;
    if (n == 0)&lt;br /&gt;
       return 1;&lt;br /&gt;
    return n * fact(n - 1);&lt;br /&gt;
}&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, fact(5)); //fact(5) = 120&lt;br /&gt;
}&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
However, in the code below templates are used. The computation of the factorial of ''5'' is done at compile time and the value is stored. Thus if the [http://en.wikipedia.org/wiki/Run-time run-time] value needs to access this value, it can access it as if it were stored in some table reference.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;int num&amp;gt;&lt;br /&gt;
struct fact &lt;br /&gt;
{&lt;br /&gt;
    enum { ret = num * fact&amp;lt;num - 1&amp;gt;::ret };&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    int val = fact&amp;lt;5&amp;gt;::ret; // returns 120 (5!)&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, val); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Ruby Vs C++ ==&lt;br /&gt;
Though [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] exists in [http://en.wikipedia.org/wiki/C%2B%2B C++] it is not as widely used as it is used in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby]. Most of the programmers might not even exploit the effectiveness of using templates in their programs. [http://en.wikipedia.org/wiki/C%2B%2B C++] does not have run-time extensibility and hence libraries cannot be generated by linking the templates. Hence templates are compiled at compile time and all the other files which use these templates must include the corresponding header files [8]. Hence code maintainability is difficult with templates. To use metaprogramming, templates or macros should be explicitly defined in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the language constructs itself provide metaprogramming and they are implicitly used and there is no need to explicitly define them. Most of the novice users might not even use templates and thus though metaprogramming exists, it might go unnoticed in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] the constructs are so widely present that the developers end up writing [http://en.wikipedia.org/wiki/Metaprograms metaprograms] even without their knowledge. Some of the [http://en.wikipedia.org/wiki/C%2B%2B C++] compilers might not support templates where as such a problem is not there in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby].&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox &amp;lt;br&amp;gt;&lt;br /&gt;
[6] http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Template_metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://articles.techrepublic.com.com/5100-10878_11-1050219.html &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
5. [http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf Ruby Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
6. [http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html Ruby Metaprogramming Techniques] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26141</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26141"/>
		<updated>2009-10-14T23:41:44Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Object-oriented languages ==&lt;br /&gt;
Let us compare the way [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is implemented in the following [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented languages] - [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] and [http://en.wikipedia.org/wiki/C%2B%2B C++].&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the declarations are also the executable statements and since Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamic language] and is [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflective] it very well supports [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Ruby provides lot of methods that aids in metaprogramming. Ruby implements [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] through [http://en.wikipedia.org/wiki/Duck_typing duck typing] which is a metaprogramming. Here we will look at the example using the ''instance_eval''. ''eval'' is used to evaluate a string or a block and and the ''instance_eval'' is used to evaluate the object on which it is called upon [5].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[10,20].instance_eval('size')&lt;br /&gt;
&lt;br /&gt;
Output: 2&lt;br /&gt;
&lt;br /&gt;
# ''instance_eval'' used on the array to calculate the average value of an array&lt;br /&gt;
# the pseudo code is given below&lt;br /&gt;
&lt;br /&gt;
[10,20].instance_eval{''use the addition operator using inject''  / ''size''}&lt;br /&gt;
&lt;br /&gt;
Output: 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] also various language constructs that provide [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming]. Some of them are ''[http://apidock.com/ruby/Module/class_variable_get class_variable_get]'', ''[http://apidock.com/ruby/Net/SMTP/send_message send_message]'', ''[http://apidock.com/ruby/Module/const_set const_set]'', ''[http://apidock.com/ruby/Module/const_get const_get]'' etc [5].&lt;br /&gt;
Consider another example [6] as shown below. If the user wants to know what the date and time 2 days ago was, he needs to just type in ''2.days.ago''. This computation is much easier and straightforward in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] as everything is defined as an object. It is similar to defining a ''macro'' where the values are computed based on the input parameter passed.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Display&lt;br /&gt;
  def days&lt;br /&gt;
    self * 24 * 60 * 60&lt;br /&gt;
  end&lt;br /&gt;
  def ago&lt;br /&gt;
    Time.now - self&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
2.days.ago&lt;br /&gt;
Output: ''date-time (a day before)''&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
[http://en.wikipedia.org/wiki/C%2B%2B C++] has Macros through which act as [http://en.wikipedia.org/wiki/Metaprograms metaprograms] as explained in earlier section. This section shows how [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] is done using templates and is known as [http://en.wikipedia.org/wiki/Template_metaprogramming Template metaprogramming]. The [http://en.wikipedia.org/wiki/C%2B%2B C++] [http://en.wikipedia.org/wiki/Compiler compiler] uses the [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] in order to generate the temporary source code ([http://en.wikipedia.org/wiki/Compile-time compile-time] execution). This code is later on merged with the rest of the code and then compiled together as whole. These [http://en.wikipedia.org/wiki/Template_%28programming%29 templates] can output anything like [http://en.wikipedia.org/wiki/Data_structures data structures], constants([http://en.wikipedia.org/wiki/Compile-time compile-time] constants), functions etc [7].&lt;br /&gt;
Consider an example[7] which calculates the factorial of the numbers. This program is return in a normal way and is factorial of a number is calculated at [http://en.wikipedia.org/wiki/Run-time run-time].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int fact(int n) &lt;br /&gt;
{&lt;br /&gt;
    if (n == 0)&lt;br /&gt;
       return 1;&lt;br /&gt;
    return n * fact(n - 1);&lt;br /&gt;
}&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, fact(5)); //fact(5) = 120&lt;br /&gt;
}&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
However, in the code below templates are used. The computation of the factorial of ''5'' is done at compile time and the value is stored. Thus if the [http://en.wikipedia.org/wiki/Run-time run-time] value needs to access this value, it can access it as if it were stored in some table reference.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;int num&amp;gt;&lt;br /&gt;
struct fact &lt;br /&gt;
{&lt;br /&gt;
    enum { ret = num * fact&amp;lt;num - 1&amp;gt;::ret };&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    int val = fact&amp;lt;5&amp;gt;::ret; // returns 120 (5!)&lt;br /&gt;
    printf(&amp;quot;%d&amp;quot;, val); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: 120&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Ruby Vs C++ ==&lt;br /&gt;
Though [http://en.wikipedia.org/wiki/Metaprogramming metaprogramming] exists in [http://en.wikipedia.org/wiki/C%2B%2B C++] it is not as widely used as it is used in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby]. Most of the programmers might not even exploit the effectiveness of using templates in their programs. [http://en.wikipedia.org/wiki/C%2B%2B C++] does not have run-time extensibility and hence libraries cannot be generated by linking the templates. Hence templates are compiled at compile time and all the other files which use these templates must include the corresponding header files [8]. Hence code maintainability is difficult with templates. To use metaprogramming, templates or macros should be explicitly defined in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby], most of the language constructs itself provide metaprogramming and they are implicitly used and there is no need to explicitly define them. Most of the novice users might not even use templates and thus though metaprogramming exists, it might go unnoticed in [http://en.wikipedia.org/wiki/C%2B%2B C++]. In [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby] the constructs are so widely present that the developers end up writing [http://en.wikipedia.org/wiki/Metaprograms metaprograms] even without their knowledge. Some of the [http://en.wikipedia.org/wiki/C%2B%2B C++] compilers might not support templates where as such a problem is not there in [http://en.wikipedia.org/wiki/Ruby_%28language%29 Ruby].&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox &amp;lt;br&amp;gt;&lt;br /&gt;
[6] http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://en.wikipedia.org/wiki/Template_metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://articles.techrepublic.com.com/5100-10878_11-1050219.html &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
5. [http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf Ruby Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
6. [http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html Ruby Metaprogramming Techniques] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26128</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26128"/>
		<updated>2009-10-14T23:00:00Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Object-oriented languages ==&lt;br /&gt;
Let us compare the way metaprogramming is implemented in the following object-oriented languages - Ruby and C++&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
In Ruby, most of the declarations are also the executable statements and since Ruby is a dynamic language and is reflective it very well supports metaprogramming. Ruby provides lot of methods that aids in metaprogramming. Here we will look at the example using the ''instance_eval''. ''eval'' is used to evaluate a string or a block and and the ''instance_eval'' is used to evaluate the object on which it is called upon [5].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[10,20].instance_eval('size')&lt;br /&gt;
&lt;br /&gt;
Output: 2&lt;br /&gt;
&lt;br /&gt;
# ''instance_eval'' used on the array to calculate the average value of an array&lt;br /&gt;
# the pseudo code is given below&lt;br /&gt;
&lt;br /&gt;
[10,20].instance_eval{''use the addition operator using inject''  / ''size''}&lt;br /&gt;
&lt;br /&gt;
Output: 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
Ruby also various language constructs that provide metaprogramming. Some of them are ''class_variable_get'', ''send'', ''const_set'', ''const_get'' etc [5].&lt;br /&gt;
Consider another example [6] as shown below. If the user wants to know what the date and time 2 days ago was, he needs to just type in ''2.days.ago''. This computation is much easier and straightforward in Ruby as everything is defined as an object. it is similar to defining a ''macro'' where the values are computed based on the input parameter passed.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Display&lt;br /&gt;
  def days&lt;br /&gt;
    self * 24 * 60 * 60&lt;br /&gt;
  end&lt;br /&gt;
  def ago&lt;br /&gt;
    Time.now - self&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
2.days.ago&lt;br /&gt;
Output: ''date-time (a day before)''&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
Ruby implements polymorphism through duck typing which is a metaprogramming.&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
C++ has Macros through which act as metaprograms as explained in earlier section. This section shows how metaprogramming is done using templates and is known as [http://en.wikipedia.org/wiki/Template_metaprogramming Template metaprogramming]. The C++ compiler uses the templates in order to generate the temporary source code (compile-time execution). This code is later on merged with the rest of the code and then compiled together as whole. These templates can output anything like data structures, constants(compile-time constants), functions etc [7].&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox &amp;lt;br&amp;gt;&lt;br /&gt;
[6] http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
5. [http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf Ruby Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
6. [http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html Ruby Metaprogramming Techniques] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26124</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26124"/>
		<updated>2009-10-14T22:53:56Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Object-oriented languages ==&lt;br /&gt;
Let us compare the way metaprogramming is implemented in the following object-oriented languages - Ruby and C++&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
In Ruby, most of the declarations are also the executable statements and since Ruby is a dynamic language and is reflective it very well supports metaprogramming. Ruby provides lot of methods that aids in metaprogramming. Here we will look at the example using the ''instance_eval''. ''eval'' is used to evaluate a string or a block and and the ''instance_eval'' is used to evaluate the object on which it is called upon [5].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[10,20].instance_eval('size')&lt;br /&gt;
&lt;br /&gt;
Output: 2&lt;br /&gt;
&lt;br /&gt;
# ''instance_eval'' used on the array to calculate the average value of an array&lt;br /&gt;
# the pseudo code is given below&lt;br /&gt;
&lt;br /&gt;
[10,20].instance_eval{''use the addition operator using inject''  / ''size''}&lt;br /&gt;
&lt;br /&gt;
Output: 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
Ruby also various language constructs that provide metaprogramming. Some of them are ''class_variable_get'', ''send'', ''const_set'', ''const_get'' etc [5].&lt;br /&gt;
Consider another example [6] as shown below. If the user wants to know what the date and time 2 days ago was, he needs to just type in ''2.days.ago''. This computation is much easier and straightforward in Ruby as everything is defined as an object. it is similar to defining a ''macro'' where the values are computed based on the input parameter passed.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Display&lt;br /&gt;
  def days&lt;br /&gt;
    self * 24 * 60 * 60&lt;br /&gt;
  end&lt;br /&gt;
  def ago&lt;br /&gt;
    Time.now - self&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
2.days.ago&lt;br /&gt;
Output: ''date-time (a day before)''&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
Ruby implements polymorphism through duck typing which is a metaprogramming.&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
C++ has Macros through which act as metaprograms as expalined in earlier section. This section shows how metaprogramming is done using templates.&lt;br /&gt;
  &lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox &amp;lt;br&amp;gt;&lt;br /&gt;
[6] http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
5. [http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf Ruby Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
6. [http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html Ruby Metaprogramming Techniques] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26116</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=26116"/>
		<updated>2009-10-14T22:38:20Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Object-oriented languages ==&lt;br /&gt;
Let us compare the way metaprogramming is implemented in the following object-oriented languages - Ruby and&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
In Ruby, most of the declarations are also the executable statements and since Ruby is a dynamic language and is reflective it very well supports metaprogramming. Ruby provides lot of methods that aids in metaprogramming. Here we will look at the example using the ''instance_eval''. ''eval'' is used to evaluate a string or a block and and the ''instance_eval'' is used to evaluate the object on which it is called upon [5].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[10,20].instance_eval('size')&lt;br /&gt;
&lt;br /&gt;
Output: 2&lt;br /&gt;
&lt;br /&gt;
# ''instance_eval'' used on the array to calculate the average value of an array&lt;br /&gt;
# the pseudo code is given below&lt;br /&gt;
&lt;br /&gt;
[10,20].instance_eval{''use the addition operator using inject''  / ''size''}&lt;br /&gt;
&lt;br /&gt;
Output: 15&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
Ruby also various language constructs that provide metaprogramming. Some of them are ''class_variable_get'', ''send'', ''const_set'', ''const_get'' etc [5].&lt;br /&gt;
Consider another example [6] as shown below. If the user wants to know what the date and time 2 days ago was, he needs to just type in ''2.days.ago''. This computation is much easier and straightforward in Ruby as everything is defined as an object. it is similar to defining a ''macro'' where the values are computed based on the input parameter passed.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Display&lt;br /&gt;
  def days&lt;br /&gt;
    self * 24 * 60 * 60&lt;br /&gt;
  end&lt;br /&gt;
  def ago&lt;br /&gt;
    Time.now - self&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
2.days.ago&lt;br /&gt;
Output: ''date-time (a day before)''&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox &amp;lt;br&amp;gt;&lt;br /&gt;
[6] http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
5. [http://video.kiberpipa.org/media/SU_David_Krmpotic-Meta-programiranje_v_Ruby-ju/Ruby_Metaprogramming.pdf Ruby Metaprogramming] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25344</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25344"/>
		<updated>2009-10-10T01:57:03Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* External Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
4. [http://qcodo.com/documentation/article.php/6 Code Generation Vs Metaprogramming] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25340</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25340"/>
		<updated>2009-10-10T01:55:20Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
=== Code Generators ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
1. [http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming The Ruby Object Model and Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
2. [http://www.dmoz.org/Computers/Programming/Metaprogramming/ Metaprogramming] &amp;lt;br&amp;gt;&lt;br /&gt;
3. [http://www.codeproject.com/KB/cpp/crc_meta.aspx Template Metaprogramming] &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25173</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25173"/>
		<updated>2009-10-10T00:52:12Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
== Code Generators ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the ''array_name'' is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25168</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25168"/>
		<updated>2009-10-10T00:51:18Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the ''SUM'' text in the program with the set of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] defined as the [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macro] [http://en.wikipedia.org/wiki/Directive_%28programming%29 directive].  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism in object-oriented languages].  In [http://en.wikipedia.org/wiki/C_language C] language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This [http://en.wikipedia.org/wiki/Preprocessor pre-processor] restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
== Code Generators ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Code_generator Code generators] (like [http://en.wikipedia.org/wiki/Flex_lexical_analyzer Flex], [http://en.wikipedia.org/wiki/GNU_bison Bison] etc.) are the programs that generate programs. Consider the code generator [http://en.wikipedia.org/wiki/Embedded_SQL Embedded SQL] that easily merges the [http://en.wikipedia.org/wiki/SQL SQL] entities into C and extends the language so that the database access from [http://en.wikipedia.org/wiki/C_language C] is done easily. This code generator produces C programs as output and makes the [http://en.wikipedia.org/wiki/Database database] access easy and error-free which would be otherwise done through the set of [http://en.wikipedia.org/wiki/Library_%28computer_science%29 libraries] [1]. Code generators generally take either a [http://en.wikipedia.org/wiki/Parse_tree parse tree] or an [http://en.wikipedia.org/wiki/Abstract_syntax_tree abstract syntax tree] as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the &amp;quot;array_name&amp;quot; is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metalanguage Metalanguage] is used to write the [http://en.wikipedia.org/wiki/Meta-programs metaprogams]. Some programming languages are also their own metalanguages. This property is known as [http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 reflection] and it helps metaprogramming [2]. &lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25098</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25098"/>
		<updated>2009-10-10T00:39:26Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating [http://en.wikipedia.org/wiki/Computer_program programs] is known as [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the [http://en.wikipedia.org/wiki/Run-time run-time] tasks at [http://en.wikipedia.org/wiki/Compile_time compile time] itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a Metaprogramming works – either through the [http://en.wikipedia.org/wiki/Application_Programming_Interfaces Application Programming Interfaces] (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single [http://en.wikipedia.org/wiki/Programming_language programming language] to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many [http://en.wikipedia.org/wiki/Programming_language programming languages] require lots of [http://en.wikipedia.org/wiki/Statement_%28programming%29 statements] to be typed to perform the tasks but [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the [http://en.wikipedia.org/wiki/Metaprograms Metaprograms] in other languages. However, the main reason behind using Metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of Metaprogamming.  One of them is for using the data at [http://en.wikipedia.org/wiki/Run-time run-time] through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of [http://en.wikipedia.org/wiki/Logarithm logarithmic] values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at [http://en.wikipedia.org/wiki/Compile_time compile time] or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of Metaprogramming is to replace [http://en.wikipedia.org/wiki/Boilerplate_%28text%29 boilerplate code]. Some of the programs might contain a set of [http://en.wikipedia.org/wiki/Error_handler error handlers] or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the Metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. [http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 Code generation] can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of Metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Metaprograms Metaprograms] provide a set of [http://en.wikipedia.org/wiki/Domain-specific_language domain-specific languages] which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using [http://en.wikipedia.org/wiki/Macro_language macro languages] [1]. [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] involves the usage of the textual macro language that consists of textual [http://en.wikipedia.org/wiki/Macro_%28computer_science%29 macros]. Textual macros do not have the knowledge of the [http://en.wikipedia.org/wiki/Programming_language programming language] but they affect the text of the programming language. The most widely used textual macro systems are [http://en.wikipedia.org/wiki/C_language C] [http://en.wikipedia.org/wiki/Preprocessor preprocessor] and [http://en.wikipedia.org/wiki/M4_%28computer_language%29 M4] macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/C_language C] programming language does not have good code-generation capability hence [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming] is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the SUM text in the program with the set of statements defined as the macro directive.  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as polymorphism in object-oriented languages.  In C language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This preprocessor restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
== Code Generators ==&lt;br /&gt;
&lt;br /&gt;
Code generators (like Flex, Bison, Gperf etc.) are the programs that generate programs. Consider the code generator Embedded SQL that easily merges the SQL entities into C and extends the language so that the database access from C is done easily. This code generator produces C programs as output and makes the database access easy and error-free which would be otherwise done through the set of libraries [1]. Code generators generally take either a parse tree or an abstract syntax tree as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the &amp;quot;array_name&amp;quot; is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25011</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=25011"/>
		<updated>2009-10-10T00:24:22Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating programs is known as Metaprogramming [1].  It means writing programs to generate programs. These programs take in either other programs or themselves as their data and manipulate them or finish the run-time tasks at compile time itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a metaprogramming works – either through the Application Programming Interfaces (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single programming language to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many programming languages require lots of statements to be typed to perform the tasks but metaprogramming eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the metaprograms in other languages. However, the main reason behind using metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of metaprogamming.  One of them is for using the data at run-time through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of logarithmic values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at compile time or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of metaprogramming is to replace boilerplate code. Some of the programs might contain a set of error handlers or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators. Code generation can be done either during compile-time or run-time or before compiling. All these forms of code generation are considered to be forms of metaprogramming [4].&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
Metaprograms provide a set of domain-specific languages which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using macro languages [1]. Metaprogramming involves the usage of the textual macro language that consists of textual macros. Textual macros do not have the knowledge of the programming language but they affect the text of the programming language. The most widely used textual macro systems are C preprocessor and M4 macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
C programming language does not have good code-generation capability hence metaprogramming is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro ''SUM'', which adds ''a'', ''b'' and stores the ''sum'' in ''a''. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the SUM text in the program with the set of statements defined as the macro directive.  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as polymorphism in object-oriented languages.  In C language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This preprocessor restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
== Code Generators ==&lt;br /&gt;
&lt;br /&gt;
Code generators (like Flex, Bison, Gperf etc.) are the programs that generate programs. Consider the code generator Embedded SQL that easily merges the SQL entities into C and extends the language so that the database access from C is done easily. This code generator produces C programs as output and makes the database access easy and error-free which would be otherwise done through the set of libraries [1]. Code generators generally take either a parse tree or an abstract syntax tree as a input which are converted to instructions while processing [3]. If a table of values have to be computed and used in the program, for instance if we need to generate the cube root of numbers from 5 to 100 and store it in an array there are three ways to accomplish this task. One way is to manually calculate all the cube roots of the numbers and initialize the array with those values which is not certainly the preferred option. Second approach is to write a program that calculates the cube roots and populates the array at run time. This takes more of user time and not a good option either. The third option uses the code generation strategy which is ideal to use under such circumstances. Consider the example below [1] -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//define a macro&lt;br /&gt;
Macro:array_name:data-type:start-index:end-index:default-value:expression-to-evaluate(parameter)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&amp;quot;%d&amp;quot;, array_name[index]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Build a code generator for &amp;quot;Macro&amp;quot; that evaluates &amp;quot;expression-to-evaluate&amp;quot;&lt;br /&gt;
//Run the code generator and the array is populated with respective computations&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, if a expression that has to be evaluated is ''sqrt'', then a code generator is built for ''sqrt'' under the name ''Macro''. The code generator is run so that it populates all the values in the corresponding ''array_name''. In the program, when the &amp;quot;array_name&amp;quot; is referred to, it returns the value that was calculated and populated by the code generator.&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://brandonbyars.com/blog/articles/2008/03/29/code-generation-and-metaprogramming &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24788</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24788"/>
		<updated>2009-10-09T23:31:14Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating programs is known as Metaprogramming [1].  These programs take in either other programs or themselves as their data and manipulate them or finish the run-time tasks at compile time itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a metaprogramming works – either through the Application Programming Interfaces (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single programming language to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many programming languages require lots of statements to be typed to perform the tasks but metaprogramming eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the metaprograms in other languages. However, the main reason behind using metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of metaprogamming.  One of them is for using the data at run-time through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of logarithmic values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at compile time or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of metaprogramming is to replace boilerplate code. Some of the programs might contain a set of error handlers or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators.&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
Metaprograms provide a set of domain-specific languages which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using macro languages [1]. Metaprogramming involves the usage of the textual macro language that consists of textual macros. Textual macros do not have the knowledge of the programming language but they affect the text of the programming language. The most widely used textual macro systems are C preprocessor and M4 macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
C programming language does not have good code-generation capability hence metaprogramming is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro SUM, which adds a, b and stores the sum in a. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the SUM text in the program with the set of statements defined as the macro directive.  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as polymorphism in object-oriented languages.  In C language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This preprocessor restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
== Code Generators ==&lt;br /&gt;
&lt;br /&gt;
Code generators (like Flex, Bison, Gperf etc.) are the programs that generate programs. Consider the code generator Embedded SQL that easily merges the SQL entities into C and extends the language so that the database access from C is done easily. This code generator produces C programs as output and makes the database access easy and error-free which would be otherwise done through the set of libraries [1]. Code generators generally take either a parse tree or an abstract syntax tree as a input which are converted to instructions while processing [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24772</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24772"/>
		<updated>2009-10-09T23:27:57Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating programs is known as Metaprogramming [1].  These programs take in either other programs or themselves as their data and manipulate them or finish the run-time tasks at compile time itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a metaprogramming works – either through the Application Programming Interfaces (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single programming language to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many programming languages require lots of statements to be typed to perform the tasks but metaprogramming eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the metaprograms in other languages. However, the main reason behind using metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of metaprogamming.  One of them is for using the data at run-time through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of logarithmic values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at compile time or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of metaprogramming is to replace boilerplate code. Some of the programs might contain a set of error handlers or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators.&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
Metaprograms provide a set of domain-specific languages which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using macro languages [1]. Metaprogramming involves the usage of the textual macro language that consists of textual macros. Textual macros do not have the knowledge of the programming language but they affect the text of the programming language. The most widely used textual macro systems are C preprocessor and M4 macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
C programming language does not have good code-generation capability hence metaprogramming is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro SUM, which adds a, b and stores the sum in a. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the SUM text in the program with the set of statements defined as the macro directive.  However, this comes with its own set of disadvantages – &lt;br /&gt;
1. Textual substitution cannot work as polymorphism in object-oriented languages.  In C language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. &amp;lt;br&amp;gt;&lt;br /&gt;
2. This preprocessor restricts the number of arguments that can be passed to the macros. This reduces the flexibility. &amp;lt;br&amp;gt;&lt;br /&gt;
3. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29 &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24769</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24769"/>
		<updated>2009-10-09T23:26:51Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating programs is known as Metaprogramming [1].  These programs take in either other programs or themselves as their data and manipulate them or finish the run-time tasks at compile time itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a metaprogramming works – either through the Application Programming Interfaces (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single programming language to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many programming languages require lots of statements to be typed to perform the tasks but metaprogramming eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the metaprograms in other languages. However, the main reason behind using metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of metaprogamming.  One of them is for using the data at run-time through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of logarithmic values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at compile time or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of metaprogramming is to replace boilerplate code. Some of the programs might contain a set of error handlers or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators.&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
Metaprograms provide a set of domain-specific languages which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using macro languages [1]. Metaprogramming involves the usage of the textual macro language that consists of textual macros. Textual macros do not have the knowledge of the programming language but they affect the text of the programming language. The most widely used textual macro systems are C preprocessor and M4 macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
C programming language does not have good code-generation capability hence metaprogramming is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro SUM, which adds a, b and stores the sum in a. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the SUM text in the program with the set of statements defined as the macro directive.  However, this comes with its own set of disadvantages – Textual substitution cannot work as polymorphism in object-oriented languages.  In C language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. This preprocessor restricts the number of arguments that can be passed to the macros. This reduces the flexibility. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.ibm.com/developerworks/linux/library/l-metaprog1.html&lt;br /&gt;
[2] http://en.wikipedia.org/wiki/Metaprogramming&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Code_generation_%28compiler%29&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24759</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24759"/>
		<updated>2009-10-09T23:25:13Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating programs is known as Metaprogramming [1].  These programs take in either other programs or themselves as their data and manipulate them or finish the run-time tasks at compile time itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a metaprogramming works – either through the Application Programming Interfaces (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single programming language to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many programming languages require lots of statements to be typed to perform the tasks but metaprogramming eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the metaprograms in other languages. However, the main reason behind using metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of metaprogamming.  One of them is for using the data at run-time through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of logarithmic values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at compile time or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of metaprogramming is to replace boilerplate code. Some of the programs might contain a set of error handlers or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators.&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
Metaprograms provide a set of domain-specific languages which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using macro languages [1]. Metaprogramming involves the usage of the textual macro language that consists of textual macros. Textual macros do not have the knowledge of the programming language but they affect the text of the programming language. The most widely used textual macro systems are C preprocessor and M4 macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
C programming language does not have good code-generation capability hence metaprogramming is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro SUM, which adds a, b and stores the sum in a. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the above program is run, it replaces the SUM text in the program with the set of statements defined as the macro directive.  However, this comes with its own set of disadvantages – Textual substitution cannot work as polymorphism in object-oriented languages.  In C language, if different type information has to be passed, then a different macro has to be defined or the type information should be included in the macro definition like shown in the example above. This preprocessor restricts the number of arguments that can be passed to the macros. This reduces the flexibility. The variable declared in the macro should not conflict with the variable passed to the macro. This gets very messy and introduces lots of errors and it is time-consuming to check the declaration of variables every time [1].&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24755</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24755"/>
		<updated>2009-10-09T23:23:44Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* Metaprogramming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating programs is known as Metaprogramming [1].  These programs take in either other programs or themselves as their data and manipulate them or finish the run-time tasks at compile time itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a metaprogramming works – either through the Application Programming Interfaces (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single programming language to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;br /&gt;
&lt;br /&gt;
== Advantages of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Many programming languages require lots of statements to be typed to perform the tasks but metaprogramming eliminates much of the typing to produce the output. This reduces errors in the code that could be caused by mistyping [1]. Few of the features that are available in one language might be available only through the metaprograms in other languages. However, the main reason behind using metaprograms is not the design issue of a programming language but easier maintenance [1]. There are various uses of metaprogamming.  One of them is for using the data at run-time through pre-generated tables. For instance, say for some application a look-up table needs to be created to hold the computation of logarithmic values for the range of numbers. This task can be accomplished either at run-time or write a program to build the table at compile time or by manually calculating it. Though building the table at run-time seems reasonable, it might delay the start up of the program. In such scenarios it is more efficient to write the program to build the static tables [1].  Other most common usage of metaprogramming is to replace boilerplate code. Some of the programs might contain a set of error handlers or a huge list of variable declarations for every instance of the program. In these circumstances it is handy to use the metaprograms such that the code is converted to its respective programming language code before compilation [1]. &lt;br /&gt;
&lt;br /&gt;
Metaprogramming can be done through the macro expansions or code generators.&lt;br /&gt;
&lt;br /&gt;
== Macro Languages ==&lt;br /&gt;
&lt;br /&gt;
Metaprograms provide a set of domain-specific languages which are easier to write and have better maintenance than the target language. These domain-specific languages can be created using macro languages [1]. Metaprogramming involves the usage of the textual macro language that consists of textual macros. Textual macros do not have the knowledge of the programming language but they affect the text of the programming language. The most widely used textual macro systems are C preprocessor and M4 macro processor [1]. &lt;br /&gt;
&lt;br /&gt;
=== C preprocessor ===&lt;br /&gt;
&lt;br /&gt;
C programming language does not have good code-generation capability hence metaprogramming is done through textual macros. These macros are beneficial in many ways as they avoid the overhead involved in function call and the computations can be accomplished without writing the code statements multiple times [1]. Consider a macro SUM, which adds a, b and stores the sum in a. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This macro can be called in the function in the following way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SUM(a, b, type) { type sum; sum = a + b; a = sum; }&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    float a = 10, b = 20;&lt;br /&gt;
    SUM(a, b, float);&lt;br /&gt;
    SUM(a, a, float);&lt;br /&gt;
    printf(&amp;quot;Value of a: %d \n&amp;quot;, a);	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output: &lt;br /&gt;
Value of a: 40&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24729</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 1 MP</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_1_MP&amp;diff=24729"/>
		<updated>2009-10-09T23:16:33Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Metaprogramming =&lt;br /&gt;
&lt;br /&gt;
The process of writing code-generating programs is known as Metaprogramming [1].  These programs take in either other programs or themselves as their data and manipulate them or finish the run-time tasks at compile time itself. This provides flexibility to the developers as the new changes could be reflected without recompilation. The time it takes the programmers to write such programs is the same as it would take them to write all the code manually [2]. There are two ways that a metaprogramming works – either through the Application Programming Interfaces (APIs) where the internal structure of the run-time engine is exposed to the code at the programmer’s level or through dynamic execution of programming commands that are represented as expressions. Though it is possible for a single programming language to incorporate both of these approaches, generally they provide better support for one approach than the other [1].&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22388</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22388"/>
		<updated>2009-09-29T02:34:40Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the [http://en.wikipedia.org/wiki/Compile_time compile time] and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the [http://en.wikipedia.org/wiki/Run-time run-time] checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The [http://en.wikipedia.org/wiki/Run-time run-time] checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the [http://en.wikipedia.org/wiki/Compile_time compile time], the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a = [‘x’, 1, 2]&lt;br /&gt;
b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the [http://en.wikipedia.org/wiki/Algorithm algorithms] hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
One of the key features of the [http://en.wikipedia.org/wiki/Dynamically_typed_language#Dynamic_typing dynamically typed] language that the [http://en.wikipedia.org/wiki/Statically_typed_language#Static_typing statically typed] language lacks is [http://en.wikipedia.org/wiki/Duck_typing duck typing]. In duck typing, when the methods are invoked the aspects of the object invoking that method is important and not the type of the object. In languages that do not allow duck typing, if there are functions ''f1'' and ''f2'' defined in ''Class A'', then the object of type ''Class A'' can invoke the functions ''f1'' and ''f2''. However, in languages that do allow duck-typing, an object of any type (not necessarily of type ''Class A'') can call the functions ''f1'' and ''f2''. Consider the code below of an dynamically typed [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented language], the function ''add'' can be invoked by the objects which do not have any related inheritance (numbers and strings). Thus, duck-typing allows [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] without [http://en.wikipedia.org/wiki/Inheritance_%28computer_science%29 inheritance] [9].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A{&lt;br /&gt;
    int add(x, y){&lt;br /&gt;
       return (x+y); &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
num = add (10, 20);&lt;br /&gt;
str = add('A', 'B');&lt;br /&gt;
&lt;br /&gt;
puts num;&lt;br /&gt;
puts str;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
30&lt;br /&gt;
AB&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Statically typed languages are considered to be [http://en.wikipedia.org/wiki/Strong_typing strongly typed] as it prevents the program from running if it has errors in the code and dynamically typed languages are [http://en.wikipedia.org/wiki/Weakly_typed weakly typed] as programs are allowed to run even if they have errors in them and they are detected during run-time. &lt;br /&gt;
&lt;br /&gt;
Though the static-checking is done for the statically typed languages, many languages postpone the type checks to the [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. For example, if the variable is declared to be of the type ''int'' by the programmer and as per the program logic, if it should be of type ''float'' the type checker will not detect it. In statically typed languages, since the type declaration has to be done explicitly, if the data type is changed for a variable at a single place in the code, then the corresponding changes have to be made everywhere in the code with respect to the logic and usage. Consider the [http://en.wikipedia.org/wiki/Java Java] code below - say a variable ''test'' is declared of type ''String'' and the in-built method of ''String'' class, ''toLowerCase()'' is used to convert ''test'' to lowercase. If ''test'' is changed to type ''int'', the developer has to manually change/delete ''test.toLowercase()'' in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Java code&lt;br /&gt;
String test = &amp;quot;ABC&amp;quot;;&lt;br /&gt;
#code&lt;br /&gt;
test.toLowerCase();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above scenario spans across multiple files, it becomes tedious and makes the code error-prone. Hence static type systems are not flexible and difficult to work with[6]. &lt;br /&gt;
&lt;br /&gt;
Some of the statically typed languages require lot of type declarations and in most cases, more declarations than necessary. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the [http://en.wikipedia.org/wiki/Rapid_application_development rapid application development]. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. Since the variables are not associated with the data type in dynamically typed languages, while reading the code it would be difficult for the developer to know the association between the variables and the data types.  The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion ([http://en.wikipedia.org/wiki/Intellisense intellisense]) and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Though the statically typed languages are much faster than the dynamically typed languages as in the latter type checking is done at run-time, currently the memory and performance are not the major issues for most of the applications (with the exception of [http://en.wikipedia.org/wiki/Embedded_systems embedded systems] on large application servers) and dynamically typed languages cannot have disadvantages due to performance concerns. Instead, dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
With respect to the [http://en.wikipedia.org/wiki/Software_testing testing], static type systems perform better than dynamic type systems. The static systems can many a times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the [http://en.wikipedia.org/wiki/Compiler compiler] can determine the exact types that are used in the code, it can generate the [http://en.wikipedia.org/wiki/Machine_code machine code] with [http://en.wikipedia.org/wiki/Optimization_%28computer_science%29 optimizations]. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until [http://en.wikipedia.org/wiki/Run-time run-time] and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and [http://en.wikipedia.org/wiki/Debugging debugging] the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective [http://en.wikipedia.org/wiki/Code_refactoring re-factoring] of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all of its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run-time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Statically and dynamically typed languages have their own advantages and disadvantages and which one to choose depends on the application one needs to develop and various other factors. [http://www.ferg.org/projects/python_java_side-by-side.html Java vs. Python] comparison gives us the idea of how the above languages differ in terms of type information, verbosity etc. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
[9] http://en.wikipedia.org/wiki/Duck_typing&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22387</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22387"/>
		<updated>2009-09-29T02:34:02Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the [http://en.wikipedia.org/wiki/Compile_time compile time] and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the [http://en.wikipedia.org/wiki/Run-time run-time] checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The [http://en.wikipedia.org/wiki/Run-time run-time] checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the [http://en.wikipedia.org/wiki/Compile_time compile time], the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a = [‘x’, 1, 2]&lt;br /&gt;
b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the [http://en.wikipedia.org/wiki/Algorithm algorithms] hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
One of the key features of the [http://en.wikipedia.org/wiki/Dynamically_typed_language#Dynamic_typing dynamically typed] language that the [http://en.wikipedia.org/wiki/Statically_typed_language#Static_typing statically typed] language lacks is [http://en.wikipedia.org/wiki/Duck_typing duck typing]. In duck typing, when the methods are invoked the aspects of the object invoking that method is important and not the type of the object. In languages that do not allow duck typing, if there are functions ''f1'' and ''f2'' defined in ''Class A'', then the object of type ''Class A'' can invoke the functions ''f1'' and ''f2''. However, in languages that do allow duck-typing, an object of any type (not necessarily of type ''Class A'') can call the functions ''f1'' and ''f2''. Consider the code below of an dynamically typed [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented language], the function ''add'' can be invoked by the objects which do not have any related inheritance (numbers and strings). Thus, duck-typing allows [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] without [http://en.wikipedia.org/wiki/Inheritance_%28computer_science%29 inheritance] [9].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A{&lt;br /&gt;
    int add(x, y){&lt;br /&gt;
       return (x+y); &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
num = add (10, 20);&lt;br /&gt;
str = add('A', 'B');&lt;br /&gt;
&lt;br /&gt;
puts num;&lt;br /&gt;
puts str;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
30&lt;br /&gt;
AB&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Statically typed languages are considered to be [http://en.wikipedia.org/wiki/Strong_typing strongly typed] as it prevents the program from running if it has errors in the code and dynamically typed languages are [http://en.wikipedia.org/wiki/Weakly_typed weakly typed] as programs are allowed to run even if they have errors in them and they are detected during run-time. &lt;br /&gt;
&lt;br /&gt;
Though the static-checking is done for the statically typed languages, many languages postpone the type checks to the [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. For example, if the variable is declared to be of the type ''int'' by the programmer and as per the program logic, if it should be of type ''float'' the type checker will not detect it. In statically typed languages, since the type declaration has to be done explicitly, if the data type is changed for a variable at a single place in the code, then the corresponding changes have to be made everywhere in the code with respect to the logic and usage. Consider the [http://en.wikipedia.org/wiki/Java Java] code below - say a variable ''test'' is declared of type ''String'' and the in-built method of ''String'' class, ''toLowerCase()'' is used to convert ''test'' to lowercase. If ''test'' is changed to type ''int'', the developer has to manually change/delete ''test.toLowercase()'' in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        #Java code&lt;br /&gt;
 	String test = &amp;quot;ABC&amp;quot;;&lt;br /&gt;
	#code&lt;br /&gt;
        test.toLowerCase();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above scenario spans across multiple files, it becomes tedious and makes the code error-prone. Hence static type systems are not flexible and difficult to work with[6]. &lt;br /&gt;
&lt;br /&gt;
Some of the statically typed languages require lot of type declarations and in most cases, more declarations than necessary. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the [http://en.wikipedia.org/wiki/Rapid_application_development rapid application development]. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. Since the variables are not associated with the data type in dynamically typed languages, while reading the code it would be difficult for the developer to know the association between the variables and the data types.  The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion ([http://en.wikipedia.org/wiki/Intellisense intellisense]) and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Though the statically typed languages are much faster than the dynamically typed languages as in the latter type checking is done at run-time, currently the memory and performance are not the major issues for most of the applications (with the exception of [http://en.wikipedia.org/wiki/Embedded_systems embedded systems] on large application servers) and dynamically typed languages cannot have disadvantages due to performance concerns. Instead, dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
With respect to the [http://en.wikipedia.org/wiki/Software_testing testing], static type systems perform better than dynamic type systems. The static systems can many a times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the [http://en.wikipedia.org/wiki/Compiler compiler] can determine the exact types that are used in the code, it can generate the [http://en.wikipedia.org/wiki/Machine_code machine code] with [http://en.wikipedia.org/wiki/Optimization_%28computer_science%29 optimizations]. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until [http://en.wikipedia.org/wiki/Run-time run-time] and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and [http://en.wikipedia.org/wiki/Debugging debugging] the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective [http://en.wikipedia.org/wiki/Code_refactoring re-factoring] of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all of its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run-time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Statically and dynamically typed languages have their own advantages and disadvantages and which one to choose depends on the application one needs to develop and various other factors. [http://www.ferg.org/projects/python_java_side-by-side.html Java vs. Python] comparison gives us the idea of how the above languages differ in terms of type information, verbosity etc. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
[9] http://en.wikipedia.org/wiki/Duck_typing&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22384</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22384"/>
		<updated>2009-09-29T02:32:25Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the [http://en.wikipedia.org/wiki/Compile_time compile time] and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the [http://en.wikipedia.org/wiki/Run-time run-time] checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The [http://en.wikipedia.org/wiki/Run-time run-time] checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the [http://en.wikipedia.org/wiki/Compile_time compile time], the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a = [‘x’, 1, 2]&lt;br /&gt;
b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the [http://en.wikipedia.org/wiki/Algorithm algorithms] hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
One of the key features of the [http://en.wikipedia.org/wiki/Dynamically_typed_language#Dynamic_typing dynamically typed] language that the [http://en.wikipedia.org/wiki/Statically_typed_language#Static_typing statically typed] language lacks is [http://en.wikipedia.org/wiki/Duck_typing duck typing]. In duck typing, when the methods are invoked the aspects of the object invoking that method is important and not the type of the object. In languages that do not allow duck typing, if there are functions ''f1'' and ''f2'' defined in ''Class A'', then the object of type ''Class A'' can invoke the functions ''f1'' and ''f2''. However, in languages that do allow duck-typing, an object of any type (not necessarily of type ''Class A'') can call the functions ''f1'' and ''f2''. Consider the code below of an dynamically typed [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented language], the function ''add'' can be invoked by the objects which do not have any related inheritance (numbers and strings). Thus, duck-typing allows [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] without [http://en.wikipedia.org/wiki/Inheritance_%28computer_science%29 inheritance] [9].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A{&lt;br /&gt;
    int add(x, y){&lt;br /&gt;
       return (x+y); &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
num = add (10, 20);&lt;br /&gt;
str = add('A', 'B');&lt;br /&gt;
&lt;br /&gt;
puts num;&lt;br /&gt;
puts str;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
30&lt;br /&gt;
AB&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Statically typed languages are considered to be [http://en.wikipedia.org/wiki/Strong_typing strongly typed] as it prevents the program from running if it has errors in the code and dynamically typed languages are [http://en.wikipedia.org/wiki/Weakly_typed weakly typed] as programs are allowed to run even if they have errors in them and they are detected during run-time. &lt;br /&gt;
&lt;br /&gt;
Though the static-checking is done for the statically typed languages, many languages postpone the type checks to the [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. For example, if the variable is declared to be of the type ''int'' by the programmer and as per the program logic, if it should be of type ''float'' the type checker will not detect it. In statically typed languages, since the type declaration has to be done explicitly, if the data type is changed for a variable at a single place in the code, then the corresponding changes have to be made everywhere in the code with respect to the logic and usage. Consider the [http://en.wikipedia.org/wiki/Java Java] code below - say a variable ''test'' is declared of type ''String'' and the in-built method of ''String'' class, ''toLowerCase()'' is used to convert ''test'' to lowercase. If ''test'' is changed to type ''int'', the developer has to manually change/delete ''test.toLowercase()'' in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        #Java code&lt;br /&gt;
 	String test = &amp;quot;ABC&amp;quot;;&lt;br /&gt;
	#code&lt;br /&gt;
        test.toLowerCase();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above scenario spans across multiple files, it becomes tedious and makes the code error-prone. Hence static type systems are not flexible and difficult to work with[6]. &lt;br /&gt;
&lt;br /&gt;
Some of the statically typed languages require lot of type declarations and in most cases, more declarations than necessary. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the [http://en.wikipedia.org/wiki/Rapid_application_development rapid application development]. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. Since the variables are not associated with the data type in dynamically typed languages, while reading the code it would be difficult for the developer to know the association between the variables and the data types.  The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion ([http://en.wikipedia.org/wiki/Intellisense intellisense]) and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Though the statically typed languages are much faster than the dynamically typed languages as in the latter type checking is done at run-time, currently the memory and performance are not the major issues for most of the applications (with the exception of [http://en.wikipedia.org/wiki/Embedded_systems embedded systems] on large application servers) and dynamically typed languages cannot have disadvantages due to performance concerns. Instead, dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
With respect to the [http://en.wikipedia.org/wiki/Software_testing testing], static type systems perform better than dynamic type systems. The static systems can many a times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the [http://en.wikipedia.org/wiki/Compiler compiler] can determine the exact types that are used in the code, it can generate the [http://en.wikipedia.org/wiki/Machine_code machine code] with [http://en.wikipedia.org/wiki/Optimization_%28computer_science%29 optimizations]. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until [http://en.wikipedia.org/wiki/Run-time run-time] and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and [http://en.wikipedia.org/wiki/Debugging debugging] the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective [http://en.wikipedia.org/wiki/Code_refactoring re-factoring] of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all of its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run-time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Statically and dynamically typed languages have their own advantages and disadvantages and which one to choose depends on the application one needs to develop and various other factors. [http://www.ferg.org/projects/python_java_side-by-side.html Java vs. Python] comparison gives us the idea of how the above languages differ in terms of type information, verbosity etc. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
[9] http://en.wikipedia.org/wiki/Duck_typing&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22381</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22381"/>
		<updated>2009-09-29T02:28:08Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The run-time checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the compile time, the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a = [‘x’, 1, 2]&lt;br /&gt;
b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the algorithms hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
One of the key features of the [http://en.wikipedia.org/wiki/Dynamically_typed_language#Dynamic_typing dynamically typed] language that the [http://en.wikipedia.org/wiki/Statically_typed_language#Static_typing statically typed] language lacks is [http://en.wikipedia.org/wiki/Duck_typing duck typing]. In duck typing, when the methods are invoked the aspects of the object invoking that method is important and not the type of the object. In languages that do not allow duck typing, if there are functions ''f1'' and ''f2'' defined in ''Class A'', then the object of type ''Class A'' can invoke the functions ''f1'' and ''f2''. However, in languages that do allow duck-typing, an object of any type (not necessarily of type ''Class A'') can call the functions ''f1'' and ''f2''. Consider the code below of an dynamically typed [http://en.wikipedia.org/wiki/Object-oriented_language object-oriented language], the function ''add'' can be invoked by the objects which do not have any related inheritance (numbers and strings). Thus, duck-typing allows [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] without [http://en.wikipedia.org/wiki/Inheritance_%28computer_science%29 inheritance] [9].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A{&lt;br /&gt;
    int add(x, y){&lt;br /&gt;
       return (x+y); &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
num = add (10, 20);&lt;br /&gt;
str = add('A', 'B');&lt;br /&gt;
&lt;br /&gt;
puts num;&lt;br /&gt;
puts str;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
30&lt;br /&gt;
AB&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Statically typed languages are considered to be [http://en.wikipedia.org/wiki/Strong_typing strongly typed] as it prevents the program from running if it has errors in the code and dynamically typed languages are [http://en.wikipedia.org/wiki/Weakly_typed weakly typed] as programs are allowed to run even if they have errors in them and they are detected during run-time. &lt;br /&gt;
&lt;br /&gt;
Though the static-checking is done for the statically typed languages, many languages postpone the type checks to the [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. For example, if the variable is declared to be of the type ''int'' by the programmer and as per the program logic, if it should be of type ''float'' the type checker will not detect it. In statically typed languages, since the type declaration has to be done explicitly, if the data type is changed for a variable at a single place in the code, then the corresponding changes have to be made everywhere in the code with respect to the logic and usage. Consider the [http://en.wikipedia.org/wiki/Java Java] code below - say a variable ''test'' is declared of type ''String'' and the in-built method of ''String'' class, ''toLowerCase()'' is used to convert ''test'' to lowercase. If ''test'' is changed to type ''int'', the developer has to manually change/delete ''test.toLowercase()'' in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        #Java code&lt;br /&gt;
 	String test = &amp;quot;ABC&amp;quot;;&lt;br /&gt;
	#code&lt;br /&gt;
        test.toLowerCase();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above scenario spans across multiple files, it becomes tedious and makes the code error-prone. Hence static type systems are not flexible and difficult to work with[6]. &lt;br /&gt;
&lt;br /&gt;
Some of the statically typed languages require lot of type declarations and in most cases, more declarations than necessary. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the [http://en.wikipedia.org/wiki/Rapid_application_development rapid application development]. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. Since the variables are not associated with the data type in dynamically typed languages, while reading the code it would be difficult for the developer to know the association between the variables and the data types.  The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion ([http://en.wikipedia.org/wiki/Intellisense intellisense]) and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Though the statically typed languages are much faster than the dynamically typed languages as in the latter type checking is done at run-time, currently the memory and performance are not the major issues for most of the applications (with the exception of [http://en.wikipedia.org/wiki/Embedded_systems embedded systems] on large application servers) and dynamically typed languages cannot have disadvantages due to performance concerns. Instead, dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
With respect to the [http://en.wikipedia.org/wiki/Software_testing testing], static type systems perform better than dynamic type systems. The static systems can many a times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the [http://en.wikipedia.org/wiki/Compiler compiler] can determine the exact types that are used in the code, it can generate the [http://en.wikipedia.org/wiki/Machine_code machine code] with [http://en.wikipedia.org/wiki/Optimization_%28computer_science%29 optimizations]. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until [http://en.wikipedia.org/wiki/Run-time run-time] and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and [http://en.wikipedia.org/wiki/Debugging debugging] the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective [http://en.wikipedia.org/wiki/Code_refactoring re-factoring] of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all of its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run-time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Statically and dynamically typed languages have their own advantages and disadvantages and which one to choose depends on the application one needs to develop and various other factors. [http://www.ferg.org/projects/python_java_side-by-side.html Java vs. Python] comparison gives us the idea of how the above languages differ in terms of type information, verbosity etc. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
[9] http://en.wikipedia.org/wiki/Duck_typing&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22380</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22380"/>
		<updated>2009-09-29T02:26:50Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The run-time checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the compile time, the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a = [‘x’, 1, 2]&lt;br /&gt;
b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the algorithms hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
One of the key features of the [http://en.wikipedia.org/wiki/Dynamically_typed_language#Dynamic_typing dynamically typed] language that the [ http://en.wikipedia.org/wiki/Statically_typed_language#Static_typing statically typed] language lacks is [http://en.wikipedia.org/wiki/Duck_typing duck typing]. In duck typing, when the methods are invoked the aspects of the object invoking that method is important and not the type of the object. In languages that do not allow duck typing, if there are functions ''f1'' and ''f2'' defined in ''Class A'', then the object of type ''Class A'' can invoke the functions ''f1'' and ''f2''. However, in languages that do allow duck-typing, an object of any type (not necessarily of type ''Class A'') can call the functions ''f1'' and ''f2''. Consider the code below of an dynamically typed [ http://en.wikipedia.org/wiki/Object-oriented_language object-oriented language], the function ''add'' can be invoked by the objects which do not have any related inheritance (numbers and strings). Thus, duck-typing allows [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism] without [http://en.wikipedia.org/wiki/Inheritance_%28computer_science%29 inheritance] [9].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A{&lt;br /&gt;
    int add(x, y){&lt;br /&gt;
       return (x+y); &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
num = add (10, 20);&lt;br /&gt;
str = add('A', 'B');&lt;br /&gt;
&lt;br /&gt;
puts num;&lt;br /&gt;
puts str;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
30&lt;br /&gt;
AB&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Statically typed languages are considered to be [http://en.wikipedia.org/wiki/Strong_typing strongly typed] as it prevents the program from running if it has errors in the code and dynamically typed languages are [http://en.wikipedia.org/wiki/Weakly_typed weakly typed] as programs are allowed to run even if they have errors in them and they are detected during run-time. &lt;br /&gt;
&lt;br /&gt;
Though the static-checking is done for the statically typed languages, many languages postpone the type checks to the [ http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. For example, if the variable is declared to be of the type ''int'' by the programmer and as per the program logic, if it should be of type ''float'' the type checker will not detect it. In statically typed languages, since the type declaration has to be done explicitly, if the data type is changed for a variable at a single place in the code, then the corresponding changes have to be made everywhere in the code with respect to the logic and usage. Consider the [http://en.wikipedia.org/wiki/Java Java] code below - say a variable ''test'' is declared of type ''String'' and the in-built method of ''String'' class, ''toLowerCase()'' is used to convert ''test'' to lowercase. If ''test'' is changed to type ''int'', the developer has to manually change/delete ''test.toLowercase()'' in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        #Java code&lt;br /&gt;
 	String test = &amp;quot;ABC&amp;quot;;&lt;br /&gt;
	#code&lt;br /&gt;
        test.toLowerCase();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above scenario spans across multiple files, it becomes tedious and makes the code error-prone. Hence static type systems are not flexible and difficult to work with[6]. &lt;br /&gt;
&lt;br /&gt;
Some of the statically typed languages require lot of type declarations and in most cases, more declarations than necessary. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the [http://en.wikipedia.org/wiki/Rapid_application_development rapid application development]. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. Since the variables are not associated with the data type in dynamically typed languages, while reading the code it would be difficult for the developer to know the association between the variables and the data types.  The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion ([http://en.wikipedia.org/wiki/Intellisense intellisense]) and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Though the statically typed languages are much faster than the dynamically typed languages as in the latter type checking is done at run-time, currently the memory and performance are not the major issues for most of the applications (with the exception of [http://en.wikipedia.org/wiki/Embedded_systems embedded systems] on large application servers) and dynamically typed languages cannot have disadvantages due to performance concerns. Instead, dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
With respect to the [http://en.wikipedia.org/wiki/Software_testing testing], static type systems perform better than dynamic type systems. The static systems can many a times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the [http://en.wikipedia.org/wiki/Compiler compiler] can determine the exact types that are used in the code, it can generate the [http://en.wikipedia.org/wiki/Machine_code machine code] with [http://en.wikipedia.org/wiki/Optimization_%28computer_science%29 optimizations]. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until [http://en.wikipedia.org/wiki/Run-time run-time] and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and [http://en.wikipedia.org/wiki/Debugging debugging] the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective [http://en.wikipedia.org/wiki/Code_refactoring re-factoring] of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all of its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run-time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Statically and dynamically typed languages have their own advantages and disadvantages and which one to choose depends on the application one needs to develop and various other factors. [http://www.ferg.org/projects/python_java_side-by-side.html Java vs. Python] comparison gives us the idea of how the above languages differ in terms of type information, verbosity etc. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
[9] http://en.wikipedia.org/wiki/Duck_typing&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22368</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22368"/>
		<updated>2009-09-29T02:05:10Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The run-time checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the compile time, the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a = [‘x’, 1, 2]&lt;br /&gt;
b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the algorithms hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
One of the key feature of the dynamically typed language that the statically typed language lacks is [http://en.wikipedia.org/wiki/Duck_typing duck typing]. In duck typing, when the methods are invoked the aspects of the object invoking that method is important and not the type of the object. In languages that do not allow duck typing, if there are functions ''f1'' and ''f2'' defined in ''Class A'', then the object of type ''Class A'' can invoke the functions ''f1'' and ''f2''. However, in languages that do allow duck-typing, an object of any type (not necessarily of type ''Class A'') can call the functions ''f1'' and ''f2''. Consider the code below of an dynamically typed object-oriented language, the function ''add'' can be invoked by the objects which do not have any related inheritance (numbers and strings). Thus, duck-typing allows polymorphism without inheritance [9].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A{&lt;br /&gt;
    int add(x, y){&lt;br /&gt;
       return (x+y); &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
num = add (10, 20);&lt;br /&gt;
str = add('A', 'B');&lt;br /&gt;
&lt;br /&gt;
puts num;&lt;br /&gt;
puts str;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
30&lt;br /&gt;
AB&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Though the static-checking is done for the statically typed languages, many languages postpone the type checks to the run-time. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. For example, if the variable is declared to be of the type ''int'' by the programmer and as per the program logic, if it should be of type ''float'' the type checker will not detect it. In statically typed languages, since the type declaration has to be done explicitly, if the data type is changed for a variable at a single place in the code, then the corresponding changes have to be made everywhere in the code with respect to the logic and usage. Consider the [http://en.wikipedia.org/wiki/Java Java] code below - say a variable ''test'' is declared of type ''String'' and the in-built method of ''String'' class, ''toLowerCase()'' is used to convert ''test'' to lowercase. If ''test'' is changed to type ''int'', the developer has to manually change/delete ''test.toLowercase()'' in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        #Java code&lt;br /&gt;
 	String test = &amp;quot;ABC&amp;quot;;&lt;br /&gt;
	#code&lt;br /&gt;
        test.toLowerCase();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above scenario spans across multiple files, it becomes tedious and makes the code error-prone. Hence static type systems are not flexible and difficult to work with[6]. &lt;br /&gt;
Some of the statically typed languages require lot of type declarations and in most cases, more declarations than necessary. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the [http://en.wikipedia.org/wiki/Rapid_application_development rapid application development]. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. Since the variables are not associated with the data type in dynamically typed languages, while reading the code it would be difficult for the developer to know the association between the variables and the data types.  The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion ([http://en.wikipedia.org/wiki/Intellisense intellisense]) and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Though the statically typed languages are much faster than the dynamically typed languages as in the latter type checking is done at run-time, currently the memory and performance are not the major issues for most of the applications (with the exception of embedded systems on large application servers) and dynamically typed languages cannot have disadvantages due to performance concerns. Instead, dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
With respect to the testing, static type systems perform better than dynamic type systems. The static systems can many a times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the compiler can determine the exact types that are used in the code, it can generate the machine code with optimizations. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until run-time and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and debugging the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective re-factoring of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all of its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run-time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
[9] http://en.wikipedia.org/wiki/Duck_typing&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22366</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22366"/>
		<updated>2009-09-29T02:03:37Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The run-time checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the compile time, the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 	a = [‘x’, 1, 2]&lt;br /&gt;
	b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the algorithms hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
One of the key feature of the dynamically typed language that the statically typed language lacks is [http://en.wikipedia.org/wiki/Duck_typing duck typing]. In duck typing, when the methods are invoked the aspects of the object invoking that method is important and not the type of the object. In languages that do not allow duck typing, if there are functions ''f1'' and ''f2'' defined in ''Class A'', then the object of type ''Class A'' can invoke the functions ''f1'' and ''f2''. However, in languages that do allow duck-typing, an object of any type (not necessarily of type ''Class A'') can call the functions ''f1'' and ''f2''. Consider the code below of an dynamically typed object-oriented language, the function ''add'' can be invoked by the objects which do not have any related inheritance (numbers and strings). Thus, duck-typing allows polymorphism without inheritance [9].&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  class A{&lt;br /&gt;
    int add(x, y){&lt;br /&gt;
       return (x+y)&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  num = add (10, 20);&lt;br /&gt;
  str = add('A', 'B');&lt;br /&gt;
&lt;br /&gt;
  puts num;&lt;br /&gt;
  puts str;&lt;br /&gt;
&lt;br /&gt;
  Output:&lt;br /&gt;
  30&lt;br /&gt;
  AB&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Though the static-checking is done for the statically typed languages, many languages postpone the type checks to the run-time. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. For example, if the variable is declared to be of the type ''int'' by the programmer and as per the program logic, if it should be of type ''float'' the type checker will not detect it. In statically typed languages, since the type declaration has to be done explicitly, if the data type is changed for a variable at a single place in the code, then the corresponding changes have to be made everywhere in the code with respect to the logic and usage. Consider the [http://en.wikipedia.org/wiki/Java Java] code below - say a variable ''test'' is declared of type ''String'' and the in-built method of ''String'' class, ''toLowerCase()'' is used to convert ''test'' to lowercase. If ''test'' is changed to type ''int'', the developer has to manually change/delete ''test.toLowercase()'' in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        #Java code&lt;br /&gt;
 	String test = &amp;quot;ABC&amp;quot;;&lt;br /&gt;
	#code&lt;br /&gt;
        test.toLowerCase();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above scenario spans across multiple files, it becomes tedious and makes the code error-prone. Hence static type systems are not flexible and difficult to work with[6]. &lt;br /&gt;
Some of the statically typed languages require lot of type declarations and in most cases, more declarations than necessary. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the [http://en.wikipedia.org/wiki/Rapid_application_development rapid application development]. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. Since the variables are not associated with the data type in dynamically typed languages, while reading the code it would be difficult for the developer to know the association between the variables and the data types.  The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion ([http://en.wikipedia.org/wiki/Intellisense intellisense]) and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Though the statically typed languages are much faster than the dynamically typed languages as in the latter type checking is done at run-time, currently the memory and performance are not the major issues for most of the applications (with the exception of embedded systems on large application servers) and dynamically typed languages cannot have disadvantages due to performance concerns. Instead, dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
With respect to the testing, static type systems perform better than dynamic type systems. The static systems can many a times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the compiler can determine the exact types that are used in the code, it can generate the machine code with optimizations. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until run-time and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and debugging the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective re-factoring of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all of its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run-time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
[9] http://en.wikipedia.org/wiki/Duck_typing&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22340</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22340"/>
		<updated>2009-09-29T01:36:44Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The run-time checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the compile time, the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 	a = [‘x’, 1, 2]&lt;br /&gt;
	b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the algorithms hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Though the static-checking is done for the statically typed languages, many languages postpone the type checks to the run-time. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. For example, if the variable is declared to be of the type ''int'' by the programmer and as per the program logic, if it should be of type ''float'' the type checker will not detect it. In statically typed languages, since the type declaration has to be done explicitly, if the data type is changed for a variable at a single place in the code, then the corresponding changes have to be made everywhere in the code with respect to the logic and usage. Consider the [http://en.wikipedia.org/wiki/Java Java] code below - say a variable ''test'' is declared of type ''String'' and the in-built method of ''String'' class, ''toLowerCase()'' is used to convert ''test'' to lowercase. If ''test'' is changed to type ''int'', the developer has to manually change/delete ''test.toLowercase()'' in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        #Java code&lt;br /&gt;
 	String test = &amp;quot;ABC&amp;quot;;&lt;br /&gt;
	#code&lt;br /&gt;
        test.toLowerCase();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above scenario spans across multiple files, it becomes tedious and makes the code error-prone. Hence static type systems are not flexible and difficult to work with[6]. &lt;br /&gt;
Some of the statically typed languages require lot of type declarations and in most cases, more declarations than necessary. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the [http://en.wikipedia.org/wiki/Rapid_application_development rapid application development]. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. Since the variables are not associated with the data type in dynamically typed languages, while reading the code it would be difficult for the developer to know the association between the variables and the data types.  The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion ([http://en.wikipedia.org/wiki/Intellisense intellisense]) and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Though the statically typed languages are much faster than the dynamically typed languages as in the latter type checking is done at run-time, currently the memory and performance are not the major issues for most of the applications (with the exception of embedded systems on large application servers) and dynamically typed languages cannot have disadvantages due to performance concerns. Instead, dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
With respect to the testing, static type systems perform better than dynamic type systems. The static systems can many a times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the compiler can determine the exact types that are used in the code, it can generate the machine code with optimizations. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until run-time and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and debugging the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective re-factoring of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all of its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run-time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22316</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22316"/>
		<updated>2009-09-29T00:57:32Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The run-time checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the compile time, the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 	a = [‘x’, 1, 2]&lt;br /&gt;
	b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the algorithms hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Though the static-checking is done for the statically typed languages, many languages postpone the type checks to the run-time. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. For example, if the variable is declared to be of the type ''int'' by the programmer and as per the program logic, if it should be of type ''float'' the type checker will not detect it. In statically typed languages, since the type declaration has to be done explicitly, if the data type is changed for a variable at a single place in the code, then the corresponding changes have to be made everywhere in the code with respect to the logic and usage. Consider the Java code below - say a variable ''test'' is declared of type ''String'' and the in-built method of ''String'' class, ''toLowerCase()'' is used to convert ''test'' to lowercase. If ''test'' is changed to type ''int'', the developer has to manually change/delete ''test.toLowercase()'' in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        #Java code&lt;br /&gt;
 	String test = &amp;quot;ABC&amp;quot;;&lt;br /&gt;
	#code&lt;br /&gt;
        test.toLowerCase();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above scenario spans across multiple files, it becomes tedious and makes the code error-prone. Hence static type systems are not flexible and difficult to work with[6]. Some of the statically typed languages require lot type declarations and in most cases, more declarations than the necessity. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the rapid application development. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Currently, the memory and performance are not the major issues for most of the applications (with the exception of embedded systems on large application servers) and dynamically typed languages cannot be disadvantageous due to performance concerns. Dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
In comparison to testing, static type systems performs better than dynamic type systems. There are two approaches that help us to check the [http://en.wikipedia.org/wiki/Correctness correctness] of a program – Testing and Proof. Testing specifies the upper bounds on correctness while proof specifies the lower bounds. If the proofs of correctness follow a proper structural induction through the syntax of the code, the static systems can many times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the compiler can determine the exact types that are used in the code, it can generate the machine code with optimizations. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until runtime and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and debugging the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective refactoring of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22300</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22300"/>
		<updated>2009-09-29T00:18:09Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The run-time checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the compile time, the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 	a = [‘x’, 1, 2]&lt;br /&gt;
	b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the algorithms hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Though the static-checking is done for the statically typed languages, many languages postpone the type checks to the run-time. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. For example, if the variable is declared to be of the type ''float'' and if the developer has declared it as type ''int'', the type checker will not detect this error at all in some of the languages and will conveniently round of the value to ''int''. In statically typed languages if the type information has to be changed for one variable, then the corresponding changes have to be made everywhere in the code and hence static type systems are not flexible and difficult to work with[6]. Some of the statically typed languages require lot type declarations and in most cases, more declarations than the necessity. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the rapid application development. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Currently, the memory and performance are not the major issues for most of the applications (with the exception of embedded systems on large application servers) and dynamically typed languages cannot be disadvantageous due to performance concerns. Dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
In comparison to testing, static type systems performs better than dynamic type systems. There are two approaches that help us to check the [http://en.wikipedia.org/wiki/Correctness correctness] of a program – Testing and Proof. Testing specifies the upper bounds on correctness while proof specifies the lower bounds. If the proofs of correctness follow a proper structural induction through the syntax of the code, the static systems can many times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the compiler can determine the exact types that are used in the code, it can generate the machine code with optimizations. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until runtime and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and debugging the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective refactoring of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22288</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22288"/>
		<updated>2009-09-29T00:07:43Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4]. Depending on when ([http://en.wikipedia.org/wiki/Compile_time compile time] or [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time]) the the “type” of the variable is checked, the typed languages can be classified as statically typed or dynamically typed.&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the [http://en.wikipedia.org/wiki/Data_types data type]. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the [http://en.wikipedia.org/wiki/Programming_languages programming languages] have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The run-time checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the compile time, the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 	a = [‘x’, 1, 2]&lt;br /&gt;
	b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the algorithms hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Though static-checking is done for the statically typed languages, many of them postpone the type checks to the run-time. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. In statically typed languages if the type information has to be changed for one variable, then the corresponding changes have to be made everywhere in the code and hence static type systems are not flexible and difficult to work with[6]. Some of the statically typed languages require lot type declarations and in most cases, more declarations than the necessity. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the rapid application development. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Currently, the memory and performance are not the major issues for most of the applications (with the exception of embedded systems on large application servers) and dynamically typed languages cannot be disadvantageous due to performance concerns. Dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
In comparison to testing, static type systems performs better than dynamic type systems. There are two approaches that help us to check the [http://en.wikipedia.org/wiki/Correctness correctness] of a program – Testing and Proof. Testing specifies the upper bounds on correctness while proof specifies the lower bounds. If the proofs of correctness follow a proper structural induction through the syntax of the code, the static systems can many times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the compiler can determine the exact types that are used in the code, it can generate the machine code with optimizations. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until runtime and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and debugging the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective refactoring of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22277</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22277"/>
		<updated>2009-09-29T00:00:43Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Type_checking#Type_checking Type checking] can be performed in [http://en.wikipedia.org/wiki/Programming_languages programming languages] either during [http://en.wikipedia.org/wiki/Run_time_%28computing%29 run-time] or at [http://en.wikipedia.org/wiki/Compile_time compile time][1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the [http://en.wikipedia.org/wiki/Data_types data types] are associated with the variables in the [http://en.wikipedia.org/wiki/Computer_program programs]. Based on this, the [http://en.wikipedia.org/wiki/Programming_languages programming languages] are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4].&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the data type. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the programming languages have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The run-time checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the compile time, the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 	a = [‘x’, 1, 2]&lt;br /&gt;
	b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the algorithms hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Though static-checking is done for the statically typed languages, many of them postpone the type checks to the run-time. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. In statically typed languages if the type information has to be changed for one variable, then the corresponding changes have to be made everywhere in the code and hence static type systems are not flexible and difficult to work with[6]. Some of the statically typed languages require lot type declarations and in most cases, more declarations than the necessity. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the rapid application development. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Currently, the memory and performance are not the major issues for most of the applications (with the exception of embedded systems on large application servers) and dynamically typed languages cannot be disadvantageous due to performance concerns. Dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
In comparison to testing, static type systems performs better than dynamic type systems. There are two approaches that help us to check the [http://en.wikipedia.org/wiki/Correctness correctness] of a program – Testing and Proof. Testing specifies the upper bounds on correctness while proof specifies the lower bounds. If the proofs of correctness follow a proper structural induction through the syntax of the code, the static systems can many times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the compiler can determine the exact types that are used in the code, it can generate the machine code with optimizations. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until runtime and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and debugging the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective refactoring of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22267</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=22267"/>
		<updated>2009-09-28T23:53:15Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Advantages of statically typed vs. dynamically typed languages=&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
&lt;br /&gt;
The languages can defined based on how the variable is stored in the memory. Based on this, the programming languages are categorized into [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed] and [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages]. The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages] ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4].&lt;br /&gt;
&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the data type. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the programming languages have the [http://en.wikipedia.org/wiki/Type_system type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Though the expression might always return true at run-time, the type error will be thrown by the static type checker as expression will not be evaluated at the compile time and there is no way for the type checker  to know that the execution will not perform the else part of the code. However, if the expression randomly evaluates to false, the static type checking could be of great advantage [1].&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
In dynamically typed languages, the types are associated with the values. The run-time checker identifies the type errors at the run time [1]. Consider the code of the program below, since the type information is not known at the compile time, the addition of the character and an integer will result in run-time error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 	a = [‘x’, 1, 2]&lt;br /&gt;
	b = a[0] + a[1] #Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
&lt;br /&gt;
The dynamic type-checker offers more flexibility to the programming language as types and functionality can be generated on the data obtained during run-time [1]. Also it accepts the code often invalidated by the static-type checker and executes it. Though the checker checks for the syntactic correctness of the code, it might not perform all the checks that are performed by the static-type checker. Nevertheless, it incorporates both the static-checking and dynamic-checking functionality. The checks are exclusively for the conditions which are part of the execution of the program and it holds good for all the executions of the same program [1]. The dynamic type-checking might be slower as more emphasis is on the optimization of the libraries and improvisations of the algorithms hence the efficient coding tricks might not be completely taken care of [5]. While evaluating an expression, sometimes the value might have been passed to the wrong type and computation might produce erroneous results. If this error occurs long after the mistake was made in the code, bug location might be difficult [1].&lt;br /&gt;
&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
&lt;br /&gt;
Though static-checking is done for the statically typed languages, many of them postpone the type checks to the run-time. The static checker mainly builds on the correctness of the code that the developer writes. If the type information is not provided by the developer to the type system, the static checker cannot detect some of the common errors in the code. In statically typed languages if the type information has to be changed for one variable, then the corresponding changes have to be made everywhere in the code and hence static type systems are not flexible and difficult to work with[6]. Some of the statically typed languages require lot type declarations and in most cases, more declarations than the necessity. This makes coding more time-consuming and also very difficult to make changes[7]. This could pose a problem while writing reusable software and also reduces the agility of the programming language. Thus, dynamically typed languages are best suited for the rapid application development. However, static-checking makes the software more reliable as they find errors at compile time[6].&lt;br /&gt;
&lt;br /&gt;
Static type systems help in producing readable software and this corresponds to the self-documentation of the source code. Since the type information is present in the code, it is easier for the developer to walk through the code when compared to the dynamically typed languages where the code might get confusing [7]. The static type system helps in providing the developers with intelligent development tools that have various features like auto-completion and other analysis tools that makes programming easier [8]. &lt;br /&gt;
&lt;br /&gt;
Currently, the memory and performance are not the major issues for most of the applications (with the exception of embedded systems on large application servers) and dynamically typed languages cannot be disadvantageous due to performance concerns. Dynamic type systems give the developers the boost with the reduced development time [6].&lt;br /&gt;
&lt;br /&gt;
In comparison to testing, static type systems performs better than dynamic type systems. There are two approaches that help us to check the [http://en.wikipedia.org/wiki/Correctness correctness] of a program – Testing and Proof. Testing specifies the upper bounds on correctness while proof specifies the lower bounds. If the proofs of correctness follow a proper structural induction through the syntax of the code, the static systems can many times tell if the changes to the code has broken any other piece of code. Thus in certain cases testing might not even be required [7]. It is fairly effective to find type errors in code through static type checking than the [http://en.wikipedia.org/wiki/Code_coverage code coverage] tests with 100% code coverage [1].&lt;br /&gt;
&lt;br /&gt;
If the compiler can determine the exact types that are used in the code, it can generate the machine code with optimizations. Hence the compiled code of the statically typed languages executes more quickly. For this reason, certain dynamically typed languages like [http://en.wikipedia.org/wiki/Common_Lisp Common Lisp] provide the optional type declarations facility for the [http://en.wikipedia.org/wiki/Optimization_(computer_science) optimizations] [1]. In dynamically typed languages the type checking is not performed until runtime and hence it has very less code to visit and this reduces the time and effort involved in editing, compiling, testing and debugging the code [1].&lt;br /&gt;
&lt;br /&gt;
Static typing provides effective refactoring of the code. For instance, the programming environment of the statically typed languages can analyze the source code and all the callers of a particular method. Using the tool, the method could be renamed throughout the source code at all its occurrences. This is difficult to accomplish in the dynamically typed languages as the reference of name is determined only during run time [1].&lt;br /&gt;
&lt;br /&gt;
Based on the above discussions, features of [http://en.wikipedia.org/wiki/Type_system type systems] can be categorized as follows [1]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt; Features &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Statically typed language &amp;lt;/th&amp;gt; &amp;lt;th&amp;gt; Dynamically typed languages &amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Safety &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at compile time thus more reliable. &amp;lt;/td&amp;gt; &amp;lt;td&amp;gt; Type errors are found at run time, less reliable. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization &amp;lt;/td&amp;gt;&lt;br /&gt;
 &amp;lt;td&amp;gt; Provides compile code.Execution is faster as complied machine code is readily available. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Optimization is option in some languages but its done at run time. Its faster.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Documentation &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; More expressive, easy to understand for the developers. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Not structured, confuses the developer. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Performance &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Time consuming and less flexibility.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt; Reduced development time.Suitable for rapid application development. &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[5] http://tratt.net/laurie/research/publications/papers/tratt__dynamically_typed_languages.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
[6] Laurence Tratt, Roel Wuyts, &amp;quot;Guest Editors' Introduction: Dynamically Typed Languages&amp;quot;, IEEE Software, vol. 24, no. 5, pp. 28-30, Sep./Oct. 2007 &amp;lt;br&amp;gt;&lt;br /&gt;
[7] http://www.pphsg.org/cdsmith/types.html &amp;lt;br&amp;gt;&lt;br /&gt;
[8] http://www.martinfowler.com/bliki/DynamicTyping.html&lt;br /&gt;
==External Links==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Ruby_(programming_language)&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://lambda-the-ultimate.org/node/100 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_09.html&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20930</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20930"/>
		<updated>2009-09-21T05:47:56Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* Advantages and Disadvantages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages of statically typed vs. dynamically typed languages'''&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system#Type_checking type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages] ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the data type. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the programming languages have the [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int x;&lt;br /&gt;
if (expression is true)&lt;br /&gt;
then &amp;lt;perform computation&amp;gt;&lt;br /&gt;
else x = “Error” // int cannot take the string “Error” – type error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20929</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20929"/>
		<updated>2009-09-21T05:46:42Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* Statically typed languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages of statically typed vs. dynamically typed languages'''&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system#Type_checking type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages] ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the data type. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the programming languages have the [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20928</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20928"/>
		<updated>2009-09-21T05:45:14Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* Statically typed languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages of statically typed vs. dynamically typed languages'''&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system#Type_checking type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages] ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the data type. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the programming languages have the [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int num;&lt;br /&gt;
num = “Assign a string”; //Type error&lt;br /&gt;
ArrayList aList = new ArrayList(); //Collection from Java&lt;br /&gt;
int array[] = aList; //Type Error&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20924</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20924"/>
		<updated>2009-09-21T05:40:09Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* Statically typed languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages of statically typed vs. dynamically typed languages'''&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system#Type_checking type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages] ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the data type. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the programming languages have the [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
&lt;br /&gt;
 puts &amp;quot;What is your name?&amp;quot;&lt;br /&gt;
 $name = STDIN.gets&lt;br /&gt;
 puts &amp;quot;Hi &amp;quot; + $name&lt;br /&gt;
&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20921</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20921"/>
		<updated>2009-09-21T05:33:57Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* Statically typed languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages of statically typed vs. dynamically typed languages'''&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system#Type_checking type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages] ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the data type. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the programming languages have the [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
In statically typed languages, types are associated with the variables or the expressions and not the values. The type checking is performed at the compile time and thus many types of errors can be identified in the early phases of the development cycle [1]. Consider the code of the program below. It shows the illegal statements in the code the static-type checker will identify.&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
If the static type checks are performed once for a program, there is no necessity to perform the check at every execution of the program. Thus the execution can be efficient by eliminating the run-time checks. Certain programs may exhibit a desired behavior at run-time but since the static type checkers do not have the type information that might be available only during run-time, they might consider identify errors is such programs even though they might be resolved at run-time[1]. For example, consider the code in a program –&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20920</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20920"/>
		<updated>2009-09-21T05:33:07Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* Type Checking */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages of statically typed vs. dynamically typed languages'''&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system#Type_checking type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages] ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
Type checking is done only for the [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. All the variables and expressions in the program are associated with the data type. Errors might occur due the explicit or implicit mismatch of the type information. Type checking identifies the errors that may or may not produce wrong computations in the program [3]. In order to eliminate these errors the programming languages have the [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing type systems]. Type system is programming language specific and defines the rules of how the typed programs should behave. The programs which do not follow these rules produce error [1]. The type system performs the static check on the statically typed languages and dynamic check on the dynamically typed languages.&lt;br /&gt;
&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20914</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20914"/>
		<updated>2009-09-21T05:26:47Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages of statically typed vs. dynamically typed languages'''&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system#Type_checking type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming], the types include [http://en.wikipedia.org/wiki/Class_(computer_science) classes] (user-defined), strings and integers ([http://en.wikipedia.org/wiki/Primitive_types primitive types]), lists/arrays/vectors/hash ([http://en.wikipedia.org/wiki/Container_(data_structure) containers]) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable ''num'' of type ''int'' in the program then ''num'' can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages typed languages]. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called [http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages untyped languages] ([http://en.wikipedia.org/wiki/Assembly_language assembly languages]) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20906</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20906"/>
		<updated>2009-09-21T05:21:03Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages of statically typed vs. dynamically typed languages'''&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the [http://en.wikipedia.org/wiki/Type_system#Type_checking type system], the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In object-oriented programming, the types include classes (user-defined), strings and integers (primitive types), lists/arrays/vectors/hash (containers) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable num of type int in the program then num can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages (assembly languages) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20901</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20901"/>
		<updated>2009-09-21T05:18:25Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages of statically typed vs. dynamically typed languages'''&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the type system, the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In object-oriented programming, the types include classes (user-defined), strings and integers (primitive types), lists/arrays/vectors/hash (containers) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable num of type int in the program then num can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages (assembly languages) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20899</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20899"/>
		<updated>2009-09-21T05:17:53Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Advantages of statically typed vs. dynamically typed languages&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the type system, the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like [http://en.wikipedia.org/wiki/PHP PHP], [http://en.wikipedia.org/wiki/Prolog_%28programming_language%29 Prolog], [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python], [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby], [http://en.wikipedia.org/wiki/Smalltalk Smalltalk] etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In object-oriented programming, the types include classes (user-defined), strings and integers (primitive types), lists/arrays/vectors/hash (containers) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable num of type int in the program then num can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages (assembly languages) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20896</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20896"/>
		<updated>2009-09-21T05:14:01Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Advantages of statically typed vs. dynamically typed languages&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the type system, the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language) Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like PHP, Prolog, Python, Ruby, Smalltalk etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In object-oriented programming, the types include classes (user-defined), strings and integers (primitive types), lists/arrays/vectors/hash (containers) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable num of type int in the program then num can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages (assembly languages) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20895</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20895"/>
		<updated>2009-09-21T05:13:33Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Advantages of statically typed vs. dynamically typed languages&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the type system, the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], [http://en.wikipedia.org/wiki/C%2B%2B C++], [http://en.wikipedia.org/wiki/C_Sharp_(programming_language) C#], [http://en.wikipedia.org/wiki/Java_(programming_language)Java], [http://en.wikipedia.org/wiki/Fortran FORTRAN] etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like PHP, Prolog, Python, Ruby, Smalltalk etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In object-oriented programming, the types include classes (user-defined), strings and integers (primitive types), lists/arrays/vectors/hash (containers) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable num of type int in the program then num can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages (assembly languages) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20890</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20890"/>
		<updated>2009-09-21T05:10:16Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Advantages of statically typed vs. dynamically typed languages&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the type system, the programming languages are classified as statically typed or dynamically typed. The statically typed languages like [http://en.wikipedia.org/wiki/C_(programming_language) C], C++, C#, Java, FORTRAN etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like PHP, Prolog, Python, Ruby, Smalltalk etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In object-oriented programming, the types include classes (user-defined), strings and integers (primitive types), lists/arrays/vectors/hash (containers) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable num of type int in the program then num can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages (assembly languages) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20882</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20882"/>
		<updated>2009-09-21T04:50:13Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Advantages of statically typed vs. dynamically typed languages&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the type system, the programming languages are classified as statically typed or dynamically typed. The statically typed languages like C, C++, C#, Java, FORTRAN etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like PHP, Prolog, Python, Ruby, Smalltalk etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In object-oriented programming, the types include classes (user-defined), strings and integers (primitive types), lists/arrays/vectors/hash (containers) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable num of type int in the program then num can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages (assembly languages) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
[1] http://en.wikipedia.org/wiki/Type_system#Type_checking &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.artima.com/weblogs/viewpost.jsp?thread=7590 &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20881</id>
		<title>CSC/ECE 517 Fall 2009/wiki1b 2 ps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1b_2_ps&amp;diff=20881"/>
		<updated>2009-09-21T04:48:37Z</updated>

		<summary type="html">&lt;p&gt;Phoenix: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Advantages of statically typed vs. dynamically typed languages&lt;br /&gt;
&lt;br /&gt;
Type checking can be performed in programming languages either during run-time or at compile time[1]. Based on such a behavior of the type system, the programming languages are classified as statically typed or dynamically typed. The statically typed languages like C, C++, C#, Java, FORTRAN etc., eliminate the type checks to be performed every time the program is executed [1]. The condition checked once will hold good for all the future executions of the program as well. The dynamically typed languages like PHP, Prolog, Python, Ruby, Smalltalk etc., perform the run-time checks uses the information from the compile time as well and hence could be more comprehensive[1].&lt;br /&gt;
&lt;br /&gt;
== Typed and Untyped languages ==&lt;br /&gt;
The “type” provides the information about the chunk of memory which holds the data and thus categorizes it such that the valid operations that can be performed on that data are defined. In object-oriented programming, the types include classes (user-defined), strings and integers (primitive types), lists/arrays/vectors/hash (containers) [2]. A variable in a program can accept a certain range of values during its execution. The upper bound value for that range marks the type for that particular variable. For example, if there is a variable num of type int in the program then num can accept only integer values during every execution of the program. Such languages where all the variables are associated with the data type are called typed languages. Certain languages do not specify separate data types for each of the variables but contains a single universal type that holds all the values. They do not define the range for the variables and are called untyped languages (assembly languages) [4].&lt;br /&gt;
== Type Checking ==&lt;br /&gt;
== Statically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages ===&lt;br /&gt;
&lt;br /&gt;
== Dynamically typed languages ==&lt;br /&gt;
=== Advantages and Disadvantages===&lt;br /&gt;
== Comparison of statically typed and dynamically typed languages ==&lt;br /&gt;
== References ==&lt;br /&gt;
1. http://en.wikipedia.org/wiki/Type_system#Type_checking&lt;br /&gt;
2 http://www.artima.com/weblogs/viewpost.jsp?thread=7590&lt;br /&gt;
3 http://www.cs.aau.dk/~normark/prog3-03/html/notes/fu-intr-1-show-types-and-check-1.html&lt;br /&gt;
4 http://www.eecs.umich.edu/~bchandra/courses/papers/Cardelli_Types.pdf&lt;/div&gt;</summary>
		<author><name>Phoenix</name></author>
	</entry>
</feed>