This is the
talk page for discussing improvements to the
Reflective programming article. This is not a forum for general discussion of the article's subject. |
Article policies
|
Find sources: Google ( books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
This article is rated C-class on Wikipedia's
content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||
|
I don't think eval should be considered in creating examples of reflection in programming languages. Few programs would ever use eval, and none would use it to hack around language limitations.
The Python example wasn't equivalent -- it did more and was presented as an interpreter session -- so I stripped it down to equivalence. As it was, it made Python look bad, and the examples in everyone's favorite programming languages are bloating the article anyway. Kaleja ( talk) 21:22, 10 February 2010 (UTC)
I think this article is not about reflection but about reflective programming, for reflection, I would like to cite Pattie Maes, Concepts and experiments in computational reflection, in the proceedings of OOPSLA '87
We define computational reflection to be the behavior exhibited by a reflective system, where a reflective system is a computational system which is about itself in a causally connected way.
This just means that reflection is the ability of a program to reason about itself. So the first sentence of the article is on toppic, the rest is about Reflection-oriented programming
134.58.39.247 ( talk) 08:31, 20 October 2008 (UTC)
I'm going to give a sentence to the MOO code just like all the other programming languages.
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)
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)
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)
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)
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)
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)
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)
You can also refer to these [1], [2], [3], [4], [5], and all references on these pages. -- Soumyasch 15:26, 26 March 2006 (UTC)
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)
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)
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)
The result of the debate was move. — Nightst a llion (?) Seen this already? 07:49, 1 April 2006 (UTC)
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:
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:
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 ( talk • contribs)
Do I supose correctly that this technique covers the often-used method (at least in the good old times of commodore 64) of reverse engineering protection, where the beginnig of the program actually decodes the next part, which in turn decodes the further parts of the code, then run them? -- grin ✎ 14:46, 18 August 2010 (UTC)
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)
All the code examples of reflection just regard what's dynamic dispatch, but reflection is much more. Better example needed. Said: Rursus ☺ ★ 17:10, 2 June 2007 (UTC)
WP:SOFIXIT :D -- soum (0_o) 12:27, 3 June 2007 (UTC)
The C# example doesn't fall in line with the other examples, so I feel that it's less helpful as a comparison. Perhaps either the C# example should be simpler (ie the Java one), or all the examples should implement some common functionality. That would give more insight into how each language handles reflection.
//With reflection
object foo = Activator.CreateInstance(null, "Foo");
foo.GetType().GetMethod("Hello").Invoke(foo, null);
The article stated: Interpreted programming languages, such as Ruby and PHP, are ideally suited to reflection, since their source code is never lost in the process of translation to machine language—the interpreter has the source readily available.
Ideally suited to reflection... what a strong statement, and sorry, that is definitely not the state of the art. Other implicit assumptions, such as source code being available as a string as opposed to an abstract syntax tree, have been negated more than 40 years ago, too. -- Zz 09:56, 17 September 2007 (UTC)
The classification of languages as 'high level' or 'low level' is almost never useful. This article is another example where it adds nothing except confusion. 150.101.166.15 08:47, 18 October 2007 (UTC)
Is this related to reification? I just came from that article, but it wasn't clear if or how these two concepts were related. I'm starting to suspect they are essentially the same idea.
Thanks
99.170.78.44 ( talk) 19:51, 16 July 2008 (UTC)
It would be good if it were shortened and stuck to the foo.hello type of example used by the other languages. At its current length/subject it detracts from the article. Could someone make the edit. -- Paddy ( talk) 15:06, 30 July 2008 (UTC)
I've no idea what the example referenced above looked like, but hopefully the new one I've added is up to scratch. 92.18.127.30 ( talk) 20:29, 9 June 2011 (UTC)
Error 1 No overload for method 'GetType' takes '1' arguments -- 141.156.215.45 ( talk) 21:02, 26 April 2009 (UTC)
Truly reflective language, worth mention! The original example:
foo: make object!
hello: does print "Hello"
; without reflection
foo/hello
; with reflection
do get in foo to-word "hello"
Fully featured example:
foo: func /local name code start-mark end-mark
name: ask "What is your name?^/"
print "Hello," name
(
; examination
code: second :foo ; accessing our actual code as data array
start-mark: find code 'ask ; searching for code fragment to change
end-mark: find code 'print
; replication
bar: func first :foo code ; making backup copy of our original code
; modification
change/part start-mark name end-mark ; replacing input operation with hardcoded value
remove back tail code ; removing self-modification code
)
Running the code:
>> foo What is your name? Alice Hello, Alice == []
Now function changed its code to not ask the same question twice.
>> foo Hello, Alice
Foo's current code:
>> source foo foo: func [/local name code start-mark end-mark][ name: "Alice" print ["Hello," name] ]
Restoring original code from backup:
>> foo: :bar >> source foo foo: func [/local name code start-mark end-mark][ name: ask "What is your name?^/" print ["Hello," name] ( code: second :foo start-mark: find code 'ask end-mark: find code 'print bar: func first :foo code change/part start-mark name end-mark remove back tail code ) ] >> foo What is your name? Bob Hello, Bob == []
The Examples section is unnecessarily long. In fact, it is longer than the rest of the article. I propose to remove all the examples but one of C#/Java and one of Perl/PHP. -- M4gnum0n ( talk) 16:56, 20 November 2010 (UTC)
More than one year has passed, and nothing has changed. I renew my proposal of keeping only two examples (see above). -- M4gnum0n ( talk) 09:32, 23 February 2012 (UTC)
So I'll fix it. —Preceding unsigned comment added by LaQuilla ( talk • contribs) 20:06, 3 December 2010 (UTC)
Please see Type introspection: very similar concepts. Wikipedia readers want understand why and what the relevant differences. —Preceding unsigned comment added by 186.223.215.33 ( talk) 12:39, 26 February 2011 (UTC)
I would rather put this in Category:Programming language concepts than in Category:Programming paradigms. I would think of a programming paradigm as a set of concepts, a set of things which you can or cannot do in a certain language or a certain style of programming. Reflection rather is a one-trick-pony, enabling the programmer to get the identifier of some entity at runtime (or similar concepts) and make a decision upon the result. So "reflection" would be just one concept of the larger paradigm of "metaprogramming". -- Theoprakt ( talk) 20:57, 15 November 2011 (UTC)
Would be nice if all examples could be in one place shown as tabs, like MSDN articles do. When printing the currently selected/visible one could be printed instead of everything — Preceding unsigned comment added by 213.16.221.149 ( talk) 14:54, 4 March 2015 (UTC)
The PHP example currently contains this section:
// With reflection, using variable variables syntax $className = 'Foo'; $foo = new $className(); $method = 'hello'; $foo->$method();
Now, as far as I can see, this method isn't really an example of reflection but it is rather a language feature that allows you to reference a symbol indirectly via a variable. As such it is very similar to taking the approach in Javascript (for example) of using indexing on the global object rather than direct references, e.g. translating new Foo()
to new window['Foo']()
. Specific reasons I don't believe this qualifies as reflection:
I'm therefore not convinced that this example belongs here. It's an interesting hack, and a useful, simple way of creating dynamic behaviour, but due to lacking facilities for introspection, I'm not convinced it's an example of Reflection. Opinions? JulesH ( talk) 00:39, 22 January 2018 (UTC)
Would functions in BASIC be considered a form of reflection with def fn? Since functions themselves are defined in BASIC and can (depending on the implementation be redefined). ZhuLien ( talk) 11:52, 6 March 2018 (UTC) — Preceding unsigned comment added by 118.127.112.218 ( talk)
The article begins with:
"In computer science, reflection is the ability of a computer program to examine, introspect, and modify its own structure and behavior at runtime."
However, e.g. Heron and C++ communities know the concept of compile-time reflection. I think the scope of the article should also include these since they're used in similar ways as runtime reflection.
Sources:
The P0385R0 document has the following definition for reflection:
"In the context of computer science, the term reflection refers to the ability of a program to examine and possibly modify its own structure and/or behavior.
When combined with metaprogramming, this can include modification of the existing or the definition of new data structures, doing changes to algorithms or changing the way a program code is interpreted"
2001:14BA:1AFC:72F0:0:0:0:E18 ( talk) 03:39, 5 March 2019 (UTC)
This is the
talk page for discussing improvements to the
Reflective programming article. This is not a forum for general discussion of the article's subject. |
Article policies
|
Find sources: Google ( books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
This article is rated C-class on Wikipedia's
content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||
|
I don't think eval should be considered in creating examples of reflection in programming languages. Few programs would ever use eval, and none would use it to hack around language limitations.
The Python example wasn't equivalent -- it did more and was presented as an interpreter session -- so I stripped it down to equivalence. As it was, it made Python look bad, and the examples in everyone's favorite programming languages are bloating the article anyway. Kaleja ( talk) 21:22, 10 February 2010 (UTC)
I think this article is not about reflection but about reflective programming, for reflection, I would like to cite Pattie Maes, Concepts and experiments in computational reflection, in the proceedings of OOPSLA '87
We define computational reflection to be the behavior exhibited by a reflective system, where a reflective system is a computational system which is about itself in a causally connected way.
This just means that reflection is the ability of a program to reason about itself. So the first sentence of the article is on toppic, the rest is about Reflection-oriented programming
134.58.39.247 ( talk) 08:31, 20 October 2008 (UTC)
I'm going to give a sentence to the MOO code just like all the other programming languages.
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)
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)
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)
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)
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)
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)
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)
You can also refer to these [1], [2], [3], [4], [5], and all references on these pages. -- Soumyasch 15:26, 26 March 2006 (UTC)
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)
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)
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)
The result of the debate was move. — Nightst a llion (?) Seen this already? 07:49, 1 April 2006 (UTC)
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:
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:
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 ( talk • contribs)
Do I supose correctly that this technique covers the often-used method (at least in the good old times of commodore 64) of reverse engineering protection, where the beginnig of the program actually decodes the next part, which in turn decodes the further parts of the code, then run them? -- grin ✎ 14:46, 18 August 2010 (UTC)
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)
All the code examples of reflection just regard what's dynamic dispatch, but reflection is much more. Better example needed. Said: Rursus ☺ ★ 17:10, 2 June 2007 (UTC)
WP:SOFIXIT :D -- soum (0_o) 12:27, 3 June 2007 (UTC)
The C# example doesn't fall in line with the other examples, so I feel that it's less helpful as a comparison. Perhaps either the C# example should be simpler (ie the Java one), or all the examples should implement some common functionality. That would give more insight into how each language handles reflection.
//With reflection
object foo = Activator.CreateInstance(null, "Foo");
foo.GetType().GetMethod("Hello").Invoke(foo, null);
The article stated: Interpreted programming languages, such as Ruby and PHP, are ideally suited to reflection, since their source code is never lost in the process of translation to machine language—the interpreter has the source readily available.
Ideally suited to reflection... what a strong statement, and sorry, that is definitely not the state of the art. Other implicit assumptions, such as source code being available as a string as opposed to an abstract syntax tree, have been negated more than 40 years ago, too. -- Zz 09:56, 17 September 2007 (UTC)
The classification of languages as 'high level' or 'low level' is almost never useful. This article is another example where it adds nothing except confusion. 150.101.166.15 08:47, 18 October 2007 (UTC)
Is this related to reification? I just came from that article, but it wasn't clear if or how these two concepts were related. I'm starting to suspect they are essentially the same idea.
Thanks
99.170.78.44 ( talk) 19:51, 16 July 2008 (UTC)
It would be good if it were shortened and stuck to the foo.hello type of example used by the other languages. At its current length/subject it detracts from the article. Could someone make the edit. -- Paddy ( talk) 15:06, 30 July 2008 (UTC)
I've no idea what the example referenced above looked like, but hopefully the new one I've added is up to scratch. 92.18.127.30 ( talk) 20:29, 9 June 2011 (UTC)
Error 1 No overload for method 'GetType' takes '1' arguments -- 141.156.215.45 ( talk) 21:02, 26 April 2009 (UTC)
Truly reflective language, worth mention! The original example:
foo: make object!
hello: does print "Hello"
; without reflection
foo/hello
; with reflection
do get in foo to-word "hello"
Fully featured example:
foo: func /local name code start-mark end-mark
name: ask "What is your name?^/"
print "Hello," name
(
; examination
code: second :foo ; accessing our actual code as data array
start-mark: find code 'ask ; searching for code fragment to change
end-mark: find code 'print
; replication
bar: func first :foo code ; making backup copy of our original code
; modification
change/part start-mark name end-mark ; replacing input operation with hardcoded value
remove back tail code ; removing self-modification code
)
Running the code:
>> foo What is your name? Alice Hello, Alice == []
Now function changed its code to not ask the same question twice.
>> foo Hello, Alice
Foo's current code:
>> source foo foo: func [/local name code start-mark end-mark][ name: "Alice" print ["Hello," name] ]
Restoring original code from backup:
>> foo: :bar >> source foo foo: func [/local name code start-mark end-mark][ name: ask "What is your name?^/" print ["Hello," name] ( code: second :foo start-mark: find code 'ask end-mark: find code 'print bar: func first :foo code change/part start-mark name end-mark remove back tail code ) ] >> foo What is your name? Bob Hello, Bob == []
The Examples section is unnecessarily long. In fact, it is longer than the rest of the article. I propose to remove all the examples but one of C#/Java and one of Perl/PHP. -- M4gnum0n ( talk) 16:56, 20 November 2010 (UTC)
More than one year has passed, and nothing has changed. I renew my proposal of keeping only two examples (see above). -- M4gnum0n ( talk) 09:32, 23 February 2012 (UTC)
So I'll fix it. —Preceding unsigned comment added by LaQuilla ( talk • contribs) 20:06, 3 December 2010 (UTC)
Please see Type introspection: very similar concepts. Wikipedia readers want understand why and what the relevant differences. —Preceding unsigned comment added by 186.223.215.33 ( talk) 12:39, 26 February 2011 (UTC)
I would rather put this in Category:Programming language concepts than in Category:Programming paradigms. I would think of a programming paradigm as a set of concepts, a set of things which you can or cannot do in a certain language or a certain style of programming. Reflection rather is a one-trick-pony, enabling the programmer to get the identifier of some entity at runtime (or similar concepts) and make a decision upon the result. So "reflection" would be just one concept of the larger paradigm of "metaprogramming". -- Theoprakt ( talk) 20:57, 15 November 2011 (UTC)
Would be nice if all examples could be in one place shown as tabs, like MSDN articles do. When printing the currently selected/visible one could be printed instead of everything — Preceding unsigned comment added by 213.16.221.149 ( talk) 14:54, 4 March 2015 (UTC)
The PHP example currently contains this section:
// With reflection, using variable variables syntax $className = 'Foo'; $foo = new $className(); $method = 'hello'; $foo->$method();
Now, as far as I can see, this method isn't really an example of reflection but it is rather a language feature that allows you to reference a symbol indirectly via a variable. As such it is very similar to taking the approach in Javascript (for example) of using indexing on the global object rather than direct references, e.g. translating new Foo()
to new window['Foo']()
. Specific reasons I don't believe this qualifies as reflection:
I'm therefore not convinced that this example belongs here. It's an interesting hack, and a useful, simple way of creating dynamic behaviour, but due to lacking facilities for introspection, I'm not convinced it's an example of Reflection. Opinions? JulesH ( talk) 00:39, 22 January 2018 (UTC)
Would functions in BASIC be considered a form of reflection with def fn? Since functions themselves are defined in BASIC and can (depending on the implementation be redefined). ZhuLien ( talk) 11:52, 6 March 2018 (UTC) — Preceding unsigned comment added by 118.127.112.218 ( talk)
The article begins with:
"In computer science, reflection is the ability of a computer program to examine, introspect, and modify its own structure and behavior at runtime."
However, e.g. Heron and C++ communities know the concept of compile-time reflection. I think the scope of the article should also include these since they're used in similar ways as runtime reflection.
Sources:
The P0385R0 document has the following definition for reflection:
"In the context of computer science, the term reflection refers to the ability of a program to examine and possibly modify its own structure and/or behavior.
When combined with metaprogramming, this can include modification of the existing or the definition of new data structures, doing changes to algorithms or changing the way a program code is interpreted"
2001:14BA:1AFC:72F0:0:0:0:E18 ( talk) 03:39, 5 March 2019 (UTC)