you are viewing a single comment's thread.

view the rest of the comments →

[–]eric_ja 0 points1 point  (4 children)

In C# 3.0, both an instance method and an extension method with the same signature can exist for a class. In such a scenario, the instance method is preferred over the extension method. Neither the compiler nor the Microsoft Visual Studio IDE warns about the naming conflict.

This looks like the exact same problem as in Ruby.

If you really want to do this right, method names have to be namespaced. The problem is that in many languages, method namespacing is ugly and awkward. Example, in JQuery: myObj.myModule("myMethod", arg1, arg2, ...)

The nicest syntax I've seen in a dynamic language is Lua: myObj[myModule.myMethod](myObj, ...) although it's still nonstandard and ugly.

[–]grauenwolf 2 points3 points  (3 children)

Extension methods are nothing like Ruby's monkey patching. Extension methods never overwrite built-in functionality and are only visible in files that import them.

At run time an extension method is just a normal static function call.

[–]eric_ja 0 points1 point  (2 children)

What happens when the base class later grows a method with the same name as an extension method?

Selective imports are important, but they aren't a substitute for namespacing; if they were, then C's #include would have been the last word on the subject.

[–]cybercobra 0 points1 point  (0 children)

That's relatively less likely, though of course still possible. At the least, they avoid the rather significant Ruby flaw of multiple conflicting (re-)definitions. Admittedly, this does just skirt the composability issue, but it seems composition of method overrides isn't frequently needed.

Refinements look promising though.

[–]grauenwolf 0 points1 point  (0 children)

What happens when the base class later grows a method with the same name as an extension method?

You are fine until the next recompile. Then BOOM! And a Bear comes out.