• Post Reply Bookmark Topic Watch Topic
  • New Topic

expected reflective capablities from a language  RSS feed

 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Authors,

It would be great if you could list the kind of reflective capabilities one should expect from a language.
I mean if i look at java it allows me to inspect fields, methods etc of a class at runtime. Now that we are doing byte code generation, a language should also allow me to change the implementation of a class at runtime.
Could you please expand on this list? Also as a side note please also indicate if that feature is present/absent in java.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If by changing the class implementation at runtime you mean to change the bytecode after the class was loaded this is not possible. You will have to discard the class (by discarding the corresponding classloader). You can modify the bytecode before the class loading into the JVM.

--
./pope
[the_mindstorm]

ps: i am not the author, so if the answer is not good just ignore it.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ali.

I realize that it is not possible in java unless we discard the class and hence the loader that loaded it in the first place. But I have seen python code snippets whereby methods could be bound to a class at runtime using straight forward syntax. Hence my question to the authors/ anyone for that matter as to what reflection features can we expect from a language?
Or in other words, what are those languages that allow you to do lot more with reflection than java does.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found very interesting info about python introspection here.

--
./pope
[the_mindstorm]
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ali Pope:
I have found very interesting info about python introspection ./pope
[the_mindstorm]


Yeah things like dynamic proxies is such a big thing in java and seems so easy in python.
 
Nate Forman
author
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karthik,

I like to think of using reflection as making your program act like a programmer. You also examine inspect fields and methods, only while your're programming. Reflection just allows the program to do these things while its running.

That means that the full potential of reflection allows the program to do things, while its running, that you would do while writing it. During development, you extend classes, add and override methods and fields, implement interfaces, change method implementations, etc. In the limit, reflection could allow you to make your program do all of these things.

Best Regards,

Nate
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nate Forman:
I like to think of using reflection as making your program act like a programmer. You also examine inspect fields and methods, only while your're programming. Reflection just allows the program to do these things while its running.


Nate,
I am also thinking all the time like that...

"reflection as making your program act like a programmer"

Of course there are some limitation that reflection cannot do, while human programmer can do manually... Could you give us some examples of this issue? Thanks...
 
Nate Forman
author
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I totally agree, Ko Ko.

This is one of the things I came up against in my masters report (http://home.austin.rr.com/forman/ira/msthesis.pdf) about implementing patterns using metaclasses. Programming with reflection will always be limited by the metadata available to the program. There are some decisions that you just can't make without access to specifications, subject matter experts, etc. Also decisions that have to do with intent and overall design. If that metadata is made available, the level above that will be the one missing, and so on. These are decisions that need to be made by humans. But even these can be aided by the use of a little reflection

Best Regards,

Nate
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if the possibilities opened by reflection are great (take as example Python), I feel that writting code in this manner will finally be - in a way - error prone.

--
./pope
[the_mindstorm]
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection code is, of course, error-prone. However, that only strives to demonstrate the value of good testing. Reflection is going to push a lot of errors off until run-time. But most, if not all, of these error are ones that should be caught during the unit/system testing cycles--they should never even make it to user testing! And they are really no harder to debug -- just make sure that you are handling the stack trace for the source of the InvocationTargetException, and then it's really no different from other debugging (and integrated debugging is no different...)
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I absolutely agree with you. Moreover, with the newadays ide-s even the refactorings which are influencing reflective code are easy.

--
./pope
[the_mindstorm]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!