baderouaich / tgbotxx

Telegram Bot C++ Library
https://baderouaich.github.io/tgbotxx/
MIT License
11 stars 0 forks source link

Looking good, but maybe remove inheritance? #1

Closed ignacionr closed 1 year ago

ignacionr commented 1 year ago

Hey, how are you! I am shopping for a Telegram Bot C++ library, and yours seems great. I've only looked at it for a few minutes and I see mostly what I like to see. Most importantly, only a few dependencies, and reasonable ones (cpr, nlohmann::json). What I don't see myself doing, is inheritance... It's been a long time since I left that style of programming. I mean, with templates and/or callables, you can achieve the same with a lot more flexibility and even getting a plus of performance and general stability by not resorting to vtables.

Your valuable opinion will be appreciated.

baderouaich commented 1 year ago

Hi @ignacionr,

I am good thank you! how about you ?

First, thank you for your interest in this project! although its still on beta and not 100% complete, you can still make decent bots (which don't use the inline mode as its not implemented yet).

I understand your concern about the inheritance-based extensibility technique used here and actually you are right, there is no strong reason behind it except few ones of my own:

// Run all bots simultaneously for (Bot* bot : bots) { std::thread([&]{ bot->start(); }).detach(); } ...



- **Uniqueness**: There are many Telegram bot C++ libraries out there such as [tgbot-cpp](https://github.com/reo7sp/tgbot-cpp), [tgbot](https://github.com/egorpugin/tgbot) ... I want to give this one some sort of uniqueness on how it's used.

Regarding performance, I agree that the use of inheritance is unlikely to significantly impact clock cycles. This library listens for updates from Telegram server and as soon as there are new updates, it dispatches them to the relevant callbacks. Whether we use inheritance with overridden methods or std::function callbacks, the difference in performance is negligible.

However, I remain open to new ideas and alternative techniques. If you have any suggestions or recommendations, please don't hesitate to share them with me.

Once again, thank you for your interest, and I wish you a good rest of day!
ignacionr commented 1 year ago

Such a lovely answer, thank you. Yes I do appreciate your work!

The problem with inheritance is... inheritance. So I totally see someone creating a lineage of bots, then you change some little thing and the whole lineage is broken.

Of course, this will mean that good programmers will create their own adapters and keep independence from your implementations.

So I guess what I am saying is be aware that you're making it easy for bad programmers to make big messes.

Take care and keep up the good work!