As the number of concurrency that the service needs to support is getting higher and higher, technologies such as asynchronous I/O, coroutines, and async/await are being used increasingly. While these techniques can increase the amount of concurrency supported by a service, they aren't particularly easy to understand. In this article, I'll share my own understanding of these technologies, hoping to aid your understanding.
In my previous article, I discussed my understanding of programming languages in general. In this article, I will concentrate on explaining object-oriented programming (OOP) and functional programming (FP) as I understand them.
To summarize briefly: OOP is used to express ideas about universal objects, whereas functional programming primarily focuses on specific types of objects.
There are many debates about the good and bad aspects of programming languages, and I will present my own viewpoints in this blog. I will also explain the keys to learning a programming language, and my understanding of design patterns.
In this tutorial, I'll go through the process of building a telegram bot in Rust, hosted in Azure Function. As an example, we build a bot to randomly pick a line from the message to help you, for example, decide what to eat for dinner.
WARNING: This may be a bad practice. The point of this article is just to share my idea.
Exception is a popular feature in many programming languages. Unlike Rust where errors are considered as a return value of the
Err case of
Result, in these languages errors are thrown like
panic. The caller may catch the errors and process them similar to
catch_unwind in Rust. Different people may have different preferences on the error handling style, but panic-unwind is always considered a bad practice and should be avoided if possible. So using exception-like error handling in Rust is impossible.
Well, it is possible with async Rust, but we need a little trick. The main idea here is to stop polling the future after an exception is thrown.
I love the traits in Rust language. Rust uses one mechanism for both compile-time polymorphism and runtime polymorphism, which is elegant. However, the runtime polymorphism in Rust is not very flexible. Some traits cannot be used as a trait object, and it's impossible to specify whether a method is resolved dynamically or statically. This shortage is reflected in my recursive function library RecurFn, and I develop a workaround, calling it customized trait object.