Talk:Reflective programming: Difference between revisions

Content deleted Content added
Reflection Vs meta-programming: emphasized the key idea
remove
 
(21 intermediate revisions by 14 users not shown)
Line 1:
{{Talk header}}
{{WikiProject Computing|class=start|importance=}}
{{WikiProject banner shell|class=C|
{{findsourcesnotice|Reflection|("object oriented" OR "programming (language OR paradigm)" OR "computer (programming OR science)")}}
{{WikiProject Computing |classimportance=Low |software=starty |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 17 ⟶ 22:
 
[[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 122 ⟶ 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 175 ⟶ 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 220 ⟶ 226:
 
Truly reflective language, worth mention! The original example:
<sourcesyntaxhighlight lang="rebol">
foo: make object! [
hello: does [print "Hello"]
Line 230 ⟶ 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 249 ⟶ 255:
)
]
</syntaxhighlight>
</source>
Running the code:
<pre>
Line 320 ⟶ 326:
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)