Talk:Reflective programming

This is an old revision of this page, as edited by Gwern (talk | contribs) at 19:52, 1 December 2006 (Robot-assisted disambiguation (you can help!): Forth programming language). 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 JRavn in topic Clarification

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
Done. Please review and comment. And I suggest that the list of languages be moved to a separate article, for reasons stated below. --Soumyasch 04:27, 27 March 2006 (UTC)Reply

Title is incorrect

Per Wikipedia's manual of style for capitalization, this should be at computational reflection if anything. Making this correction would require fixing the double redirects. Fredrik Johansson 12:11, 26 March 2006 (UTC)Reply

Google hits show Computational Reflection with both capital C and capital R --Soumyasch 12:23, 26 March 2006 (UTC)Reply
Doesn't matter; it is Wikipedia's house style to capitalize only the first word in a title (with exception for proper nouns). See Wikipedia:Naming conventions (capitalization). Fredrik Johansson 12:47, 26 March 2006 (UTC)Reply

JA: The move from Reflection (computer science) to Computational reflection was ill-advised (if advised at all). Analogous considerations have come up many times before, for example, with all discipline-specific usages in mathematics, for instance, Group (mathematics) versus Mathematical group. If you think a little bit ahead (Partial lookahead (computer science)), you will perhaps see what kind of mess you are getting into with this strategy for disambiguation. Jon Awbrey 13:46, 26 March 2006 (UTC)Reply

I did not do it as a means of disambiguation but because "Computational Reflection" is a more formal name to the technique. Calling it "reflection" is a colloquialism and the word "computational" is dropped only when referring to something such as "reflective programming" or "reflective system", but if the technique is mentioned, it is always formally introduced as "Computational Reflection", even though it might be referred to as "reflection" only.

You can also refer to these [1], [2], [3], [4], [5], and all references on these pages. --Soumyasch 15:26, 26 March 2006 (UTC)Reply

JA: I am familiar with the literature. The intent of the adjective is to disambigaute the use of the term, but context already does that. However, putting the adjective up front introduces additional problems. For instance, if you consider the paradigm of parallel usage, like "computational process", the term "computational reflection" connotes an algorithm that carries out reflection. This is a useful concept, one that may even be discussed under this head, but it is not in general the concept that is being discussed here. Again, this sort of thing has come up very often before, and experience shows that putting the disciplinary category in parenthesis works best, especially as one begins to use terms in combination, supply quick wiki links, and so on. Jon Awbrey 15:42, 26 March 2006 (UTC)Reply

Well, now what? Should this title be kept or get it moved back? I have no problem with any name, its the content that matters to me. As posted earlier, I am going to expand the definition of reflection a bit, tabularize the list of languages and add a section for reflection as a programming paradigm (I know it will be bit theoretical, but I will try to make it as layman-ly as I can). I would appreciate comments in this respect as well. --Soumyasch 17:08, 26 March 2006 (UTC)Reply

JA: As far as I can tell, what little I know, the move back to Reflection (computer science) is now blocked by previous history, so requires Admin assistance. I can go through the steps for that later tonight. I think that this falls under "moves that require discussion and consensus", so that's what I think happens next. Maybe somebody else knows an easier way though? Jon Awbrey 17:16, 26 March 2006 (UTC)Reply

List of languages

I would suggest the list of reflective programming languages be forked off into a new article. The list is preventing the article from having a coherent structue and because, lists generally have their own page. Please support or oppose. --Soumyasch 03:36, 27 March 2006 (UTC)Reply

No one objected. Doing it. --Soumyasch 04:25, 28 March 2006 (UTC)Reply
The following discussion is an archived debate of the proposal. Please do not modify it. Subsequent comments should be made in a new section on the talk page. No further edits should be made to this section.

The result of the debate was move. —Nightstallion (?) Seen this already? 07:49, 1 April 2006 (UTC)Reply

Requested move


Add *Support or *Oppose followed by an optional one-sentence explanation, then sign your opinion with ~~~~
The above discussion is preserved as an archive of the debate. Please do not modify it. Subsequent comments should be made in a new section on this talk page. No further edits should be made to this section.

Example applications?

I'd be grateful if someone could put some example applications of Reflections - I mean an example where it's for example useful to use them, in more real-world situations.

I have an idea of an example, but I don't know if I understood the Reflections ideas properly. I can be completely wrong and the example stupid. Therefore, I write it here for someone to 'certify', or change, or maybe write his own one, taking from his experience - and put on the main page:


A computational program (physics problem for example) could use a library of procedures for solving a simple equation. Now, each procedure would have attributes, like:

  • it's speed,
  • it's accuracy.

Now, we write the program, which can solve problems of various sizes (from Jimmy's homework to Earth simulation). When it is started, it checks the size and type of the problem; now, knowing something more about it's nature, the program can browse through the library, aiming for:

  • solving Jimmy's homework:
    • average speed (1 equation, but needs it for tomorrow),
    • good accuracy (Jimmy wants a good mark)
  • solving Prof. Mastermind's Earth simulation:
    • superb speed (zillions of equations, which must be solved before Proffessor's life ends),
    • low accuracy (can ommit some butterflies... - speed's more important)
  • solving Cancer-super-cure simulation:
    • accuracy is crucial (we don't want people to get worse),
    • speed is unimportant (we're a huge corporation with loads of money we can spend on new supercomputers).

Reflection allows for such a 'search'. Furthermore, it allows for simple ways of adding new procedures to the library, given they're attributed with some speed & accuracy ratings - and they'll work with the program.

Am I right? or not? — Preceding unsigned comment added by Akavel (talkcontribs)

Yep, that would be possible. A program would load a Homework assembly, and search for methods which satisfy the requirements and use the one that meets the needs..

Clarification

As someone unfamiliar with reflection, this article does a poor job of explaining what it is. I have a decent idea from the example section, but the rest of the article reads like an editorial on reflection, not a description. I think for starters the summary could be improved. It doesn't need to be so long, and it only needs to summarize what reflection is in a short and concise way. It also contains some confusing grammar. For example, "More generally, reflection is an activity in computation that allows an object to have information about the structure and reason about its own computation." Information about the reason about its own computation? I have no idea what that is supposed to mean. It would be great if someone with the knowledge could make this article more clear to people not familiar with the topic. --JRavn 15:07, 14 August 2006 (UTC)Reply