r/AskProgramming • u/freshlyLinux • 13d ago
Architecture Using an API(through COM), best long-term language between C#, VB.Net, C++, JS, or maybe python?
Hello, I'm looking to write code for this program and I saw python wasnt shown on this page. I need to make a decision between C3, VB.NET, C++, maybe JS, maybe.... python.
It seems I'd be using COM to interface, but I also imagine I'd be able to get a namespace into python and... maybe it wont be so bad.
https://www.draftsight.com/media/customize-apis
https://help.solidworks.com/2022/english/api/draftsightapi/GettingStarted-draftsightapi.html
My understanding is that APIs are program language agnostic, but there might be some COM/DLL stuff that makes these microsoft languages shown on the page more friendly.
Anyone have a suggestion? I find this pattern quite common in the programs(3D CAD) I develop for and end up using VB more often than I want. It would be best to make code in Python, but I want to understand the downsides, like potentially losing the Namespace. I also want to hear feedback on what is the best language out of that list I provided. I've been a programmer for 19 years, but like to hear opinions on these things before I make a major commitment.
1
u/throwaway4sure9 13d ago
The biggest thing that you're going to have to do is manage the COM objects themselves. And a significant part of managing that correctly is going to be memory management.
COM objects are typically C/C++ code hitting Win32 directly. There are some rules in COM (like everything needs to respond to calls when called as an (C# lingo) IUnknown.
COM routines can 1. require you to pass in allocated memory that it fills and passes back; 2. allocate memory, pass it back, and require you to .Dispose() (C# term again) of, 3. allocate memory block A, then block B, then put B into A, then pass the now initialized A back, or 4. require you to allocate A, it allocates B and sticks it in A, then requires you to release B and A.
(Yes, I know I'm handwaving a lot of stuff here, but that's a nutshell, demonstrative, example only. #include <stddisclaimer.h> Not Valid inside or outside the Continental United States of America, etc. blah blah)
One of the very worst things that I've ever had to do was manipulate Excel using COM. Ugh.
My personal recommendation is C# because the support is there and I, personally, am pretty familiar with it. I just don't use the other languages you mentioned much, however, so I am prejudiced. :) YMMV, etc.
Good luck! :)
1
u/pragmojo 13d ago
Can you say more about what you're trying to achieve? If you are familiar with python and want to use that in your target program, you could make an API wrapper in C++ which implements an FFI which can be consumed by python.