twinbasic / lang-design

Language Design for twinBASIC
MIT License
11 stars 1 forks source link

Ability to change referenced library namespace identifier #22

Open WaynePhillipsEA opened 3 years ago

WaynePhillipsEA commented 3 years ago

Is your feature request related to a problem? Please describe. At the moment, you cannot reference two type libraries that have the same namespace identifier. This is sometimes needed, for example if you are writing a VBE addin and want to support both VBA and VB6 hosts, then you really need to reference both the 'Visual Basic 6.0 extensibility' type library, and also the 'Visual Basic for Applications extensibility' typelibrary, however they both use the same namespace identifier of 'VBIDE', causing a conflict if both are referenced from the same project.

Describe the solution you'd like I'd like to be able to change the namespace identifier of any referenced typelibrary, so that we can avoid conflicts when necessary.

Describe alternatives you've considered Using late-bound code throughout, but this is less than ideal.

Additional context I've just added another sample project for showing how to create a VBE addin using twinBASIC: https://www.twinbasic.com/preview.html#sample4

The sample does work for both VBA and VB6 IDEs, but only because I've late bound the objects.

bclothier commented 3 years ago

FWIW, I quite like how C# handles this problem.

// Import the library's namespace "MyFoo"
using MyLibrary.MyFoo;
// Imports another library's namespace "MyFoo" and alias as "NotMyFoo"
using NotMyFoo = OtherGuys.MyFoo;
// Imports a type defined in another library and alias it as "Foo"
using Foo = OtherGuys.MyFoo.Foo;

I'd actually prefer having the equivalent on a per-file level rather than per-project level as that would help a lot with keeping the intellisense manageable. For the project level, this can be provided as a text file, rather than as a GUI control. That is more SCC-friendly but not so convenient for hand-editing since I assume we need to provide either the type library's GUID or the path to the type library.

WaynePhillipsEA commented 3 years ago

@bclothier I'm not a fan of per-file using/aliases in BASIC. Don't get me wrong; it works great in some languages, and it does certainly cleanup the intellisense. But for me, part of the charm of classic BASIC is that you just set a reference to a library and that's it. Most of the time.

I wasn't really planning on making this overly complicated. I was more thinking along the lines of allowing the developer to change the library 'namespace' identifier alongside the project references list.

Just FWIW, the project settings file is just a JSON file (you can right click on it and open as a text file in VS code), so is already largely SCC-friendly, apart from the hard-coded paths to the references (similar to what VBA does, which admittedly needs looking at).

But I don't want to be a dictator... so I'm certainly open to opinions on this.

Kr00l commented 3 years ago

My opinion is also that just an alias to be defined in the references list is sufficient, that's it. (IMO) This way it keeps simple and not starts to be "over engineered". (in my sense)

mansellan commented 3 years ago

I just realised there wasn't yet a discussion on namespaces, so I added twinbasic/lang-design#21. It's a thorny subject to be sure. For this particular issue though, I don't think it's necessary to solve - a simple means to alter the name of the imported library space should be all that's needed here?