Talk:Reflective programming

message: 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)
thread_title: Python Example

message: 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)
replies: text: 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)
thread_title: Reflection Vs meta-programming

message: 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)
thread_title:  Is reflection slow? 

message: 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)
replies: text: I will be trying to do so. --Soumyasch 10:03, 26 March 2006 (UTC)
replies: text: 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)
replies: text: 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)
thread_title:  Paradigm 

message: 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)
replies: text: Google hits show Computational Reflection with both capital C and capital R --Soumyasch 12:23, 26 March 2006 (UTC)
replies: text: 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)

text: 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 , , , , , and all references on these pages.
--Soumyasch 15:26, 26 March 2006 (UTC)

text: 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)
thread_title: Title is incorrect

message: 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)
replies: text: No one objected. Doing it. --Soumyasch 04:25, 28 March 2006 (UTC)

text: 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)
thread_title:  List of languages 

message: 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.
: 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)
replies: text: 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)
thread_title:  Example applications? 

message: 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)
replies: text:  Agreed. The description is not clear for someone unfamiliar with reflection. Praslisa (talk) 21:02, 17 February 2011 (UTC)
thread_title:  Clarification 

message: 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)
thread_title:  Weak examples 

message: 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.
: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)
thread_title:  C# Example doesn't fit 

message: 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)
replies: text: 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)
thread_title:  Interpreted languages 

message: 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)
replies: text: 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)
replies: text: 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)
thread_title:  high level language 

message: 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)
replies: text: 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)
thread_title:  Reification? 

message: 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)
thread_title:  Delphi is wrong example and looong 

message: Error	1	No overload for method 'GetType' takes '1' arguments  --141.156.215.45 (talk) 21:02, 26 April 2009 (UTC)
thread_title: C# Example Produces Compile Time Error

message: 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)
replies: text: 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)
replies: text: 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===
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)

text: , as no one objected. --M4gnum0n (talk) 15:08, 9 March 2012 (UTC)
thread_title: Too many examples

message: 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)
replies: text: , as no one objected. --M4gnum0n (talk) 15:08, 9 March 2012 (UTC)
thread_title: Examplefarm, again

message: So I'll fix it.  —Preceding unsigned comment added by LaQuilla (talk • contribs) 20:06, 3 December 2010 (UTC)
thread_title:  The Java example could be more concise 

message: 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)
thread_title:  Reflection vs Introspection: compare? merge articles?

message: 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)
replies: text: 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)
thread_title:  concept rather than paradigm 

message: 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)
thread_title:  Tabbed UI for examples 

message: 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:
* 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)
thread_title:  PHP example - variable variable syntax 

message: 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)
thread_title: Reflection in BASIC

message: 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:
* 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)
replies: text: 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)
thread_title: Compile time reflection