Talk:Reflective programming
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: | ||||||||||||||
|
Is eval reflection?
editI 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.
Python Example
editThe 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)
Reflection Vs meta-programming
editI 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 agree with you, but reasoning is too ambiguous and more in the field of AI. It seems that more peopole thing about this term in the context of programming languages, although theoretically this concept is as old as the Universal Turing Machine which lead to the concept or programmable computers. A program that reason about it self is more interesting from a philosophic perspective. — Preceding unsigned comment added by 2806:107E:4:4B49:218:DEFF:FE2B:1215 (talk) 20:08, 2 May 2017 (UTC)
MOO code
editI'm going to give a sentence to the MOO code just like all the other programming languages.
Self-modifying code
editHow 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 don't think that reflection is self-modifing code, they are two different things. With reflection, code does not change at runtime at all, it's only introspection, code knows about itself, but does not change at all. You could do reflection even in C (but it's not portalbe), as you can call functions via pointers, and you could search for the required pointer to be called by browsing through the debug symbol database for example. But the article DOES make confusion betweek reflection, that is, knowing itself, with self-modification, that is an entirely different concept! Most languages that support reflection do not support self-modification. IMHO the article is all wrong in this respect! AND there are some self-modifing languages where you can't query for the type of an object and thus, they don't have reflection. - AngeloPesce, Jan 2008
- Reflection is not just introspection. Reflection may be divided in two major areas: introspection and intercession. Self-modifing code is a form of intercession as as such is a form of reflection. - Vieira, Jun 2012
- Also every example there that uses code interpretation (that still is NOT QUITE full self-modifing code, because you're just invoking the interpreter to parse more text, but you are not allowed to modify existing code, or at least, not easily, that's something that is only doable in ASM or in languages that have code-as-data equivalence, like LISP) are _plain wrong_. There you don't have reflection, you are not allowed to know the type given a string, to query the interpreter database... you're only hacking the function call by interpreting it in runtime, instead of having it hardcoded. It's not, conceptually, the same thing. For example, if I have an interpreted language that makes me interpret strings in runtime, I surely can call methods given the string of the class and of the method, but still is not quite the same thing as getting the type object via a string. IMHO those examples are only confusing, and are one of the typical Wikipedia problems, users add everything just to add things to the article, even if the examples are not useful to clarify the concept, and rather they make it harder to be understood. This is really bad. - AngeloPesce, Jan 2008, please consider deleting those examples
Is reflection slow?
editI 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)
Emmited vs produced
editIs 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
editHumm, 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)
- 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)
- Like Behdad, I fail to see the distinction beyond that dlsym() is only a slightly weak implementation of the idea: add more meta-information to the shared library, and a small amount of infrastructure, and reflection in the "strong" sense will appear. That this is all possible at such a low level suggests that, indeed, this is a property of the environment, not of any particular language. That there are special hooks and syntax in language X to help it along is no more or no less than the aforementioned "infrastructure".
- Also note my use of "slightly". The fact you can dig out information about code and data structures doesn't help you much in the end, unless you know what you are looking for and how to use what you finally find. Behdad's printf() example is basically identical to all the examples in the article. They search for something in some meta-database and, upon success, make immediate use of it. mdf 13:10, 15 August 2007 (UTC)
- "Add more meta-information to the shared library, and a small amount of infrastructure, and reflection in the "strong" sense will appear." Sure, and add garbage collection, references, exceptions and runtime checks to the library (all of which can certainly be implemented with enough low-level grovelling) and you'll have C#. More or less. But that's not the point.
- The point is that the C programming language has no support for reflection. Of course the environment is very likely to provide some form of metadata discovery if you go low-level -- it would be hard not to. (For one thing, almost any environment will allow a program to inspect its own executable, even if it has to do all the gruntwork itself.) But calling this "reflection" is missing the point entirely -- namely, that such features are only relevant to the discussion if they're part of the language proper. dlsym() cannot be called part of the language proper, not even if we constrain ourselves to the particular dialect of C as implemented by the GNU Compiler Collection.
- If you want to call this "a weak form of reflection provided by the environment", then sure, go ahead, but calling this reflection does not change the fact that C is not a reflective language, so Behdad's statement is at best misleading, and your dismissal of native reflection as "hooks and syntax" reminds me of the old adage that "you can write FORTRAN in any language". The same is doubtlessly true for getting reflection, as long as you're willing to put in all the extra work yourself. But you're getting dangerously close to just reasserting the basics of the von Neumann architecture. 82.95.254.249 (talk) 01:41, 27 November 2007 (UTC)
- There is no such thing as GNU C language, there is a GNU C compiler only. And I think that it's not useful anyways to add information about a non-standard non-portable way of doing reflection in C. Of course it can be done. In a non portable way it can be done with each compiler that has debug symbols. It's even easy, there's nothing magic in GNU C. But how does this add to the concept and understanding of the reflection concept? If you explain the concept clearly, then of course a C programmer know that he can implement it in C. It's something that should not enter in the main article IMHO. -AngeloPesce —Preceding unsigned comment added by 24.80.96.229 (talk) 07:04, 9 January 2008 (UTC)
- This article has examples from many languages on how programs can peer into their own guts. Given it is possible to do this with C, C++ or anything else with access to dlsym(), or other mechanisms, then such examples can only serve to highlight the technique even more. To simply state that "C" or "C++" has no reflective abilities, or to re-label them as "late binding" (as if that isn't what reflection will boil down to in the end!) is deeply misleading. C#, Objective-C, Java, and other languages are no more special, beyond making the resulting code slightly less messy. mdf (talk) 20:00, 20 February 2008 (UTC)
- I don't dismiss reflection as "hooks and syntax": I assert that is what reflection ultimately is, assuming the relevant information is accessible. There is nothing inherently special about making glorified calls to dlsym() vs. directly calling dlsym() -- beyond the obvious lack of detail inherent in dlsym() implementations. "#include <dlfcn.h>" or "#include <libelf/libelf.h>" vs. something like "using System.Reflection" is neither here nor there, and I say from experience that both make for fairly horrid snippets of code. I suspect that when you speak of "language proper", you are confusing syntax and semantics of a language with a abilities of a run-time library. Or the "environment", as I said back in August. That, as you observe, any von Neumann machine is capable of this behavior should be a very strong hint that the language has little, if anything, to do with reflection. mdf (talk) 20:00, 20 February 2008 (UTC)
Paradigm
editThis 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)
- I will be trying to do so. --Soumyasch 10:03, 26 March 2006 (UTC)
- 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)
- The first paragraph of this makes very little sense. There is no need (and in my experience it's quite rare) for imperative or object oriented programs to be "pre-determined" in the way you describe. There is no mention anywhere else in the article of how reflection provides self-optimization. In all, I think this section doesn't actually describe reflection in the same sense as the rest of the article itself and should probably be moved. The keeping of meta-information for all compound statements in a program, including what the statement actually does sounds... intractable too. 84.19.238.82 09:39, 31 January 2007 (UTC)
- 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)
Title is incorrect
editPer 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)
- Google hits show Computational Reflection with both capital C and capital R --Soumyasch 12:23, 26 March 2006 (UTC)
- 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)
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)
- 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)
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)
- 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)
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)
List of languages
editI 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)
- No one objected. Doing it. --Soumyasch 04:25, 28 March 2006 (UTC)
- 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)
Requested move
edit- Computational reflection → Reflection (computer science) Return to previous name now blocked by history, more standard practice to disambiguate a term with the discipline name in parentheses. — Jon Awbrey 04:52, 27 March 2006 (UTC)
- Add *Support or *Oppose followed by an optional one-sentence explanation, then sign your opinion with ~~~~
- Support --Soumyasch 05:03, 27 March 2006 (UTC)
- 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?
editI'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.
- Say you have a class with several methods that want to be exposed to a user-facing menu. Every time you add such a method, you want it to appear in the menu. One way is to write the menu explicitly, and modify the menu code manually every time you add a method, but that's labor intensive, error-prone, and easy to forget to do. With reflection, you can implement the menu so that it inspects the class and populates itself with all the appropriate methods. I use this a lot -- any time you find yourself writing repetitive, mechanical boilerplate code, or where making a change in one place in the code requires you to make matching changes in other places, reflection might be useful. Kaleja (talk) 21:15, 10 February 2010 (UTC)
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 (talk • contribs)
- 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..
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)
Clarification
editAs 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)
- Agreed. The description is not clear for someone unfamiliar with reflection. Praslisa (talk) 21:02, 17 February 2011 (UTC)
Weak examples
editAll 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)
C# Example doesn't fit
editThe 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.
- I'm thinking the following snippet (probably the simplest way to reflect in C#) might be more understandable to the lay-programmer. It minimizes the need to recognize the .NET System.Type and System.Reflection.BindingFlags classes, and it parallels the (create object -> call method on object) style that the other language examples use. Talyian (talk) 23:18, 8 April 2008 (UTC)
//With reflection
object foo = Activator.CreateInstance(null, "Foo");
foo.GetType().GetMethod("Hello").Invoke(foo, null);
Interpreted languages
editThe 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)
- Also there is no thing as "interpreted programming languages", a PL is a specification of a language, there you can implement it into an interpreter, a compiler or a JIT. As long as you can respect the specification, it's fine. Ruby has its compilers as well. And having the source code availabe is no useful at all, it would be the same to say that if you ship C programs with their sourcecode then it's easy to do reflection in C... But it's true that reflection is trivial to implement into an interpreter, but not because an interpreter has the source loaded everytime (it's not true, it gets tokenized and discarded) but because it usually has all the symbols loaded (but it could discard them as well and if so, then reflection would be impossible) —Preceding unsigned comment added by 24.80.96.229 (talk) 07:09, 9 January 2008 (UTC)
high level language
editThe 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)
- Yes it's really confusing, and it's wrong too. "With high-level languages, when program source code is compiled, information about the structure of the program is normally lost when low-level code (typically machine language code) is produced, unless, of course, the code is compiled into an Intermediate Language (IL)...". Who told that? Normally, every compiler retains the information about the types of the target code for debugging purposes, so actually, every compiler has a way to save that info, it's not a novelty of IL-languages and there is no reason for IL-languages to retain more info than non-IL ones. Of course, Java and C# do retain that info in the IL, but because they are reflective languages, it's a conseguence of language design, not IL use. I've deleted that statement - AngeloPesce —Preceding unsigned comment added by 24.80.96.229 (talk) 07:13, 9 January 2008 (UTC)
- Come now, there is absolutely nothing in (say) Java that makes reflection a "consequence of language design". Indeed, that you need to import the appropriate library before this computational navel-gazing can occur is good evidence the language is not inherently reflective. As I said above, the substrate itself is why this stuff works: the code-data duality is built right into the machinery. This is mentioned in the first paragraph of this article, but could use some highlighting, in my opinion. mdf (talk) 20:13, 20 February 2008 (UTC)
Reification?
editIs 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)
- Loosely related, but not the same. Reification is a much more general concept; some kinds of reification can be achieved with the help of reflection. For instance, something like "the name of the function that called the current function" is an abstraction. By using reflection, you could reify that into a string containing the name of the calling function. Reification is the goal, reflection is the tool. Kaleja (talk) 21:08, 10 February 2010 (UTC)
Delphi is wrong example and looong
editIt 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)
C# Example Produces Compile Time Error
editError 1 No overload for method 'GetType' takes '1' arguments --141.156.215.45 (talk) 21:02, 26 April 2009 (UTC)
REBOL
editTruly 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 == []
Too many examples
editThe 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)
- I could not disagree more. All of the examples are useful in understanding the issue from a programming and language implementation perspective.--Jarhed (talk) 02:20, 1 July 2011 (UTC)
- Not "too many" examples but rather no prominent example of self-modifying code. All I saw in C# and Java was code using "Reflection" to create an instance of a class.
Examplefarm, again
editMore 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)
- Done, as no one objected. --M4gnum0n (talk) 15:08, 9 March 2012 (UTC)
The Java example could be more concise
editSo I'll fix it. —Preceding unsigned comment added by LaQuilla (talk • contribs) 20:06, 3 December 2010 (UTC)
Reflection vs Introspection: compare? merge articles?
editPlease 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)
concept rather than paradigm
editI 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)
- Based on the current contents of these categories, Category:Programming constructs seems most appropriate. There is a certain ambiguity in its relation to Category:Programming language concepts - there is room for some cleanup and reorganization there. AmirOnWiki (talk) 11:44, 10 October 2013 (UTC)
Tabbed UI for examples
editWould 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)
PHP example - variable variable syntax
editThe 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:
- It doesn't allow introspection, only indirection.
- You can't get a list of available classes using this technique.
- Given a class name, you can't tell if it exists or not (other than by attempting to create one and catching the exception if that fails).
- Given a class name, you can't get a list of its methods (other than by instantiating it, and examining the resulting object to find out its properties, which you would need to do using an *actual* reflection API, rather than this technique).
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)
Reflection in BASIC
editWould 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)
Compile time reflection
editThe 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:
- http://www.drdobbs.com/windows/compile-time-reflection-metaprogramming/228700607
- https://www.gnu.org/software/gcc/projects/cxx-reflection/
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0385r0.pdf
- https://rly.sexy/post/basic-reflection-in-pure-cpp17
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)
- I agree with this. The PhD dissertation by David Christiansen on the reflection system of Idris also defines reflection similarly, does not limit it to runtime. TuXie (talk) 18:21, 25 April 2019 (UTC)