Friday, June 3, 2011

Virtual Functions

As a combat veteran very experienced professional software developer (server admin, network admin, change management nazi, DBA, architect, glorified typist, coffee lackey, punching bag, and whatever else needs to be done), the overwhelming majority of my career has been built using Microsoft stuff, most notably .NET. The main reason I (and others) have such a hard-on for .NET (or its archetype Java) is the managed runtime. To put it simply - no goofy "pointer arithmetic" for us humans to screw up! But, after all these years of building things inside the warm, loving safety of .NET's fertile womb, I've found myself sneaking closer and closer to the edge,  yearning to get right next to the metal. That's how I ended up finding the article for which this post was created:


Until now, I had never really spent any time mulling over questions like "I wonder whether the implementation of a virtual function gets resolved at compile-time or at run-time?" or "I wonder if there is another human on this planet that gives a shit, much less wants to read a blog post about it?". But hey - today's a new day, and I decided to throw caution to the wind and run with it!

But seriously, that "part 12.5 out of some presumably multi-part C++ thing" up there is pretty friggin' sweet, if you ask me! (I know you didn't, so please STFU...) It explains the real, "under the hood" implementation of virtual functions in such a clear, concise, "plain-speak" manner that I left with a newly gained ability to picture it in my head, almost as a set of 3D puzzle pieces fits together. It is elegant simplicity at its finest. And you know those asshole interview questions about niche subtleties of polymorphism that nobody ever encounters in Real Life? Well, if it involves class foo overriding the virtual function of class bar, you'll never miss it again!

P.S. - I never knew that pretty much all functions in Java are virtual! Weird!?!?

No comments:

Post a Comment