Performance of application-defined functions and collations in SQLite

When writing the post on Unicode case-insensitive search in SQLite I got interested in the performance of application-defined functions and collations: they must introduce overhead, the question is how much and whether it is something to be concerned about. To answer these questions I made a simple test suite measuring the performance of both built-in SQLite and application-defined functions and collations – the full code is at the very end of the post....

2022-01-26 · 10 min

5 ways to implement case-insensitive search in SQLite with full Unicode support

Recently I needed a case-insensitive search in SQLite to check if an item with the same name already exists in one of my projects – listOK. At first, it looked like a simple task, but upon deeper dive, it turned out to be easy, but not simple at all, with many twists and turns. Built-in SQLite capabilities and their drawbacks In SQLite you can get a case-insensitive search in three ways:...

2022-01-10 · 13 min

End-to-end tests for Telegram bots

I think there is no need to say that automatic testing is a must in software development. Tests improve the quality of the code, give confidence in it and make it more stable. However, not all tests are created equal: they differ both in what they test and how hard it is to set them up and maintain. For instance, it is relatively easy to write unit tests. In turn, they tell you very little about how your system will behave in production....

2021-12-13 · 12 min

Using Python decorators to process and authorize requests

When building any system that interacts with users you always need to check that they are who they are claiming to be and whether they are allowed to do what they are trying to do. In other words, you need to authenticate and authorize users. Chatbots are no exception. Strictly speaking, with chatbots you do not need to authenticate users yourself – the platform does it for you. However, on each request you still have to load the user model and authorize it....

2021-12-06 · 5 min

Are python comprehensions faster than loops, why, and does it matter?

Python comprehensions are believed to be faster for generating collections than for loops. The question is why are they faster? What part of a comprehension is faster than in the loop? Below we answer this question and whether their faster performance is something worth considering. This will be more of an exploratory exercise, where the journey and methodology are more interesting than the destination. If you need only the conclusions, you can jump there....

2021-11-15 · 8 min

Python comprehensions breakdown

Comprehensions are a quick and easy way to generate sequences (collections) of any kind in Python. In simple cases, they should be easy to write and, more importantly, read. However, when I was making my first steps in Python I tried to avoid comprehensions as much as possible: most of them looked convoluted and not easy at all. Better stick to good old for loop. In time my attitude changed, of course, I just needed to dive deeper to understand syntax and use cases for applying comprehensions....

2021-11-01 · 11 min

defaultdict: a hidden gem of Python standard library

Often you need to store data (counters, sums, lists, etc.) about some entities. A regular Python dictionary will suffice with one caveat: before adding information regarding a particular entity you need to check if the corresponding key exists in the dictionary, otherwise you will get a KeyError. Do not know about you, but I have written similar code many times: dct = {} if key not in dct: dct['key'] = 0 dct['key'] += 1 A better way While it is perfectly workable, it does not add to readability....

2021-10-25 · 2 min