81

What is the origin of the term reflection? It seems more like introspection. Why isn't it called that?

Introspection: A looking inward; specifically, the act or process of self-examination.

Reflection:

  1. the act of reflecting or the state of being reflected.
  2. an image; representation; counterpart
  3. a fixing of the thoughts on something; careful consideration
  4. a thought occurring in consideration or meditation.
tvanfosson
  • 524,688
  • 99
  • 697
  • 795
  • actually this is an interesting question. i'm not sure anymore i see any difference :p – Johannes Schaub - litb Dec 09 '08 at 02:27
  • Added definition, if you don't like you can remove it. – mmcdole Dec 09 '08 at 02:39
  • 1
    At least in TCL there doesn't seem to be any difference – jk. Dec 07 '09 at 13:50
  • @JohannesSchaub-litb: this is a must-asking/excelent question. I was just on the verge of posting it if not finding it was asked before. It only shows how much we do things in life without paying attention to the slightest details around. – Veverke Mar 31 '15 at 14:12

6 Answers6

65

There is an interesting answer on the french wikipedia article for Reflection (here)

Reflection can be decomposed in two parts:

  • introspection: a program can examine itself.
  • intercession: a program can modify its state/meaning.

So reflection is a 'stronger' property than introspection. That's why you say type introspection for the ability to know types at runtime (and changing them is another action: conversion/casting).

EDIT: actually I just realized the first answer was saying exactly that ^^. Time to unplug myself...

G-Nugget
  • 8,666
  • 1
  • 24
  • 31
Piotr Lesnicki
  • 9,442
  • 2
  • 28
  • 26
  • 2
    Reading the French Wikipedia article, I realized that in French, the term "reflection" may be more closely associated than in English with the idea of "reflexivity" -- of something operating on itself. This seems to be the right way to understand the term as it applies to programming languages. – Jan Hettich Dec 25 '10 at 04:46
  • I still can't see how does this answer the question: indeed, wikipedia helps out in differentiating type introspection in that it "satisfies" itself with only getting information, without changing it (although again, how is this exactly relevant... how many times we use reflection to instantiate types on the go - and so, where did change happen here? we did not have the newly created object in the first place, no other change happened unless you consider "coming into existence" a change, although the change was not on the inspected subject itself (would not make much sense either). – Veverke Mar 31 '15 at 14:21
  • So reflection is a "process" that comprises more steps than "introspection". Where is the compelling argument in favor of reflection, yet ?! Introspection as a word goes hand in hand with what the term represents in a programming context - whereas "reflection" - in which way is the act of reflecting an instruction/type closer to "modifying" than "introspection" is ? – Veverke Mar 31 '15 at 14:25
27

Reflection comes from the idea of "self-examination, self-modification, and self-replication", reflecting on one's self for the purpose of change. In programming you use reflection to examine the structure of the program itself in the context of using it instead of just examining it. What you get back is a representation of the program that you can use to modify it, rather than the data on which it operates.

More information can be found at the wikipedia article..

Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
tvanfosson
  • 524,688
  • 99
  • 697
  • 795
  • You didn't answer his question at all. Introspection: A looking inward; specifically, the act or process of self-examination. – mmcdole Dec 09 '08 at 02:33
  • @Simucal, sorry I wasn't more clear. I've edited the answer to specify that it is examination with the intent of action. – tvanfosson Dec 09 '08 at 02:39
  • He did. He's stating that the term reflection is used according to the program's ability to reflect upon changes by modifying itself. – Filip Dupanović Dec 09 '08 at 02:40
  • 1
    @kRON, my initial answer wasn't as specific. – tvanfosson Dec 09 '08 at 02:43
  • I still can't see how does this answer the question: indeed, wikipedia helps out in differentiating type introspection in that it "satisfies" itself with only getting information, without changing it (although again, how is this exactly relevant... how many times we use reflection to instantiate types on the go - and so, where did change happen here? we did not have the newly created object in the first place, no other change happened unless you consider "coming into existence" a change, although the change was not on the inspected subject itself (would not make much sense either). – Veverke Mar 31 '15 at 14:19
5

The term reflection comes from Brian Cantwell Smith's 1982 PHD dissertation which can be found at http://publications.csail.mit.edu/lcs/pubs/pdf/MIT-LCS-TR-272.pdf

What has come to be called reflection is often merely introspection, i.e., access to metadata. Smith's requirements for reflection included a causal connection from metadata back, and this is usually the missing component. One way to imagine reflection is access to implementation, and not merely the implementation of some new instance of a computation, but a computation's access to it's own implementation. Certainly Java's original reflection api was misnamed as it was not reflective in this sense.

Ed Puckett
  • 51
  • 1
  • 1
4

There is another concept called type introspection that refers to the ability to determine the type of an object at runtime.

edit: I realize your question was intended to be language-agnostic, but in Java, reflection is used to identify what members an object has, whereas introspection allows you to identify which JavaBeans properties an object has, which is why the introspection class is in the java.beans package. I'm not sure what the exact difference between the terms would be in other languages, though,

dancavallaro
  • 13,109
  • 8
  • 37
  • 33
1

In .Net I think the term Reflection is very appropriate because it is not the type itself that is examined, it is the manifest of the code, which is only a description.

Guge
  • 4,569
  • 4
  • 35
  • 47
1

Reflection, in the sense of definitions 3 and 4, can be introspective. That is, introspection is reflection on one's self. I think that introspection is the better word to use for the act of code analyzing itself because the word is more specific, but I don't think reflection is entirely inappropriate.

Greg Graham
  • 484
  • 4
  • 11