News for hackers. Stuff that matters.
Re:Do you know Ruby’s ‘Chainsaw’ method? by jfager on Wednesday October 06, 2010 @10:44PM (#1766666)
When I work with Java or C#, I accept this kind of code duplication as a fact of life.

Java has had dynamic proxies since 1.4. As long as you're working with interfaces, you can do the exact same thing as the example given in this post.

Re:Do you know Ruby’s ‘Chainsaw’ method? by city41 on Wednesday October 06, 2010 @11:55PM (#1766787)
And the new dynamic support in C# gives it a direct equivalent to method_missing.
Re:Do you know Ruby’s ‘Chainsaw’ method? by nusco on Thursday October 07, 2010 @06:32AM (#1767399)
From the OP: I used dynamic proxies in both Java and C#. For example, I wrote the annotations introspector for Hibernate Annotations, and a memcached wrapper for a C# project. Both are proxy-based.

However, using dynamic proxies in Java feels like going against the grain of the language: strong typing and dynamic calls don't really like each other. As a result, you usually resort to Java/C# dynamic proxies only when you have no other option. I've yet to see anyone using a dynamic proxy just to remove duplication in a Java class.

C# dynamics might make dynamic proxies less clumsy in that language. Will try. Do you have experience with them already?

Re:Do you know Ruby’s ‘Chainsaw’ method? by jfager on Thursday October 07, 2010 @06:54AM (#1767428)
I haven't seen them used much in any of the open source Java projects I'm familiar with, I agree. We used them fairly extensively at my previous job, though, for implementing a mix-in pattern for boilerplate-free service endpoints, and they worked nicely. Outside of that, I use them al the time during development to add quick-and-dirty method call tracing when I'm trying to debug something.

I personally think that they're very much underused, and having based an interview question on them for a while, not well-known at all.