Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Deon Chawaguta H190650Y

Programming Techniques Assignment 2

A) Metaprogramming refers to programming techniques where


computer programs are designed to treat other programs as their
data. This provides the program the ability to read, generate and
analyze other programs as well as modifying themselves. In
simple terms metaprogramming is writing code that writes code
for us. Metaprogramming presents abstraction, flexibility and
logical autonomy to programmers. Metaprogramming typically
in of a few ways; in the first scenario we utilize APIs (i.e.
Application Programming Interfaces) which are collections of
functions which can be called to generate the code we need; in
the second scenario we execute expressions that contain
programming commands, which is “programs that write
programs” in the purest sense, and in the last scenario we use
general purpose transformation systems which allows
metaprogramming to be applied to any target language without
consideration of the metaprogramming abilities of said target
language. The reasons behind adopting metaprogramming
include, it can bypass limitations in a target language.
Reflection is the ability of a process to examine, introspect and
modify its own structure and behavior. It is an important
strategy of metaprogramming, for example in C# reflection is
used to overcome certain accessibility rules.

B) Types of Metalanguages

1. Order Metalanguage is one consisting of levels, which


each level representing different levels of abstraction.

2. Nested Metalanguage is similar to ordered metalanguages


however the difference lies in that each level includes the one
below it.

3. Embedded metalanguage is a language embedded in the


object language, that occurs formally and naturally.

C) In spoken languages the term semantics refers to the branch


of linguistic and logic concerned with meaning, the to two main
areas being logical semantics concerning sense, reference and
presupposition and lexical semantics concerned with the
analysis of words and relations between them. In programming
and programming languages semantics also carry much of the
same meaning i.e. studying the meaning of programming
languages by evaluating the meaning of valid string defined by
specific programming languages.
Within the context of a programming language such as C++, a
statement like if a > b then c = d can only be understood both by
the compiler and the programmer writing the code if the
statement has any meaning to it. In this case the if signifies that
a condition is being tested for, that condition being a > b. In the
case that the condition is met a following expression in this case
c = d is then executed. This example serves to showcase the
necessity of understanding semantics withing programming.

References:
https://prateekvjoshi.com/2014/04/05/what-is-metaprogramming-part-12/
https://prateekvjoshi.com/2014/04/05/what-is-metaprogramming-part-22/

You might also like