Ruby and Java’s approach towards Reflection

As per http://docs.oracle.com/javase/tutorial/reflect/index.html, certain VM optimizations cannot be performed during reflection, also there are security concerns since private methods are made accessible. There are also synchronization concerns in some of the reflection apis ex: loading class is a synchronized operation. These reasons discouraged java developers from using the api unless its absolutely necessary.
 
While in ruby reflection seems to be a feature that’s used extensively, on-top of which meta-programming is made possible. ex: activerecord creates model’s attributes and their accessors on the fly.
 
While the overhead of reflection and possible erroneous scenarios in a multi-threaded environment have to be addressed, these two languages seem to have taken diametrically opposite stances on the subject.
Proudly powered by WordPress | Theme: Outfit Blog by Crimson Themes.