CSC/ECE 517 Spring 2013/ch1b 1k hf: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 22: Line 22:
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.
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.


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.
:One of the best examples of metaprogramming is that of the [http://en.wikipedia.org/wiki/Compiler compiler]<ref>[http://c2.com/cgi/wiki?MetaProgramming Overview of Metaprogramming]</ref>.  A compiler uses code written in one language in order to generate code that can be executed by a computer.


Metaprogramming can modify the behavior of a program at [http://en.wikipedia.org/wiki/Run_time_(program_lifecycle_phase) runtime].
: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.  


 
: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<ref>[http://blog.adaptivesoftware.biz/2009/02/what-is-metaprogramming.html Coding Insights Blog]</ref>:
Some languages, such as [http://www.ruby-lang.org/en/ Ruby] are [http://en.wikipedia.org/wiki/Interpreted_language| interpreted languages].
::*Add methods to objects at runtime
::*Determine if an oject responds to a message or contains a property
::*Respond to calls made on non-existent methods
::*Respond to queries made on non-existent properties


== References ==
== References ==
<references/>
<references/>

Revision as of 15:48, 19 February 2013

  • Here is a link to the writing assignment for this topic.
  • Here is a link to previous work on this topic.


A Basic Definition of Metaprogramming

The most basic definition of metaprogramming is: writing code that writes or manipulates code. <ref>Video Lecture on Metaprogramming by Dr. Gehringer</ref> <ref name="wiki metaprogramming">Wikipedia Article on Metaprogramming</ref>

A metaprogram can either manipulate itself, or it can manipulate some other program.

Below are three important terms associated with a metaprogramming<ref name="wiki metaprogramming">Wikipedia Article on Metaprogramming</ref>:
  • metalanguage - the language in which a metaprogram is written
  • object language - the language of the program that is being manipulated by a metaprogram
  • reflection - the ability of a programming language to be its own metalanguage (also known as reflexivity)


Uses of Metaprogramming

Metaprogramming can allow programmers to write code that is more 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.

One of the best examples of metaprogramming is that of the compiler<ref>Overview of Metaprogramming</ref>. A compiler uses code written in one language in order to generate code that can be executed by a computer.
Metaprogramming is also used for building frameworks such as Ruby on Rails. In this case, the use of 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 scaffold uses the code the code written by the developer to generate code that is expansive, interconnected, and standardized.
One of the most powerful uses for metaprogramming, is the ability to change the program itself during runtime. In languages such as Groovy, programmers can<ref>Coding Insights Blog</ref>:
  • Add methods to objects at runtime
  • Determine if an oject responds to a message or contains a property
  • Respond to calls made on non-existent methods
  • Respond to queries made on non-existent properties

References

<references/>