Panopticon Central

a blog on Visual Basic, .NET and other stuff

  Home :: Contact :: Syndication  :: Login
  504 Posts :: 19 Stories :: 3894 Comments :: 659 Trackbacks

News

The information in this weblog is provided "AS IS" with no warranties, and confers no rights.

My Book

Picture

My Recent Posts

Article Categories

Archives

Post Categories

Microsoft Blogs

Samples

Technical Blogs

VB Links

I’m clearing out some old mail and I came across a reference to a blog entry by Jon Skeet about extension methods that I saved a while back. He says:

One of the things I don't like about the proposed extension methods is the way the compiler is made aware of them - on a namespace basis. "Using" directives are very common to add for any namespace used in a class, and quite often I wouldn't want the extension methods within that namespace to be applied. I propose using using static System.Query.Sequence; instead, in a way that is analogous to the static imports of Java 1.5 (except without importing single members or requiring the ".*" part. This would make it clearer what you were actually trying to do.

The interesting thing is, if you look at the document that we released on LINQ at the PDC, you’ll see that our design for extension methods incorporates this suggestion: extension methods in VB are brought into scope by directly importing the containing type, not the namespace. Imports System.Query isn’t sufficient to get LINQ methods in scope; you have to say Imports System.Query.Sequence. I agree with Jon that it’s clearer to do it this way, but that’s not the whole reason we did it. You see, the real problem is late binding.

Yes, late binding. We still support that, you know? And if you think for a minute about late binding and extension methods the way C# does them, you’ll quickly see that the two things don’t go together very well. When we go to late bind a member “foo” on an instance of a type “bar” today things are relatively simple — we gather all the members of “bar” with the name “foo” and then apply our regular binding rules to determine which, if any, of them fit the bill. All we need to know at run-time is the type of the instance we’re late binding on. With extension methods, though, this breaks down. Now we need to know not just the type of the instance, but also all of the extension methods in scope at the point of invocation. That’s because if “bar” doesn’t have a member “foo,” then in the early-bound case the compiler is going to go looking for extensions method. And the late-binder needs to do this, too!

If you look at how C# does extension methods, they go out and start looking in all the enclosing namespaces for extension methods, then look in all the imported namespaces for extension methods, etc. Replicating this at run-time would be difficult, at best — at every late-bound invocation point you would have to capture the complete binding context. And this binding context would change from method to method. What a nightmare! Our design is more friendly to late-binding. Our current design says that if “bar” doesn’t have a member “foo,” then we’ll look only at types whose members have been imported for extension methods. This collapses down the search space hugely and also means that the binding context is per-file (since we only allow file-level imports, unlike C#). While still a bit bulky, this seems much more manageable. Although we’ll see — although we’ve implemented early-bound extension methods, we haven’t gotten to the late bound stuff yet. <g>

Although we felt we had to do extension methods this way because of late-binding, we also believe there are some other advantages to the scheme. Jon lists one: it becomes much easier to be clear about the extensions you are using. You won’t import some useful namespace and then, whoops!, you just added a whole bunch of extension methods that you didn’t want. It’s also fairly congruent with the fact that VB (again, unlike C#) allows you to import a type directly, allowing access to its shared members without qualification.

Of course, now that I think of it, I’m not sure how this works with standard modules and their special binding rules. Hmmmm. I’m going to have to look at that…

posted on Tuesday, November 22, 2005 12:05 PM

Feedback

# re: Extension methods + late binding = trouble? 12/2/2005 6:41 PM Kyralessa
On the other hand, you could make things a lot easier for everybody by just getting rid of late-binding. :) I'm inclined to think that Late Binding plus _anything_ equals trouble.

# Here best software for PC and MAC - Enjoy ! 10/6/2008 5:42 PM FiestaBoy
<b>You can get professional software for you work !
Fast shipping and FTP download !
Online support 24hours in 7 days</b>

<a href=http://www.prowarezshop.com>http://www.hdwarez.org</a>
<b>E-mail </b> order@hdwarez.org
<b>ICQ</b> 949092

Last software suits on our site:
SACS 5.2
Scania 5.21 - 9.2005
Setra Evobus - 2001
DAF Rapido 2006 all models -2.2006
Volvo Impact 2006 - 1.2006
Mitsubiski Truck
DASSAULT SYSTEMES ENOVIA LCA V5R17
Gerber Tech Accumark Ver 8.3
Schlumberger PETREL 2007
TRICALC V6.4
PFAFF 4D EMBROIDERY PROFESSIONAL
Gerber Omega Composer 2.6
HTRI Xchanger Suite v4.0
Bentley HVAC 08.00.07.03
ELITE SOFTWARE Chvac v7.01.45
HVAC CARRIER E20-II SW
Carmel Design-Build 6.0
HVAC Solution Pro 4.1
QwickLoad W-500
ComfortAir HVAC Software 3.3
Elite Ventilation Tool
Elite Heavent
Centrix Fan software Version 3.5
AGILE Software FANPAL
DIAMINO FASHION V5R2C5
Wasatch Softrip 6.3
Carlson Takeoff 2009
DAT/EM SUMMIT EVOLUTION 4.3
Socet set 5.4.1
Chief Architect X1 Enterprise Bundle V11.5.4.17
Adobe Acrobat Connect Pro V7
Gemcom Minex 5.2.2
Gemcom Minex 5.2.3
Udec Itasca 4.00.153
REBARCAD V9
Muller MUCAD V3.6
Ergosoft text print 12.0.6
Dpinnovation Dr.wirth Ripmaster Pro
Inedit neoStampa 6.1
Inedit neoProfiler 1.0
Monaco Profiler Platinum 4.8.3
Microsoft Small Business Financials North America Edition
Microsoft Dynamics GP 10
Wilcom Sirius ES-65 V11
Great Notions 2005
Corel Drawings2
NaviFlash v1.00.16
DYNALOG V2.3.31
CAD-Schroer Medusa 4 v2
Think3 ThinkID DesignXpressions v2005.2
OpenMind HyperMILL V9.0 incl SP4 HF 29087
Compucon EOS Ver 3.01
Barudan TES Ver. 3.0
Tajima DG/ML by Pulse Edition "Xi" Ver 11.0.5. 2633(Maestro)
Pad System Ver. 4.5
Melco EDS Design Shop 2005 V6.0
Sierra Embroidery Office Suite Ver. 7.50


# gay shorties 10/30/2008 10:38 AM stories

gay <a href="http://www.virtualroom.co.uk/moodle/user/view.php?id=205&course=1 ">amateur video gay</a> gay <a href="http://www.viisaankivi.fi/moodle/user/view.php?id=978&course=1 ">amr gay thumbnail gallery</a> gay <a href="http://www.vasciaveo.com/el/user/view.php?id=6&course=1 ">gay tube</a> gay <a href="http://www.mauxsalamanca.es/user/view.php?id=751&course=1 ">ambiguously gay duo</a> gay <a href="http://www.mbhci.net/user/view.php?id=256&course=1 ">amature gay</a> gay <a href="http://www.mcartaya.net/campus/user/view.php?id=1

# derfe er er er 11/5/2008 4:53 AM wddedase
<a href=http://trahhun.io.ua>?????</a>
<a href=http://hahuner.io.ua>??????</a>
<a href=http://xxl-and.io.ua>????? ?????</a>
<a href=http://ebazzo.io.ua>????? ?????</a>
<a href=http://fakkerun.io.ua>????? ?????</a>
<a href=http://minetik.io.ua>?????</a>
<a href=http://sosikaher.io.ua>????? ???</a>
<a href=http://deraswer.io.ua>?????</a>
<a href=http://nikasss.io.ua>????</a>
<a href=http://hulihuli.io.ua>???</a>


Post Feedback

Title:
Name:
Url:
Comments: