Talk:Reflective programming: Difference between revisions

Content deleted Content added
LaQuilla (talk | contribs)
No edit summary
remove
 
(43 intermediate revisions by 28 users not shown)
Line 1:
{{Talk header}}
{{WikiProject Computing|class=|importance=}}
{{WikiProject banner shell|class=C|
{{WikiProject Computing |classimportance=Low |software=y |software-importance=Mid}}
}}
==Is eval reflection?==
 
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.
 
==Python Example==
Line 13 ⟶ 19:
</blockquote>
 
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
 
[[Special:Contributions/134.58.39.247|134.58.39.247]] ([[User talk: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 [[Artificial Intelligence|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. <!-- Template:Unsigned IP --><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/2806:107E:4:4B49:218:DEFF:FE2B:1215|2806:107E:4:4B49:218:DEFF:FE2B:1215]] ([[User talk:2806:107E:4:4B49:218:DEFF:FE2B:1215#top|talk]]) 20:08, 2 May 2017 (UTC)</small> <!--Autosigned by SineBot-->
 
==MOO code==
 
Line 25 ⟶ 33:
 
: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'''
Line 118 ⟶ 128:
 
<div class="boilerplate" style="background-color: #eeffee; margin: 2em 0 0 0; padding: 0 10px 0 10px; border: 1px dotted #AAAAAA;"><!-- Template:polltop -->
:''The following discussion is an archived debate of the {{{type|proposal}}}. <fontspan colorstyle="color:red;">'''Please do not modify it.'''</fontspan> Subsequent comments should be made in a new section on the talk page. No further edits should be made to this section. ''
 
{{{result|The result of the debate was}}} '''move'''. &mdash;[[User:Nightstallion|<span style="font-variant:small-caps">Nightst</span>]]<font color="green">[[User:Nightstallion/esperanza|<span style="font-variant:small-caps; color:green;">a</span>]]</font>[[User:Nightstallion|<span style="font-variant:small-caps">llion</span>]] [[User talk:Nightstallion|''(?)'']] <sup>[[Wikipedia:WikiProject Elections and Referenda|''Seen this already?'']]</sup> 07:49, 1 April 2006 (UTC)
==Requested move==
 
* [[Computational reflection]] → '''[[Reflection (computer science)]]''' &#133;… Return to previous name now blocked by history, more standard practice to disambiguate a term with the discipline name in parentheses. — [[User:Jon Awbrey|Jon Awbrey]] 04:52, 27 March 2006 (UTC)
----
:''Add *'''Support''' or *'''Oppose''' followed by an optional one-sentence explanation, then sign your opinion with ''<nowiki>~~~~</nowiki>
*'''Support''' --[[User:Soumyasch|Soumyasch]] 05:03, 27 March 2006 (UTC)
 
:''The above discussion is preserved as an archive of the debate. <fontspan colorstyle="color:red;">'''Please do not modify it.'''</fontspan> Subsequent comments should be made in a new section on this talk page. No further edits should be made to this section.''</div><!-- Template:pollbottom -->
 
== Example applications? ==
Line 166 ⟶ 176:
== 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. --[[User:JRavn|JRavn]] 15:07, 14 August 2006 (UTC)
:: Agreed. The description is not clear for someone unfamiliar with reflection. [[User:Praslisa|Praslisa]] ([[User talk:Praslisa|talk]]) 21:02, 17 February 2011 (UTC)
 
== Weak examples ==
All the code examples of reflection just regard what's [[dynamic dispatch]], but reflection is ''much more''. Better example needed. <span style="color: #800000; background-color: #FFFF80; padding: 1px 2px 3px 2px">''Said: [[User talk:Rursus|Rursus]] [[User:Rursus/OTHITPWMEEENAE|☺]] [[User:Rursus|★]]''</span> 17:10, 2 June 2007 (UTC)
 
[[WP:SOFIXIT]] :D --<span style="background-color: #Fda;">''[[User:Soumyasch|<fontspan colorstyle="color:#ff6633;">soum</fontspan>]]'' [[User talk:Soumyasch|(0_o)]]</span> 12:27, 3 June 2007 (UTC)
 
== C# Example doesn't fit ==
Line 194 ⟶ 205:
 
::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. [[User:Mdf|mdf]] ([[User talk:Mdf|talk]]) 20:13, 20 February 2008 (UTC)
 
 
== Smalltalk ==
Why invoke the compiler when you can do something like (Smalltalk at: className asSymbol) [[User:R4p70r|R4p70r]] ([[User talk:R4p70r|talk]]) 21:42, 2 June 2008 (UTC)
 
 
== Reification? ==
Line 211 ⟶ 217:
== Delphi is wrong example and looong ==
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. --[[User:Paddy3118|Paddy]] ([[User talk:Paddy3118|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. [[Special:Contributions/92.18.127.30|92.18.127.30]] ([[User talk:92.18.127.30|talk]]) 20:29, 9 June 2011 (UTC)
 
==C# Example Produces Compile Time Error==
Error 1 No overload for method 'GetType' takes '1' arguments --[[Special:Contributions/141.156.215.45|141.156.215.45]] ([[User talk:141.156.215.45|talk]]) 21:02, 26 April 2009 (UTC)
Line 217 ⟶ 226:
 
Truly reflective language, worth mention! The original example:
<sourcesyntaxhighlight lang="rebol">
foo: make object! [
hello: does [print "Hello"]
Line 227 ⟶ 236:
; with reflection
do get in foo to-word "hello"
</syntaxhighlight>
</source>
 
Fully featured example:
<sourcesyntaxhighlight lang="rebol">
foo: func [/local name code start-mark end-mark] [
name: ask "What is your name?^/"
Line 246 ⟶ 255:
)
]
</syntaxhighlight>
</source>
Running the code:
<pre>
Line 293 ⟶ 302:
==Too many examples==
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. --[[User:M4gnum0n|M4gnum0n]] ([[User talk: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.--[[User:Jarhed|Jarhed]] ([[User talk: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===
More than one year has passed, and nothing has changed. I renew my proposal of keeping only two examples (see above). --[[User:M4gnum0n|M4gnum0n]] ([[User talk:M4gnum0n|talk]]) 09:32, 23 February 2012 (UTC)
 
:{{Done}}, as no one objected. --[[User:M4gnum0n|M4gnum0n]] ([[User talk:M4gnum0n|talk]]) 15:08, 9 March 2012 (UTC)
 
== The Java example could be more concise ==
So I'll fix it. <small><span class="autosigned">—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:LaQuilla|LaQuilla]] ([[User talk:LaQuilla|talk]] • [[Special:Contributions/LaQuilla|contribs]]) 20:06, 3 December 2010 (UTC)</span></small><!-- Template:Unsigned --> <!--Autosigned by SineBot-->
So I'll fix it.
 
== Reflection vs Introspection: compare? merge articles?==
Please see [[Type introspection]]: very similar concepts. Wikipedia readers want understand why and what the relevant differences. <span style="font-size: smaller;" class="autosigned">—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/186.223.215.33|186.223.215.33]] ([[User talk:186.223.215.33|talk]]) 12:39, 26 February 2011 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->
 
== concept rather than paradigm ==
 
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". -- [[User:Theoprakt|Theoprakt]] ([[User talk: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. [[User:AmirOnWiki|AmirOnWiki]] ([[User talk:AmirOnWiki|talk]]) 11:44, 10 October 2013 (UTC)
 
== Tabbed UI for examples ==
 
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 <small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/213.16.221.149|213.16.221.149]] ([[User talk:213.16.221.149|talk]]) 14:54, 4 March 2015 (UTC)</small><!-- Template:Unsigned IP --> <!--Autosigned by SineBot-->
 
== PHP example - variable variable syntax ==
 
The PHP example currently contains this section:
 
<pre>
// With reflection, using variable variables syntax
$className = 'Foo';
$foo = new $className();
$method = 'hello';
$foo->$method();
</pre>
 
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 <code>new Foo()</code> to <code>new window['Foo']()</code>. 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? [[User:JulesH|JulesH]] ([[User talk:JulesH|talk]]) 00:39, 22 January 2018 (UTC)
 
==Reflection in BASIC==
 
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). [[User:ZhuLien|ZhuLien]] ([[User talk:ZhuLien|talk]]) 11:52, 6 March 2018 (UTC) <!-- Template:Unsigned IP --><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/118.127.112.218|118.127.112.218]] ([[User talk:118.127.112.218#top|talk]]) </small> <!--Autosigned by SineBot-->
 
==Compile time reflection==
 
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"
 
[[Special:Contributions/2001:14BA:1AFC:72F0:0:0:0:E18|2001:14BA:1AFC:72F0:0:0:0:E18]] ([[User talk:2001:14BA:1AFC:72F0:0:0:0:E18|talk]]) 03:39, 5 March 2019 (UTC)
 
::I agree with this. The [https://davidchristiansen.dk/david-christiansen-phd.pdf PhD dissertation by David Christiansen] on the reflection system of [[Idris (programming language)|Idris]] also defines reflection similarly, does not limit it to runtime. [[User:TuXie|TuXie]] ([[User talk:TuXie|talk]]) 18:21, 25 April 2019 (UTC)