6 ms·
Author here, thank you for having this project on the front page! I want to explain why this bot is in C, while, for instance, another project of mine that impl
by antirez 3y ago
Author here, thank you for having this project on the front page! I want to explain why this bot is in C, while, for instance, another project of mine that implements a LoRa driver/protocol for the ESP32 (a much lower level project, in theory) is in Python!
This code started as the Telegram bot Stonky, it's on Github, and you'll see the bot does a lot of financial analysis things, including Montecarlo simulations. I really needed the speed. Later my daughter was diagnosed with scoliosis, and requires to wear a corset. To take track of the time she wears it was a pita, so I wrote another bot (not released so far) and put it in our family channel.
Then... I needed another bot. And I finally extracted the common parts from the two. So:
1. For Stonky, speed was essential, but not for my next bot.
2. Once I needed to write the new bot for the corset I tried the Python lib. And... I started to have the first code compatibility issues (accross versions) of the modern software stack (context here: https://twitter.com/antirez/status/1726305869032570992 https://twitter.com/antirez/status/1726305869032570992).
3. Meanwhile Stocky was no longer able to work because I did the unescapable error of basing it on the Yahoo Finance API, now retired :( So I told myself, I don't want to relay on a software stack that will make this bot unable to work or obsolete in 2/3 years because all the libraries will change fast (and, if you check, you will see there was a lot of work that went into Stonky back in the couple of weeks when I worked at it constantly).
On top of that, with Stonky I decided to serve each request with a thread, and not in multiplexing. In the specific case of a Telegram bot this is basically able to simplify many things: many bot requests are long living, because you want to call an LLM API, or Whisper to transcribe, or do a Montecarlo simulation on a stock history, (btw the Whisper thing will be one of the official examples of this library) and so forth. Now in Stonky this approach worked so well because it's written in C, so each thread consumes only minimaul resources associated with the OS thread creation.
Finally: With SDS lib, my JSON and Sqlite3 wrapper (the wrappers are the interesting part of the project IMHO) it is not so different than writing Python code. So, I said, why not?
P.S. this library is just a work in progress, hacked while I'm doing many other stuff. I hope it will improve in the next weeks. I use Telegram for more than 10 years now, with all my friends and family. So it is very likely I'll require to write more bots in the future :D
- jay-barronville 3y agoUnrelated: I just want to say thank you for all of your amazing work over the years. You’re a software hero of mine. I’m 100% certain your code and work has saved me time, money, and maybe even my job at one point! Also, sorry to hear about your daughter. I’m going to pray for you and your family! (If my memory serves me right, you don’t believe in God, but I hope you don’t mind.)
- antirez 3y agoThank you Jay! It's a great thing to read in the morning :) Appreciated. I don't believe in God, but in a very "soft" way, that is, I'm happy other people enjoy their religious life.
- 59nadir 3y ago[flagged]
- antirez 3y agoThe Thompson story is very telling about C and how semantically powerful it is. KT tried to rewrite UNIX in B at some time, but he failed. Assembly allows you to do many interesting things because it is a low level language, and yet you can build abstractions, so it was a better language than B to write UNIX. But once B got structures, and was starting to become C, things changed. Structures with fields and pointers to other structures is the ha-ha moment of C. It is what really makes the whole language so special. With this simple building block you can start building abstractions that are able to abstract away low level details, while, at the same time, you have full control on low level details.
- rollcat 3y agoDo you see any features in modern, high-level programming languages (such as Python, Go, C#) that could guide the next evolutionary step for C, without sacrificing that low-level control? Knowing KT worked on Go, I'd guess he'd say concurrency, but that's difficult to get right without sacrificing low-level control. What's your take?