<?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=Drhowar5</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=Drhowar5"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Drhowar5"/>
	<updated>2026-08-10T17:09:45Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_E605A&amp;diff=74125</id>
		<title>CSC/ECE 517 Spring 2013/OSS E605A</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_E605A&amp;diff=74125"/>
		<updated>2013-03-21T00:31:48Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: added information about changes made to the copy method&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza Questionnaire Refactoring=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
This project involved refactoring the questionnaire portion of Expertiza. This part of the Expertiza project deals with the creation and management of questionnaires that are used during project review and feedback. It also allows for the creation of advice on what each score in a question should represent (a 5 being excellent, 3 being average, etc.). The majority of the refactoring took place in the file questionnaire_controller.rb, as it contains the CRUD functionality for questionnaires. Some refactoring also took place on the questionnaire.rb model, along with various different kinds of questionnaires that were represented as subclasses of questionnaire.rb.&lt;br /&gt;
&lt;br /&gt;
=List of Changes=&lt;br /&gt;
&lt;br /&gt;
Following is a list of the changes made during refactoring, along with the design principles and patterns that were upheld by making these changes.&lt;br /&gt;
&lt;br /&gt;
==Pulled up get_weighted_score==&lt;br /&gt;
&lt;br /&gt;
Each of the questionnaire subclasses had a get_weighted_score method that tallied up the points for a completed questionnaire. These methods were all identical, so we pulled the method up to the questionnaire superclass (questionnaire.rb). The following subclasses had the method and were refactored accordingly:&lt;br /&gt;
&lt;br /&gt;
* author_feedback_questionnaire.rb&lt;br /&gt;
* metareview_questionnaire.rb&lt;br /&gt;
* review_questionnaire.rb&lt;br /&gt;
* teammate_review_questionnaire.rb&lt;br /&gt;
* questionnaire.rb (superclass that the method was moved to)&lt;br /&gt;
&lt;br /&gt;
The main design principle that influenced this refactor was DRY. As the same functionality was used in multiple places, moving it to the superclass made the code easier to understand by showing that all of the subclasses were able to use the function in the same way.&lt;br /&gt;
&lt;br /&gt;
==Renamed create_questionnaire and save_questionnaire==&lt;br /&gt;
&lt;br /&gt;
The questionnaire_controller (questionnaire_controller.rb) contained CRUD functionality for several types of objects. Naturally, one of these objects was a questionnaire. For clarity, its methods had been named create_questionnaire and save_questionnaire. However, proper Ruby design emphasizes convention over configuration. Since the methods were in the questionnaire controller, the convention is to name them create and save, as the fact that they affect a questionnaire is implied. Therefore create_questionnaire (on line 156) was changed to create and save_questionnaire (on line 214) was changed to save.&lt;br /&gt;
&lt;br /&gt;
==Pulled methods from edit==&lt;br /&gt;
&lt;br /&gt;
The edit method in questionnaire_controller.rb did not need to be renamed, but it had another problem; the method was too long. Keeping methods short (around 25 lines or less) is another design principle that increases the readability of code. Therefore, we looked for chunks of the method that would make sense if pulled out as a separate method. Part of the edit method involved exporting and importing questionnaires. These chunks of code were well contained, with clear start and stop points, so we pulled them into separate methods. This resulted in creating an export method from lines 102-108 of the old edit method, and an import method from lines 110-125 of the old method. By doing this, the edit method was shortened to an acceptable length.&lt;br /&gt;
&lt;br /&gt;
==Created advice_controller==&lt;br /&gt;
&lt;br /&gt;
As mentioned above, the questionnaire controller contained some CRUD methods that dealt with another type of object besides questionnaires. This was the advice object, which is used to type notes regarding what score should be given on a question. Again, this violated the Ruby principle of convention over configuration, since these advice methods were in the questionnaire controller. Therefore, a new advice controller (advice_controller.rb) was created, and the edit_advice and save_advice methods were moved from the questionnaire controller to it.&lt;br /&gt;
&lt;br /&gt;
==Removed delete_question_type==&lt;br /&gt;
&lt;br /&gt;
The questionnaire_controller had a delete_question_type method that was only used when destroying the questions of a questionnaire. As it only consisted of two lines, and was only used in one place, we felt that having it in a separate method caused a minor, but unnecessary, case of the Ping-Pong effect. Since the code of the method was rather self-explanatory (simply finding the question type of the question to be deleted and destroying it), moving the functionality back into the delete_questions method and removing the delete_question_type method reduced the complexity of the code without affecting its readability or DRYness.&lt;br /&gt;
&lt;br /&gt;
==Changes to the Copy Method==&lt;br /&gt;
&lt;br /&gt;
The copy method was initially 78 lines long.  After refactoring, the copy method is only 9 lines.  We extracted 2 methods: getInstructorId, and cloneQuestionnaireDetails.  &lt;br /&gt;
&lt;br /&gt;
The getInstructorId method determines whether the person calling the copy method is a TA or an instructor.  Then it returns the relevant instructor ID.  This code was formerly implemented as a conditional statement within the copy method.  Now it is one line of code that uses the ternary operator.  The code is now easier to read, and easier to follow.&lt;br /&gt;
&lt;br /&gt;
The cloneQuestionnaireDetails method loops through the questions and advice of the questionnaire that is being copied.  Each question and its advice are copied over into the newly created questionnaire.  This method is still a little long, but it was hard to break it down any smaller, without removing functionality that is essential to the method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
* [https://www.youtube.com/watch?v=XZzKb_PM07A Project Screencast]&lt;br /&gt;
* [https://github.com/expertiza/expertiza Main Expertiza Repository]&lt;br /&gt;
* [https://github.com/mlhall3/expertiza Refactored Expertiza Fork]&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73760</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73760"/>
		<updated>2013-02-26T04:22:06Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
*The main purpose of this wiki entry is to provide insight into Dr. Gehringer's lecture on Metaprogramming in Ruby found at this [http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html link]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref name=&amp;quot;Video Lecture on Metaprogramming by Dr. Gehringer&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
Whenever a call to an undefined method is made on an object, Ruby provides an option to intercept the call. This is done by implementing the method method_missing within the class definition.  Ruby passes, as parameters, the name of the method called and the arguments passed to it.  &lt;br /&gt;
&lt;br /&gt;
Define a module (or class) Roman.  This class contains a method_missing method that intercepts calls to “class methods” that are undefined.  It then tries to interpret the method name as a Roman numeral.&lt;br /&gt;
For example, &lt;br /&gt;
*evaluating Roman.xix calls the xix,method of module Roman.  &lt;br /&gt;
*Roman has no xix method, so method_missing is invoked with xix as the argument.  &lt;br /&gt;
*The id2name method of class Symbol is invoked on :xix, returning &amp;quot;xix&amp;quot;. &lt;br /&gt;
*The &amp;quot;xix&amp;quot; is then parsed according to the rules for evaluating Roman numerals, and evaluates to 19.&lt;br /&gt;
&lt;br /&gt;
  class Roman &lt;br /&gt;
  DIGITS = {&lt;br /&gt;
    'I' =&amp;gt; 1,&lt;br /&gt;
    'V' =&amp;gt; 5,&lt;br /&gt;
    'X' =&amp;gt; 10,&lt;br /&gt;
    'L' =&amp;gt; 50,&lt;br /&gt;
    'C' =&amp;gt; 100,&lt;br /&gt;
    'D' =&amp;gt; 500,&lt;br /&gt;
    'M' =&amp;gt; 1000,&lt;br /&gt;
  }&lt;br /&gt;
  def roman_to_integer(roman_string)&lt;br /&gt;
    last = nil&lt;br /&gt;
    &lt;br /&gt;
  roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
  |memo, digit|&lt;br /&gt;
      if digit_value = DIGITS[digit]&lt;br /&gt;
        if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
          memo -= digit_value&lt;br /&gt;
        else&lt;br /&gt;
          memo += digit_value&lt;br /&gt;
        end&lt;br /&gt;
  last = digit_value&lt;br /&gt;
      end&lt;br /&gt;
  memo&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(method)        &lt;br /&gt;
    str = method.id2name &lt;br /&gt;
    roman_to_integer(str)      &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Meta Programming in Java&amp;lt;ref&amp;gt;[http://www.cs.tut.fi/~kk/webstuff/MetaProgrammingJavaKalvot.pdf Metaprogramming in Java]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
The generics can be used in classes, interfaces, methods and constructors.&lt;br /&gt;
Two new types:&lt;br /&gt;
*Parametrized types&lt;br /&gt;
*Type variables&lt;br /&gt;
A type variable is an unqualified identifier.&lt;br /&gt;
Class and interface declarations can have type arguments (type variables)&lt;br /&gt;
*Metalevel: Class implements GenericsDeclaration&lt;br /&gt;
Method and constructors definitions can have type arguments (type variables)&lt;br /&gt;
*Metalevel: Method, Constructor implements GenericsDeclaration&lt;br /&gt;
&lt;br /&gt;
  public interface List&amp;lt;E&amp;gt; { &lt;br /&gt;
    void add(E x);&lt;br /&gt;
    Iterator&amp;lt;E&amp;gt; iterator();&lt;br /&gt;
  }&lt;br /&gt;
  public interface Iterator&amp;lt;E&amp;gt; { &lt;br /&gt;
    E next();&lt;br /&gt;
    boolean hasNext();&lt;br /&gt;
  }&lt;br /&gt;
  List&amp;lt;String&amp;gt; anExample;&lt;br /&gt;
  anExample.add(”sdfdfss”);&lt;br /&gt;
  anExample.add(new Object()); // compile time error&lt;br /&gt;
  String aTest = anExample.iterator().next();&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73753</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73753"/>
		<updated>2013-02-26T04:11:10Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: removed abrupt content change&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
Whenever a call to an undefined method is made on an object, Ruby provides an option to intercept the call. This is done by implementing the method method_missing within the class definition.  Ruby passes, as parameters, the name of the method called and the arguments passed to it.  &lt;br /&gt;
&lt;br /&gt;
Define a module (or class) Roman.  This class contains a method_missing method that intercepts calls to “class methods” that are undefined.  It then tries to interpret the method name as a Roman numeral.&lt;br /&gt;
For example, &lt;br /&gt;
*evaluating Roman.xix calls the xix,method of module Roman.  &lt;br /&gt;
*Roman has no xix method, so method_missing is invoked with xix as the argument.  &lt;br /&gt;
*The id2name method of class Symbol is invoked on :xix, returning &amp;quot;xix&amp;quot;. &lt;br /&gt;
*The &amp;quot;xix&amp;quot; is then parsed according to the rules for evaluating Roman numerals, and evaluates to 19.&lt;br /&gt;
&lt;br /&gt;
  class Roman &lt;br /&gt;
  DIGITS = {&lt;br /&gt;
    'I' =&amp;gt; 1,&lt;br /&gt;
    'V' =&amp;gt; 5,&lt;br /&gt;
    'X' =&amp;gt; 10,&lt;br /&gt;
    'L' =&amp;gt; 50,&lt;br /&gt;
    'C' =&amp;gt; 100,&lt;br /&gt;
    'D' =&amp;gt; 500,&lt;br /&gt;
    'M' =&amp;gt; 1000,&lt;br /&gt;
  }&lt;br /&gt;
  def roman_to_integer(roman_string)&lt;br /&gt;
    last = nil&lt;br /&gt;
    &lt;br /&gt;
  roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
  |memo, digit|&lt;br /&gt;
      if digit_value = DIGITS[digit]&lt;br /&gt;
        if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
          memo -= digit_value&lt;br /&gt;
        else&lt;br /&gt;
          memo += digit_value&lt;br /&gt;
        end&lt;br /&gt;
  last = digit_value&lt;br /&gt;
      end&lt;br /&gt;
  memo&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(method)        &lt;br /&gt;
    str = method.id2name &lt;br /&gt;
    roman_to_integer(str)      &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
===Meta Programming in Java&amp;lt;ref&amp;gt;[http://www.cs.tut.fi/~kk/webstuff/MetaProgrammingJavaKalvot.pdf Metaprogramming in Java]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
The generics can be used in classes, interfaces, methods and constructors.&lt;br /&gt;
Two new types:&lt;br /&gt;
*Parametrized types&lt;br /&gt;
*Type variables&lt;br /&gt;
A type variable is an unqualified identifier.&lt;br /&gt;
Class and interface declarations can have type arguments (type variables)&lt;br /&gt;
*Metalevel: Class implements GenericsDeclaration&lt;br /&gt;
Method and constructors definitions can have type arguments (type variables)&lt;br /&gt;
*Metalevel: Method, Constructor implements GenericsDeclaration&lt;br /&gt;
&lt;br /&gt;
  public interface List&amp;lt;E&amp;gt; { &lt;br /&gt;
    void add(E x);&lt;br /&gt;
    Iterator&amp;lt;E&amp;gt; iterator();&lt;br /&gt;
  }&lt;br /&gt;
  public interface Iterator&amp;lt;E&amp;gt; { &lt;br /&gt;
    E next();&lt;br /&gt;
    boolean hasNext();&lt;br /&gt;
  }&lt;br /&gt;
  List&amp;lt;String&amp;gt; anExample;&lt;br /&gt;
  anExample.add(”sdfdfss”);&lt;br /&gt;
  anExample.add(new Object()); // compile time error&lt;br /&gt;
  String aTest = anExample.iterator().next();&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73559</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73559"/>
		<updated>2013-02-21T04:20:29Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Metaprogramming in Other Languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
Whenever a call to an undefined method is made on an object, Ruby provides an option to intercept the call. This is done by implementing the method method_missing within the class definition.  Ruby passes as parameters the name of the method called and the arguments passed to it. Another interesting use of method_missing can be found on the Web by looking for “Roman method_missing”. Define a module (or class) Roman.  This class contains a method_missing method that intercepts calls to “class methods” that are undefined.  It then tries to interpret the method name as a Roman numeral.&lt;br /&gt;
For example, &lt;br /&gt;
*evaluating Roman.xix calls the xix,method of module Roman.  &lt;br /&gt;
*Roman has no xix method, so method_missing is invoked with xix as the argument.  &lt;br /&gt;
*The id2name method of class Symbol is invoked on :xix, returning &amp;quot;xix&amp;quot;. &lt;br /&gt;
*The &amp;quot;xix&amp;quot; is then parsed according to the rules for evaluating Roman numerals, and evaluates to 19.&lt;br /&gt;
&lt;br /&gt;
  class Roman &lt;br /&gt;
  DIGITS = {&lt;br /&gt;
    'I' =&amp;gt; 1,&lt;br /&gt;
    'V' =&amp;gt; 5,&lt;br /&gt;
    'X' =&amp;gt; 10,&lt;br /&gt;
    'L' =&amp;gt; 50,&lt;br /&gt;
    'C' =&amp;gt; 100,&lt;br /&gt;
    'D' =&amp;gt; 500,&lt;br /&gt;
    'M' =&amp;gt; 1000,&lt;br /&gt;
  }&lt;br /&gt;
  def roman_to_integer(roman_string)&lt;br /&gt;
    last = nil&lt;br /&gt;
    &lt;br /&gt;
  roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
  |memo, digit|&lt;br /&gt;
      if digit_value = DIGITS[digit]&lt;br /&gt;
        if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
          memo -= digit_value&lt;br /&gt;
        else&lt;br /&gt;
          memo += digit_value&lt;br /&gt;
        end&lt;br /&gt;
  last = digit_value&lt;br /&gt;
      end&lt;br /&gt;
  memo&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(method)        &lt;br /&gt;
    str = method.id2name &lt;br /&gt;
    roman_to_integer(str)      &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Additional Examples of Ruby Metaprogramming ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Meta Programming in Java&amp;lt;ref&amp;gt;[http://www.cs.tut.fi/~kk/webstuff/MetaProgrammingJavaKalvot.pdf Metaprogramming in Java]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
The generics can be used in classes, interfaces, methods and constructors.&lt;br /&gt;
Two new types:&lt;br /&gt;
*Parametrized types&lt;br /&gt;
*Type variables&lt;br /&gt;
A type variable is an unqualified identifier.&lt;br /&gt;
Class and interface declarations can have type arguments (type variables)&lt;br /&gt;
*Metalevel: Class implements GenericsDeclaration&lt;br /&gt;
Method and constructors definitions can have type arguments (type variables)&lt;br /&gt;
*Metalevel: Method, Constructor implements GenericsDeclaration&lt;br /&gt;
&lt;br /&gt;
  public interface List&amp;lt;E&amp;gt; { &lt;br /&gt;
    void add(E x);&lt;br /&gt;
    Iterator&amp;lt;E&amp;gt; iterator();&lt;br /&gt;
  }&lt;br /&gt;
  public interface Iterator&amp;lt;E&amp;gt; { &lt;br /&gt;
    E next();&lt;br /&gt;
    boolean hasNext();&lt;br /&gt;
  }&lt;br /&gt;
  List&amp;lt;String&amp;gt; anExample;&lt;br /&gt;
  anExample.add(”sdfdfss”);&lt;br /&gt;
  anExample.add(new Object()); // compile time error&lt;br /&gt;
  String aTest = anExample.iterator().next();&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73558</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73558"/>
		<updated>2013-02-21T04:20:01Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Responding to a Non-Existent Method Call */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
Whenever a call to an undefined method is made on an object, Ruby provides an option to intercept the call. This is done by implementing the method method_missing within the class definition.  Ruby passes as parameters the name of the method called and the arguments passed to it. Another interesting use of method_missing can be found on the Web by looking for “Roman method_missing”. Define a module (or class) Roman.  This class contains a method_missing method that intercepts calls to “class methods” that are undefined.  It then tries to interpret the method name as a Roman numeral.&lt;br /&gt;
For example, &lt;br /&gt;
*evaluating Roman.xix calls the xix,method of module Roman.  &lt;br /&gt;
*Roman has no xix method, so method_missing is invoked with xix as the argument.  &lt;br /&gt;
*The id2name method of class Symbol is invoked on :xix, returning &amp;quot;xix&amp;quot;. &lt;br /&gt;
*The &amp;quot;xix&amp;quot; is then parsed according to the rules for evaluating Roman numerals, and evaluates to 19.&lt;br /&gt;
&lt;br /&gt;
  class Roman &lt;br /&gt;
  DIGITS = {&lt;br /&gt;
    'I' =&amp;gt; 1,&lt;br /&gt;
    'V' =&amp;gt; 5,&lt;br /&gt;
    'X' =&amp;gt; 10,&lt;br /&gt;
    'L' =&amp;gt; 50,&lt;br /&gt;
    'C' =&amp;gt; 100,&lt;br /&gt;
    'D' =&amp;gt; 500,&lt;br /&gt;
    'M' =&amp;gt; 1000,&lt;br /&gt;
  }&lt;br /&gt;
  def roman_to_integer(roman_string)&lt;br /&gt;
    last = nil&lt;br /&gt;
    &lt;br /&gt;
  roman_string.to_s.upcase.split(//).reverse.inject(0) do&lt;br /&gt;
  |memo, digit|&lt;br /&gt;
      if digit_value = DIGITS[digit]&lt;br /&gt;
        if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
          memo -= digit_value&lt;br /&gt;
        else&lt;br /&gt;
          memo += digit_value&lt;br /&gt;
        end&lt;br /&gt;
  last = digit_value&lt;br /&gt;
      end&lt;br /&gt;
  memo&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  def method_missing(method)        &lt;br /&gt;
    str = method.id2name &lt;br /&gt;
    roman_to_integer(str)      &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Additional Examples of Ruby Metaprogramming ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Meta Programming in Java&amp;lt;ref&amp;gt;[http://www.cs.tut.fi/~kk/webstuff/MetaProgrammingJavaKalvot.pdf Metaprogramming in Java]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
The generics can be used in classes, interfaces, methods and constructors.&lt;br /&gt;
Two new types:&lt;br /&gt;
*Parametrized types&lt;br /&gt;
*Type variables&lt;br /&gt;
A type variable is an unqualified identifier.&lt;br /&gt;
Class and interface declarations can have type arguments (type variables)&lt;br /&gt;
*Metalevel: Class implements GenericsDeclaration&lt;br /&gt;
Method and constructors definitions can have type arguments (type variables)&lt;br /&gt;
*Metalevel: Method, Constructor implements GenericsDeclaration&lt;br /&gt;
&lt;br /&gt;
  public interface List&amp;lt;E&amp;gt; { &lt;br /&gt;
    void add(E x);&lt;br /&gt;
    Iterator&amp;lt;E&amp;gt; iterator();&lt;br /&gt;
  }&lt;br /&gt;
  public interface Iterator&amp;lt;E&amp;gt; { &lt;br /&gt;
    E next();&lt;br /&gt;
    boolean hasNext();&lt;br /&gt;
  }&lt;br /&gt;
  List&amp;lt;String&amp;gt; anExample;&lt;br /&gt;
  anExample.add(”sdfdfss”);&lt;br /&gt;
  anExample.add(new Object()); // compile time error&lt;br /&gt;
  String aTest = anExample.iterator().next();&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73543</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73543"/>
		<updated>2013-02-21T03:38:59Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Responding to a Non-Existent Method Call */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73542</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73542"/>
		<updated>2013-02-21T03:38:44Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Modifying a Method at Runtime */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73541</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73541"/>
		<updated>2013-02-21T03:38:26Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Creating a Method at Runtime */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73540</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73540"/>
		<updated>2013-02-21T03:38:11Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Creating a Method at Runtime */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73539</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73539"/>
		<updated>2013-02-21T03:37:56Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Modifying a Class at Runtime */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73538</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73538"/>
		<updated>2013-02-21T03:37:42Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Examples of Metaprogramming in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73537</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73537"/>
		<updated>2013-02-21T03:37:31Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Features in Ruby that Enable Metaprogramming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73536</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73536"/>
		<updated>2013-02-21T03:37:19Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Creating a Method at Runtime */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73503</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73503"/>
		<updated>2013-02-21T02:17:12Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&amp;lt;ref name=&amp;quot;DrGCodeNotes&amp;quot;&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf Dr. Gehrenger's notes on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73502</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73502"/>
		<updated>2013-02-21T02:12:40Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Modifying a Method at Runtime */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
== Examples of Metaprogramming in Ruby &amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf]Dr. Gehrenger's notes on Metaprogramming&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Responding to a Non-Existent Method Call ===&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73501</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73501"/>
		<updated>2013-02-21T02:11:14Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Modifying a Class at Runtime */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
== Examples of Metaprogramming in Ruby &amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf]Dr. Gehrenger's notes on Metaprogramming&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
=== Creating a Method at Runtime ===&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73499</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73499"/>
		<updated>2013-02-21T02:09:32Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Examples of Metaprogramming in Ruby [http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf]Dr. Gehrenger's notes on Metaprogramming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
== Examples of Metaprogramming in Ruby &amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf]Dr. Gehrenger's notes on Metaprogramming&amp;lt;/ref&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
=== Creating a New Class at Runtime ===&lt;br /&gt;
Below is an example of creating a new class at runtime:&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         puts &amp;quot;MyClass defined&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In example shown above, the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method is invoked on the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; object.  Inside of the &amp;lt;tt&amp;gt;times&amp;lt;/tt&amp;gt; method call, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is defined.  &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is actually defined three times, once for each of the three iterations.  Even though the class is defined three times, it has the same effect as only defining it once.  The important thing to note here, is that a new class is defined at runtime, inside of a method call.&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Class at Runtime ===&lt;br /&gt;
Below is an example of modifying a class, and and example of creating a new method at runtime:&lt;br /&gt;
   &amp;lt;code&amp;gt;3.times do&lt;br /&gt;
      class MyClass&lt;br /&gt;
         def one&lt;br /&gt;
            puts &amp;quot;one&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class &amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is modified again to include a new method.  This method, the &amp;lt;tt&amp;gt;one&amp;lt;/tt&amp;gt; method is defined three times, just like the class is defined three times.  Even though it has been defined three times, it has the same effect as only defining it once.  The important thing to note here is that a new method is defined at runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a class at runtime:&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the class&amp;lt;tt&amp;gt;MyClass&amp;lt;/tt&amp;gt; is reopened and the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is added to it.&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the code written above is executed:&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Modifying a Method at Runtime ===&lt;br /&gt;
&lt;br /&gt;
Below is an additional example of modifying a method at runtime:&lt;br /&gt;
    &amp;lt;code&amp;gt;class MyClass&lt;br /&gt;
      def two&lt;br /&gt;
         puts &amp;quot;one two&amp;quot;&lt;br /&gt;
   end&amp;lt;/code&amp;gt;&lt;br /&gt;
In the example shown above, the &amp;lt;tt&amp;gt;two&amp;lt;/tt&amp;gt; method is reopened and modified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Below is an example of what happens when the modified code written above is executed:&lt;br /&gt;
   &amp;lt;code&amp;gt;&lt;br /&gt;
   mc = MyClass.new&lt;br /&gt;
   mc.one&lt;br /&gt;
   mc.two&lt;br /&gt;
   &amp;lt;/code&amp;gt;&lt;br /&gt;
The output of the code will be:&lt;br /&gt;
   &amp;lt;code&amp;gt;one&lt;br /&gt;
   one two&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73469</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73469"/>
		<updated>2013-02-21T01:37:35Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Uses of Metaprogramming */ modified list of uses so that it will match up with later examples&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Create a new class at runtime&lt;br /&gt;
::*Create new methods at runtime&lt;br /&gt;
::*Modify existing classes and/or methods at runtime&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
== Examples of Metaprogramming in Ruby &amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/lectures/notes/ol5.pdf]Dr. Gehrenger's notes on Metaprogramming&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Ruby has several metaprogramming facilities.  One can create new class and add methods to it using &amp;quot;define_method&amp;quot;&lt;br /&gt;
  c = Class.new&lt;br /&gt;
  c.class_eval do&lt;br /&gt;
    define_method :hi do&lt;br /&gt;
    puts &amp;quot;Hey&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
  c.new.hi&lt;br /&gt;
  &amp;gt;&amp;gt;Hey&lt;br /&gt;
&lt;br /&gt;
This technique allows you to add any type of new code and modify behavior of a program at run time.&lt;br /&gt;
Another example, adding attr_accessor to all classes:&lt;br /&gt;
  Object.class_eval do&lt;br /&gt;
    class &amp;lt;&amp;lt; self&lt;br /&gt;
      def attribute_accessor( *instance_variables )  &lt;br /&gt;
        instance_variables.each do |instance_variable| &lt;br /&gt;
          class_eval %Q?&lt;br /&gt;
            def #{instance_variable}&lt;br /&gt;
                @#{instance_variable}&lt;br /&gt;
            end&lt;br /&gt;
            def #{instance_variable}=( new_value )&lt;br /&gt;
                @#{instance_variable} = new_value&lt;br /&gt;
            end&lt;br /&gt;
          ?&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end &lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)&amp;lt;ref&amp;gt;[http://www.ibm.com/developerworks/library/l-metaprog1/index.html The Art of Metaprogramming]&amp;lt;/ref&amp;gt;===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73306</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73306"/>
		<updated>2013-02-20T15:55:16Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Features in Ruby that Enable Metaprogramming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Add methods to objects at runtime&lt;br /&gt;
::*Determine if an oject responds to a message or contains a property&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
::*Respond to queries made on non-existent properties &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73305</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73305"/>
		<updated>2013-02-20T15:50:44Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Features in Ruby that Enable Metaprogramming */ added content to about the three features of Ruby that enable metaprogramming&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Add methods to objects at runtime&lt;br /&gt;
::*Determine if an oject responds to a message or contains a property&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
::*Respond to queries made on non-existent properties &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Ruby is a [http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing dynamically typed language]&lt;br /&gt;
*Ruby is an [http://en.wikipedia.org/wiki/Interpreted_language interpreted language]&lt;br /&gt;
*Ruby classes are [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open]&lt;br /&gt;
&lt;br /&gt;
::In dynamically typed languages, the majority of its type checking is performed at run-time, as opposed to compile time.&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing Wikipedia Article on the Type System]&amp;lt;/ref&amp;gt;  Because variables are not type-checked until they are used in program execution, it is possible to use types that are created during program execution.&lt;br /&gt;
&lt;br /&gt;
::Interpreted languages avoid explicit compilation&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Interpreted_language Wikipeida Article on Interpreted Language]&amp;lt;/ref&amp;gt;.  Because Ruby is being interpreted as it is being executed, it is possible to create new classes and methods during program execution.&lt;br /&gt;
&lt;br /&gt;
::Most object-oriented programming languages adhere to the [http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle open/closed principle]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Open/closed_principle#Meyer.27s_Open.2FClosed_Principle Wikipedia Article on the Open/Closed Principle]&amp;lt;/ref&amp;gt;.  This means that the core components that are part of the language cannot be modified.  In Ruby, the classes are open, meaning that all of the classes and methods be changed.&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73300</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73300"/>
		<updated>2013-02-20T04:29:03Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Features in Ruby that Enable Metaprogramming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Add methods to objects at runtime&lt;br /&gt;
::*Determine if an oject responds to a message or contains a property&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
::*Respond to queries made on non-existent properties &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
*Dynamic?&lt;br /&gt;
*Interpreted&lt;br /&gt;
*Open&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
===The C preprocessor (CPP)===&lt;br /&gt;
First let's look at metaprogramming that involves textual macro languages. Textual macros are macros that directly affect the text of the programming language without knowing about or dealing with the meaning of the language.&lt;br /&gt;
=====The SWAP macro: =====&lt;br /&gt;
   #define SWAP(a, b, type) { &lt;br /&gt;
       type __tmp_c; c = b; b = a; a = c; &lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
This macro allows you to swap the two values of the given type. A macro is effective in this situation because:&lt;br /&gt;
*A function call would take too much overhead for a simple operation&lt;br /&gt;
*The functions would require variables' addresses to be passed which is messier and prevents the compiler from keeping the values in registers. &lt;br /&gt;
*A different function would need to be coded for each type of item you wanted to swap.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #define SWAP(a, b, type) { type __tmp_c; c = b; b = a; a = c; }&lt;br /&gt;
  int main()&lt;br /&gt;
  {&lt;br /&gt;
      int a = 3;&lt;br /&gt;
      int b = 5;&lt;br /&gt;
      printf(&amp;quot;a is %d and b is %d\n&amp;quot;, a, b);&lt;br /&gt;
      SWAP(a, b, int);&lt;br /&gt;
      printf(&amp;quot;a is now %d and b is now %d\n&amp;quot;, a, b);&lt;br /&gt;
      return 0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=====The MIN macro: =====&lt;br /&gt;
  #define MIN(x, y) ((x) &amp;gt; (y) ? (y) : (x))&lt;br /&gt;
&lt;br /&gt;
This macro returns the the minimum of two values.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73202</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73202"/>
		<updated>2013-02-19T16:25:30Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: finished basic outlining of article,&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change a program during runtime.  In languages such as Ruby and [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Add methods to objects at runtime&lt;br /&gt;
::*Determine if an oject responds to a message or contains a property&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
::*Respond to queries made on non-existent properties &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features in Ruby that Enable Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
== Examples of Metaprogramming in Ruby ==&lt;br /&gt;
&lt;br /&gt;
== Metaprogramming in Other Languages ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73201</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73201"/>
		<updated>2013-02-19T15:48:02Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]&amp;lt;ref&amp;gt;[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]&amp;lt;/ref&amp;gt;.  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
:Metaprogramming is also used for building frameworks such as [http://rubyonrails.org/ Ruby on Rails].  In this case, the use of [http://en.wikipedia.org/wiki/Convention_over_configuration convention over configuration] allows developers to write more concise and consistent code.  Following specific conventions, developers write a relatively small amount of code.  The Ruby on Rails [http://en.wikipedia.org/wiki/Scaffold_(programming) scaffold] uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized. &lt;br /&gt;
&lt;br /&gt;
:One of the most powerful uses for metaprogramming, is the ability to change the program itself during runtime.  In languages such as [http://groovy.codehaus.org/ Groovy], programmers can&amp;lt;ref&amp;gt;[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::*Add methods to objects at runtime&lt;br /&gt;
::*Determine if an oject responds to a message or contains a property&lt;br /&gt;
::*Respond to calls made on non-existent methods&lt;br /&gt;
::*Respond to queries made on non-existent properties &lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73187</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73187"/>
		<updated>2013-02-19T01:29:56Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: /* Uses of Metaprogramming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler].  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can modify the behavior of a program at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime].  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some languages, such as [http://www.ruby-lang.org/en/ Ruby] are [http://en.wikipedia.org/wiki/Interpreted_language| interpreted languages].&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73186</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73186"/>
		<updated>2013-02-19T01:29:02Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: rearranged existing content&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
This can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler].  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can modify the behavior of a program at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime].  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some languages, such as [http://www.ruby-lang.org/en/ Ruby] are [http://en.wikipedia.org/wiki/Interpreted_language| interpreted languages].  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73185</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73185"/>
		<updated>2013-02-19T01:26:48Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: expanding uses of meta programming&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is: ''writing code that writes or manipulates code.''&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can modify the behavior of a program at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime].  &lt;br /&gt;
&lt;br /&gt;
This can allow programmers to write code that is more&lt;br /&gt;
concise and more flexible.  It can be more concise because a program that can write code is able to generate more code than it is initially given.  It can be more flexible, because it can allow the program to change the way it behaves without having to recompile.&lt;br /&gt;
&lt;br /&gt;
One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler].  A compiler uses code written in one language in order to generate code that can be executed by a computer.&lt;br /&gt;
&lt;br /&gt;
Some languages, such as [http://www.ruby-lang.org/en/ Ruby] are [http://en.wikipedia.org/wiki/Interpreted_language| interpreted languages].  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73184</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73184"/>
		<updated>2013-02-18T22:26:07Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is writing code that writes or manipulates code.&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can modify the behavior of a program at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime].  &lt;br /&gt;
&lt;br /&gt;
This can allow programmers to write code that is more&lt;br /&gt;
concise, reducing the total number of lines of code required.  It can also introduce greater flexibility for compiled languages, without requiring a program to be recompiled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73183</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73183"/>
		<updated>2013-02-18T22:25:37Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: first pass at rewriting some of the introductory material&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
*Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A Basic Definition of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
The most basic definition of metaprogramming is writing code that writes or manipulates code.&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://courses.ncsu.edu/csc517/common/media/08/Metaprogramming/Metaprogramming.html Video Lecture on Metaprogramming by Dr. Gehringer]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A metaprogram can either manipulate itself, or it can manipulate some other program.&lt;br /&gt;
&lt;br /&gt;
:Below are three ''important terms'' associated with a metaprogramming&amp;lt;ref name=&amp;quot;wiki metaprogramming&amp;quot;&amp;gt;[http://en.wikipedia.org/wiki/Metaprogramming Wikipedia Article on Metaprogramming]&amp;lt;/ref&amp;gt;:&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Metalanguage metalanguage] - the language in which a metaprogram is written&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Object_language object language] - the language of the program that is being manipulated by a metaprogram&lt;br /&gt;
::* [http://en.wikipedia.org/wiki/Reflection_(computer_science) reflection] - the ability of a programming language to be its own metalanguage (also known as ''reflexivity'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Uses of Metaprogramming ==&lt;br /&gt;
&lt;br /&gt;
Metaprogramming can modify the behavior of a program at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime].  &lt;br /&gt;
&lt;br /&gt;
This can allow programmers to write code that is more&lt;br /&gt;
consice, reducing the total number of lines of code required.  It can also introduce greater flexibility for compiled languages, without requiring a program to be recompiled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73182</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73182"/>
		<updated>2013-02-18T21:26:59Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
&lt;br /&gt;
Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73181</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73181"/>
		<updated>2013-02-18T21:26:17Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
&lt;br /&gt;
This is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73180</id>
		<title>CSC/ECE 517 Spring 2013/ch1b 1k hf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1b_1k_hf&amp;diff=73180"/>
		<updated>2013-02-18T16:57:15Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: finally, I think this is started correctly&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a [https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit link] to the writing assignment for this topic.&lt;br /&gt;
&lt;br /&gt;
Here is a [[CSC/ECE_517_Fall_2011/ch4_4g_as|link]] to previous work on this topic.&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=MainPage&amp;diff=73179</id>
		<title>MainPage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=MainPage&amp;diff=73179"/>
		<updated>2013-02-18T16:45:33Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: still trying to get the name of the new page right&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Course-Specific Topics==&lt;br /&gt;
* [[CSC 216]] learning exercise&lt;br /&gt;
* [[CSC 379]]&lt;br /&gt;
* [[CSC/ECE 506 Fall 2007]]&lt;br /&gt;
* [[ECE506_Main_Page | CSC/ECE 506 Main Portal]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2007]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
* [[CSC/ECE_517_Spring_2013/ch1b_1k_hf|Lecture on Metaprogramming]]&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=MainPage&amp;diff=73178</id>
		<title>MainPage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=MainPage&amp;diff=73178"/>
		<updated>2013-02-18T16:42:52Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: trying to properly name the new page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Course-Specific Topics==&lt;br /&gt;
* [[CSC 216]] learning exercise&lt;br /&gt;
* [[CSC 379]]&lt;br /&gt;
* [[CSC/ECE 506 Fall 2007]]&lt;br /&gt;
* [[ECE506_Main_Page | CSC/ECE 506 Main Portal]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2007]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
* [[ch1b_1k_hf|Lecture on Metaprogramming]]&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Lecture_on_Metaprogramming&amp;diff=73177</id>
		<title>Lecture on Metaprogramming</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Lecture_on_Metaprogramming&amp;diff=73177"/>
		<updated>2013-02-18T16:37:36Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: Created page with &amp;quot;This is a link to the writing assignment for this topic. This is a [[ch4_4g_as...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a [[https://docs.google.com/a/ncsu.edu/document/d/1aER6f9EDFJaUMgSpK7g5nYPiMNoUjZzwQxzY0jMW8mI/edit|link]] to the writing assignment for this topic.&lt;br /&gt;
This is a [[ch4_4g_as|link]] to previous work on this topic.&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=MainPage&amp;diff=73176</id>
		<title>MainPage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=MainPage&amp;diff=73176"/>
		<updated>2013-02-18T16:18:04Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: adding a sub category for meta programming&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Course-Specific Topics==&lt;br /&gt;
* [[CSC 216]] learning exercise&lt;br /&gt;
* [[CSC 379]]&lt;br /&gt;
* [[CSC/ECE 506 Fall 2007]]&lt;br /&gt;
* [[ECE506_Main_Page | CSC/ECE 506 Main Portal]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2007]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
* [[Lecture on Metaprogramming]]&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=MainPage&amp;diff=73175</id>
		<title>MainPage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=MainPage&amp;diff=73175"/>
		<updated>2013-02-18T16:16:27Z</updated>

		<summary type="html">&lt;p&gt;Drhowar5: adding a category for metaprogramming&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Course-Specific Topics==&lt;br /&gt;
* [[CSC 216]] learning exercise&lt;br /&gt;
* [[CSC 379]]&lt;br /&gt;
* [[CSC/ECE 506 Fall 2007]]&lt;br /&gt;
* [[ECE506_Main_Page | CSC/ECE 506 Main Portal]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2007]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
&lt;br /&gt;
==Design==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;/div&gt;</summary>
		<author><name>Drhowar5</name></author>
	</entry>
</feed>