Talk:Reflective programming

This is an old revision of this page, as edited by Soumyasch (talk | contribs) at 10:03, 26 March 2006 (Paradigm). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Latest comment: 19 years ago by Soumyasch in topic Paradigm

Self-modifying code

How does reflection relate to self-modifying code? The terms are used in quite different contexts, of course, but aren't they really forms of the same thing? Self-modifying code is usually done in assembly language, and is normally considered bad form; reflection is usually considered a good thing, especially if the language is set up for it. I might at least add a "see also" to the other one on both pages. Benhoyt 20:56, 22 December 2005 (UTC)Reply

Is reflection slow?

I removed "Depending on the implementation, code with reflection tends to run slower than that without it." Sure, it does depend on the implementation, but I thought this was unhelpful, because it only applies to a particular kind of reflection. With many types of reflection, such as macros and code compiling code, the whole point is to make the result run faster.

For example, in Forth you could add up the numbers from 0 to 9 with a loop, or with an unrolled, reflective-style loop:

: count  ( -- )
  0  10 0 do  i +  loop  . ;
count
: unrolled-count  ( -- xt )
  :noname
  0 postpone literal
  10 0 do
    i postpone literal  postpone +
  loop
  postpone .  postpone ;  ;
\ effectively ":noname 0 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + . ;"
unrolled-count execute

For a better, more "real-life" example, see Bruce Hoyt's Fast Pentomino Solver written in Forth using generated macros. Benhoyt 20:26, 22 December 2005 (UTC)Reply

Emmited vs produced

Is the meaing of the word "emmited" here similar to the word "produced?" It might be easier for a non-programmer to understand the intended meaning if the word "produced" were used, since one reading this is probably already immersed in unfamiliar terminology that may have meanings beyond typical language.

Uh, aren't C# and Visual Basic.NET reflective languages? If not why not? They have runtime metadata. KellyCoinGuy 07:29, August 20, 2005 (UTC)

Reflection in C

Humm, in fact the GNU C language does have some reflection capabilities, through the dl library. Here is the code example for that:

#define _GNU_SOURCE 1
#include <dlfcn.h>
int
main(void)
{
 typedef int (*printf_t) (const char *format, ...);
 printf_t the_printf;
 the_printf = dlsym (RTLD_DEFAULT, "printf");
 the_printf ("Hello %s!\n", "world");
 return 0;
}

Behdad 03:47, 23 September 2005 (UTC)Reply

That's not reflection, that's dynamic linking, a form of late binding. It does allow you to do things you couldn't do statically, but it doesn't give you knowledge about the program's own structure like reflection does. You can't find out how many arguments a function takes or what procedures a library exports, for example, or dynamically create objects of a given type name, find out what members an aggregate type has, etc. If we can call this reflection at all, it's a very weak sort of reflection, and it's certainly not part of the language itself (support for dynamic linking comes from the environment; the language guarantees nothing). 82.92.119.11 15:09, 25 November 2005 (UTC)Reply

Paradigm

This article should include a section on reflective programming as a paradigm. And the list of languages should also be presented in a multi-column tabular form, for better readability --Soumyasch 10:00, 26 March 2006 (UTC)Reply

I will be trying to do so. --Soumyasch 10:03, 26 March 2006 (UTC)Reply