Talk:Reflective programming: Difference between revisions

Content deleted Content added
remove
 
(29 intermediate revisions by 19 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 26 ⟶ 34:
: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 120 ⟶ 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 173 ⟶ 181:
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 218 ⟶ 226:
 
Truly reflective language, worth mention! The original example:
<sourcesyntaxhighlight lang="rebol">
foo: make object! [
hello: does [print "Hello"]
Line 228 ⟶ 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 247 ⟶ 255:
)
]
</syntaxhighlight>
</source>
Running the code:
<pre>
Line 311 ⟶ 319:
 
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)