r/visualbasic • • Sep 23 '24

Most used version of .Net Framework

Hi, I have a question for all the vb.net devs, which version(s) of .net do you typically or most frequently target for your apps and why? Personally I'm typically using .Net 4.0 for most projects. I've been noticing that the more recent versions just give some syntactic sugar. I don't see anything noteworthy beyond that.

3 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/Ok_Society4599 Sep 26 '24

Yes, I know the differences. I've programmed IDispatch consumers and providers in several programming languages.

It is NOT rare in VB6 at all. Pretty much ALL COM calls off Object references use IDispatch. ActiveX. Office Documents. ADO. The list goes on. Devs used Object and get an IDispatch rather than proper interface -- I said they abuse "object.". it saves referencing COM objects in the project and hides dependencies until runtime. VB6 used "guessing" to invoke dispatch methods and hides a bunch of type conversions and marshalling. At the time, computers were sufficiently fast, users weren't considering anything as "inefficient" if it ran. And most of those untrained devs didn't think about maintainable code at all. These were the days of "spaghetti code."

.NET simply does support IDispatch like VB6 so it pushes devs to use interfaces more. I've written to use IDispatch in .NET to access some "stuff" that wasn't easily available otherwise, so I know it can be done. I would not advise doing it if it can be avoided. Mostly, it seemed code was added to IDispatch without hitting the object's actual interface, possibly an oversight, possibly just more lazy.

VB6 late binding should be rare, or a lot less than I've found. It's mostly lazy programming, in my experience. People write hundreds of lines in a single sub because they don't know it's easier not to. People neglect to add references and use interfaces because it's less work ... and they call me because something broke, or it won't run on a new PC, or whatever.

And most of those "not part of the language" methods should be simple imports from the system DLL with a light-weight wrapper to handle marshaling and OS level errors.

We agree: late binding is a code smell. It's a problem trying to convert VB6 to .NET using most of the tools I've tried. I contend VB6 made it too easy to late bind rather than strongly encourage early binding strategies. I'd even suggest that's why IDispatch is very hard to use in .NET

Fortunately, most of my VB6 lately is conversion, not debugging and fixing.

1

u/Mayayana Sep 26 '24

It is NOT rare in VB6 at all. Pretty much ALL COM calls off Object references use IDispatch. ActiveX. Office Documents. ADO.

That's where it gets mixed up. I'm guessing the people you know are the ones using VBA in MSO. The average VB programmer is not calling into MSO or ADO. Those are scripting objects.

1

u/Ok_Society4599 Sep 26 '24

Um, yes, that was the "intent." Microsoft has a lot of smart devs that never imagined how badly VB6 would stray from good programming style, let alone best practices. I'm sure they never thought 75% of method invocation could be pushed through the iDispatch invocation code.

I'm currently fixing a system that abuses Object frequently. Almost all of the VB code I've ever been asked to work on does. So, I don't know where you're finding your "average programmer" but it's nowhere near my sample :-) and many of these projects were dropped by their developers - another code smell for unsustainable code.

In my VB code, I like to avoid Object whenever possible. It just makes life so much saner ;-). And no, I rarely do any office scripting or macros outside of some light Excel. Straight up VB6 projects.