Forwarded from Хроники постмодерна
Entwine it.
It’s summertime, a heatwave has come to central Russia, and a thermometer on my balcony is rising higher and higher. Having awakened because of a ringing doorbell in the morning – that was a currier delivering my usual products – in my thoughts, I’ve been sunbathing in the nearest park since, though, in fact, it isn't so.
Several days ago, I started reading Andrew S. Tanenbaum's “Computer Networks”, 6th edition. Many years ago, being a student, I was reading another edition of the book (4th? 3rd?), and from the very beginning, I noticed a huge difference between editions, well, no surprise. The reason why I decided to read this book is just curiosity, I don’t want to confuse someone with a phrase like “As a software developer I have to read it”, because it wouldn’t be true.
Nevertheless, so few people talk about computer networks and related technologies even though it’s a foundation of the entire IT industry, and our (developers) salaries result from the fact that the networks exist and work better than the famous Swiss watch. When we develop another e-commerce or delivery app we stand on the shoulders of network technology giants.
#today #summer #weekend #flood #books #networks
It’s summertime, a heatwave has come to central Russia, and a thermometer on my balcony is rising higher and higher. Having awakened because of a ringing doorbell in the morning – that was a currier delivering my usual products – in my thoughts, I’ve been sunbathing in the nearest park since, though, in fact, it isn't so.
Several days ago, I started reading Andrew S. Tanenbaum's “Computer Networks”, 6th edition. Many years ago, being a student, I was reading another edition of the book (4th? 3rd?), and from the very beginning, I noticed a huge difference between editions, well, no surprise. The reason why I decided to read this book is just curiosity, I don’t want to confuse someone with a phrase like “As a software developer I have to read it”, because it wouldn’t be true.
Nevertheless, so few people talk about computer networks and related technologies even though it’s a foundation of the entire IT industry, and our (developers) salaries result from the fact that the networks exist and work better than the famous Swiss watch. When we develop another e-commerce or delivery app we stand on the shoulders of network technology giants.
#today #summer #weekend #flood #books #networks
Let's speak up!
There is a belief that software developers as well as other people from the IT world don't know how to talk with other people. Well, if you could look at the meeting schedule of a regular developer or even better at a team leader's one you would be surprised... Highly doubtedly any serious software can be developed by just one person, and supposedly a level of communication in developers' teams exceeds the same level in teams of other white collars. If you take into account a popular T-shaped skills idea and the fact that a developer team consists not only of developers but also different roles: QA engineers, DevOps, designers...I guess my idea must be clear by this point.
"Everything that they do is just writing down code according to exact task description" - is another common and wrong belief. In reality, writing an accurate task description is a pretty demanding task, and for complex problems, it's never detailed enough, so developers can't just bluntly write a code without diving into the product. Most of the real tasks are complex: everything that can be automated, copy-pasted, and so on got done a long time ago even without ChatGPT
#job #IT #General
There is a belief that software developers as well as other people from the IT world don't know how to talk with other people. Well, if you could look at the meeting schedule of a regular developer or even better at a team leader's one you would be surprised... Highly doubtedly any serious software can be developed by just one person, and supposedly a level of communication in developers' teams exceeds the same level in teams of other white collars. If you take into account a popular T-shaped skills idea and the fact that a developer team consists not only of developers but also different roles: QA engineers, DevOps, designers...I guess my idea must be clear by this point.
"Everything that they do is just writing down code according to exact task description" - is another common and wrong belief. In reality, writing an accurate task description is a pretty demanding task, and for complex problems, it's never detailed enough, so developers can't just bluntly write a code without diving into the product. Most of the real tasks are complex: everything that can be automated, copy-pasted, and so on got done a long time ago even without ChatGPT
#job #IT #General
Threads and interviews
As I mentioned above interviews in IT are weird and full of cringe. In case you're a software developer and want to get a decent income interviews are a "necessary evil", bearing in mind that many companies have several interview sections - highly likely that you'll see tens of them during several years in the industry.
Today I want to bring up memories of my interviews with a quite famous company that altered its name several times. The plot of that wasn't particularly unusual: an online meeting with HR, a test task, a C++ question section, and the final meeting with a department manager. Well, the test task part is unusual. In general, I wouldn't advise anyone to accept this part as long as it isn't paid or you're not just curious about that. I succeded in all the sections except the final one - guess they just found someone ready to get a smaller salary. I have neither negative nor positive emotions with that. Because interviews aren't covered with NDA nothing prevents me from publishing all the details: without further delay the test task description:
Below you can find a naive version of it without any synhronizaation at all, the solution along with a detailed description will be published later.
#job #C++ #interview #today #memories #c_plus_plus
As I mentioned above interviews in IT are weird and full of cringe. In case you're a software developer and want to get a decent income interviews are a "necessary evil", bearing in mind that many companies have several interview sections - highly likely that you'll see tens of them during several years in the industry.
Today I want to bring up memories of my interviews with a quite famous company that altered its name several times. The plot of that wasn't particularly unusual: an online meeting with HR, a test task, a C++ question section, and the final meeting with a department manager. Well, the test task part is unusual. In general, I wouldn't advise anyone to accept this part as long as it isn't paid or you're not just curious about that. I succeded in all the sections except the final one - guess they just found someone ready to get a smaller salary. I have neither negative nor positive emotions with that. Because interviews aren't covered with NDA nothing prevents me from publishing all the details: without further delay the test task description:
Write a console C++ program with two threads, where the first thread prints '1' and the second one prints '2', and, the most important condition, a one always precedes a two, so the output should be '12121212...', the program works endlessly. Use only the standard library (std).
Below you can find a naive version of it without any synhronizaation at all, the solution along with a detailed description will be published later.
#include <iostream>
#include <thread>
using namespace std;
int main()
{
auto firstRoutine = [](){
while (true){
cout << '1';
}
};
auto secondRoutine = [](){
while (true){
cout << '2';
}
};
thread th1{firstRoutine};
thread th2{secondRoutine};
th1.join();
th2.join();
return 0;
}
#job #C++ #interview #today #memories #c_plus_plus
The tip of the iceberg
Having mentioned earlier about technical specifications I realized that I’d like to discuss it deeper. Though at first, I’ll present a general description of how a software development team works.
I’d like to note two major points: everything is based on my personal experience, and there is no way to grasp an entire range of possible situations in great detail. Let me explain the latter: nowadays companies, developing software, vary in their sizes and spheres so that it can be a start-up with 2 software engineers, it can be a bank with a thousand employees or it can be a giant corporation consisting of one hundred thousand employees. As you might have heard software development itself falls into different specializations, though a well-known frontend/backend dichotomy is not comprehensive, for instance, it doesn’t cover the following: driver development, embedded development, Windows-based game development, and so on. Plenty of programming languages and frameworks are out of the current discussion scope because I want to focus on how processes are organized rather than coding here. Let’s also close our eyes on other roles in a team that can also accidentally write code: DevOps, QA engineers, etc. Last but not least: personality traits of a team leader as well as other team members, on one team a team leader, has read a book about Scrum and now they groom their backlog every day and have all sorts of meetings, in another place everyone has decided that Scrum is too complicated, so their team leader tries to split tasks themselves, finally in one more place a whole IT department consists of two people who work as they can without time or intention to read books about how it’d be perfect.
So, in future posts, I’ll tell you about different roles involved in software development, and how the processes can be organized, little by little, I'll come to examples of successful and unsuccessful cases from my personal experience. Finally, after all the introduction we’ll come back to the technical specifications. Stay tuned!
#job #IT #General #Introduction
Having mentioned earlier about technical specifications I realized that I’d like to discuss it deeper. Though at first, I’ll present a general description of how a software development team works.
I’d like to note two major points: everything is based on my personal experience, and there is no way to grasp an entire range of possible situations in great detail. Let me explain the latter: nowadays companies, developing software, vary in their sizes and spheres so that it can be a start-up with 2 software engineers, it can be a bank with a thousand employees or it can be a giant corporation consisting of one hundred thousand employees. As you might have heard software development itself falls into different specializations, though a well-known frontend/backend dichotomy is not comprehensive, for instance, it doesn’t cover the following: driver development, embedded development, Windows-based game development, and so on. Plenty of programming languages and frameworks are out of the current discussion scope because I want to focus on how processes are organized rather than coding here. Let’s also close our eyes on other roles in a team that can also accidentally write code: DevOps, QA engineers, etc. Last but not least: personality traits of a team leader as well as other team members, on one team a team leader, has read a book about Scrum and now they groom their backlog every day and have all sorts of meetings, in another place everyone has decided that Scrum is too complicated, so their team leader tries to split tasks themselves, finally in one more place a whole IT department consists of two people who work as they can without time or intention to read books about how it’d be perfect.
So, in future posts, I’ll tell you about different roles involved in software development, and how the processes can be organized, little by little, I'll come to examples of successful and unsuccessful cases from my personal experience. Finally, after all the introduction we’ll come back to the technical specifications. Stay tuned!
#job #IT #General #Introduction
Heavy tails
Recently I remembered times when I was hard studying probability theory, though here I’m not going to bring up with formulas and faint definitions, let’s think about a simple and easily observed physical value, namely the height of a grown-up (over 18 years) man. Remember your acquaintances, people who you face during your commuting, and so on. Of course, I can’t be certain about your neighborhood, but in mine, their height varies from 160cm to 195cm, where the boundaries aren’t too often. Is it possible to face a guy higher or lower than that? – Surely, but how often? – Not that much (I suppose you don’t hang out with a basketball team). If you don’t believe that people higher than 195cm are a rare event to observe here you can read a bit about how few of them are.
Hopefully, by this point, everyone has realized that men’s height is a value mostly concentrated in a certain range. It’s called Gaussian or normal distribution and is represented in the form of those boring formulas I promised not to bring up here. Briefly, it means the following: if we lay a height on the X axis and its share over the population by the Y axis, we’ll get a figure close to a bell, with its maximum at the average value and with symmetrical borders in a certain range. Everything is already drawn for us (scroll to the phrase "Height is normally distributed").
Are all the values distributed according to the normal distribution? - No. Let’s consider another very practical value – a person’s income, very often we can’t know this value for their people but we can estimate it by their expenses. If you spend some time thinking over it you’ll probably realize that there are much fewer rich people than there are poor people, and if you take a person who is considered to be rich in your neighborhood and multiply their income by ten and try to find someone with this income you’ll immediately realize that they are even more rare: there are around 3 thousand of billionaires over the world. And again, all these facts were summarized and expressed as a mathematical law a long time ago. Look at the first picture there: there is a maximum at a low value and then an infinitely long tail coming to the right. If we apply this law to the example with an income it’ll give us the following picture: most people have several hundred dollars a month and then rarely and more rarely we’ll find richer people ending with very separate points representing people from the Forbes list. It’d be much funnier if we try to apply the same to the example about men’s height: most men are 170cm tall though it’s possible to find one who is as tall as the Eifel Tower or Empire-State-building, or one whose height equals to the distance from the Earth to Pluto…
These kinds of distributions are called heavy-tailed ones, several years ago I started reading the famous “The Black Swan” book, but ended it up soon because I’d already learned the statistics.
#flood #education #math #probability_theory #books
Recently I remembered times when I was hard studying probability theory, though here I’m not going to bring up with formulas and faint definitions, let’s think about a simple and easily observed physical value, namely the height of a grown-up (over 18 years) man. Remember your acquaintances, people who you face during your commuting, and so on. Of course, I can’t be certain about your neighborhood, but in mine, their height varies from 160cm to 195cm, where the boundaries aren’t too often. Is it possible to face a guy higher or lower than that? – Surely, but how often? – Not that much (I suppose you don’t hang out with a basketball team). If you don’t believe that people higher than 195cm are a rare event to observe here you can read a bit about how few of them are.
Hopefully, by this point, everyone has realized that men’s height is a value mostly concentrated in a certain range. It’s called Gaussian or normal distribution and is represented in the form of those boring formulas I promised not to bring up here. Briefly, it means the following: if we lay a height on the X axis and its share over the population by the Y axis, we’ll get a figure close to a bell, with its maximum at the average value and with symmetrical borders in a certain range. Everything is already drawn for us (scroll to the phrase "Height is normally distributed").
Are all the values distributed according to the normal distribution? - No. Let’s consider another very practical value – a person’s income, very often we can’t know this value for their people but we can estimate it by their expenses. If you spend some time thinking over it you’ll probably realize that there are much fewer rich people than there are poor people, and if you take a person who is considered to be rich in your neighborhood and multiply their income by ten and try to find someone with this income you’ll immediately realize that they are even more rare: there are around 3 thousand of billionaires over the world. And again, all these facts were summarized and expressed as a mathematical law a long time ago. Look at the first picture there: there is a maximum at a low value and then an infinitely long tail coming to the right. If we apply this law to the example with an income it’ll give us the following picture: most people have several hundred dollars a month and then rarely and more rarely we’ll find richer people ending with very separate points representing people from the Forbes list. It’d be much funnier if we try to apply the same to the example about men’s height: most men are 170cm tall though it’s possible to find one who is as tall as the Eifel Tower or Empire-State-building, or one whose height equals to the distance from the Earth to Pluto…
These kinds of distributions are called heavy-tailed ones, several years ago I started reading the famous “The Black Swan” book, but ended it up soon because I’d already learned the statistics.
#flood #education #math #probability_theory #books
🔥1
Is there a chance?
Let’s go on with the section “Probability theory for the little ones”. If you’ve opened and flicked through the link from the previous post you might have noticed many obvious points, namely: height is dependent on many factors, and in various regions average height is different – people from Montenegro are tall even among Europeans, and people from Thailand are low. It means if we took data from only one region, better monoethnic, and even better only people of the same year of birth we would get the same “bell” with a narrower range. By the way, its range is determined by a so-called standard deviation (a square root of the variance). The impact of many different factors is exactly why height is distributed according to normal distribution.
Are there any other values distributed according to it? – Surely! They occur especially often when it relates to “real” physical values: results of experiments or measurements, results of a production line, it can be a volume of ice cream or a volume of espresso cooked by a coffee machine with the same settings. If you don’t believe it's possible, look at it. However, if an error (3 * standard derivation) is much less than the nominal value a customer should not be worried about it. In the given link the error lies in the range of -1…+1 grams per 1000 grams.
One can think that the milk filling line is just a bad example and in other industries, everything must be absolutely precise, in fact, – no, those errors are unavoidable, and the best that we can limit them under certain conditions. Chipset factories are a multi-billion business but they can’t guarantee all CPUs produced on the same line have equal characteristics, instead they are tested and classified afterward.
#flood #education #math #probability_theory
Let’s go on with the section “Probability theory for the little ones”. If you’ve opened and flicked through the link from the previous post you might have noticed many obvious points, namely: height is dependent on many factors, and in various regions average height is different – people from Montenegro are tall even among Europeans, and people from Thailand are low. It means if we took data from only one region, better monoethnic, and even better only people of the same year of birth we would get the same “bell” with a narrower range. By the way, its range is determined by a so-called standard deviation (a square root of the variance). The impact of many different factors is exactly why height is distributed according to normal distribution.
Are there any other values distributed according to it? – Surely! They occur especially often when it relates to “real” physical values: results of experiments or measurements, results of a production line, it can be a volume of ice cream or a volume of espresso cooked by a coffee machine with the same settings. If you don’t believe it's possible, look at it. However, if an error (3 * standard derivation) is much less than the nominal value a customer should not be worried about it. In the given link the error lies in the range of -1…+1 grams per 1000 grams.
One can think that the milk filling line is just a bad example and in other industries, everything must be absolutely precise, in fact, – no, those errors are unavoidable, and the best that we can limit them under certain conditions. Chipset factories are a multi-billion business but they can’t guarantee all CPUs produced on the same line have equal characteristics, instead they are tested and classified afterward.
#flood #education #math #probability_theory
👍1
Where is it going?
Recently I remembered my experience of working in a payment system, which currently doesn’t appear to be functioning. I had been working there for many years, definitely longer than I needed, so there are many things to remember. Today I want to tell a story about how the company turned my colleague and me into an Android developer and why it wasn’t so beneficial for me.
The story had its place a long time ago, in 2018, you might remember those years: Android was as popular as it is nowadays and lots of companies were developing applications for that, and the company where I was working wasn’t left behind. At the same time a project, written in C++, in which my colleague and I were involved, came to its decline phase: support and support, very few features, and no plan for further development. It isn’t a figure of speech because there is a concept of the product life cycle and software is also a product, but let’s leave this discussion for another time. The company stuck to a very calm position relating to declining projects: if employees want to work then let, them work as they can, we’re not going to fire them (as well as not going to raise their salaries). Consequently, when during a conversation with our manager my colleague and I were offered to switch to an Android development without prior experience in this field we took this offer immediately.
Particular conditions also sounded very interesting: develop an Android app from scratch, which contains several tens of screens and interacts with a backend and so on, and by the way, you’ll work with an analyst/project manager and an experienced coach from a flagship company’s project. Amazing! I’ll skip functional description because it doesn’t play a major role.
Having looked at Java documentation and an Android project, I realized that Java is quite close to C++ from which someone removed all the most complicated parts, and the main difficulty is Android SDK itself: the activity lifecycle, fragment lifecycle, branched screen transitions… The coach helped with it: “You need to use Moxy, Cicerone, RxJava, Retrofit, and of course Dagger”. No sooner said than done, though not all of those technologies look pretty obvious for a C++ developer, but they make life simpler.
The story has turned out to be long, so let’s go on with it another time.
#job #IT #Android #Java #memories #ToBeContinued #interesting_tasks
Recently I remembered my experience of working in a payment system, which currently doesn’t appear to be functioning. I had been working there for many years, definitely longer than I needed, so there are many things to remember. Today I want to tell a story about how the company turned my colleague and me into an Android developer and why it wasn’t so beneficial for me.
The story had its place a long time ago, in 2018, you might remember those years: Android was as popular as it is nowadays and lots of companies were developing applications for that, and the company where I was working wasn’t left behind. At the same time a project, written in C++, in which my colleague and I were involved, came to its decline phase: support and support, very few features, and no plan for further development. It isn’t a figure of speech because there is a concept of the product life cycle and software is also a product, but let’s leave this discussion for another time. The company stuck to a very calm position relating to declining projects: if employees want to work then let, them work as they can, we’re not going to fire them (as well as not going to raise their salaries). Consequently, when during a conversation with our manager my colleague and I were offered to switch to an Android development without prior experience in this field we took this offer immediately.
Particular conditions also sounded very interesting: develop an Android app from scratch, which contains several tens of screens and interacts with a backend and so on, and by the way, you’ll work with an analyst/project manager and an experienced coach from a flagship company’s project. Amazing! I’ll skip functional description because it doesn’t play a major role.
Having looked at Java documentation and an Android project, I realized that Java is quite close to C++ from which someone removed all the most complicated parts, and the main difficulty is Android SDK itself: the activity lifecycle, fragment lifecycle, branched screen transitions… The coach helped with it: “You need to use Moxy, Cicerone, RxJava, Retrofit, and of course Dagger”. No sooner said than done, though not all of those technologies look pretty obvious for a C++ developer, but they make life simpler.
The story has turned out to be long, so let’s go on with it another time.
#job #IT #Android #Java #memories #ToBeContinued #interesting_tasks
👏2
How to sum it up?
It’s a weekend, so I’d like to return to the topic I introduced a week ago, in other words, it’s our probability theory section. Namely, reconsider the example about the milk filling caning line: for us, it’s important that there is an error +- 1 gram per kilo. This time, let’s discuss what will be the error if we buy 100 milk bottles where each one is one kilo.
First of all, it’s necessary to understand that the weight of a particular bottle is randomly scattered in a range of 999…1001 grams being distributed accordingly to the normal distribution. So, if I sum up one hundred random values, barely I can state that the result will always be something like 100 kilo + 42 grams (or any other particularly given number). The result must be a random value, too.
Now let me translate the task into terms of the probability theory: there are one hundred identically distributed random values, whose mean equals a kilo and standard deviation equals 1/3 gram (coming from the 3-sigma rule). There is a complex matter for me here: it’s impossible to solve this problem not involving mathematical equations, but I particularly don’t want to use them in my posts. I just state that means and variations are just summed up, and the most significant thing is that the error is dependent on the standard derivation – a square root of variance.
In numbers we’ll get the following: the mean (of the sum) is 100 kilos, the variation for one bottle is a square of the standard deviation – 1/9, thus the variation of the sum is 100/9, and, finally, the standard deviation of the sum is 10/3, applying 3-sigma rule the wanted error is 10 grams. Pay attention a relative error for 1 kilo is 1/1000 = 0.1% and for 100 kilos it’s 10/100 000 = 0.01%. This result isn’t accidental.
Because there are things to be added here, it’s to be continued.
#flood #education #math #probability_theory
It’s a weekend, so I’d like to return to the topic I introduced a week ago, in other words, it’s our probability theory section. Namely, reconsider the example about the milk filling caning line: for us, it’s important that there is an error +- 1 gram per kilo. This time, let’s discuss what will be the error if we buy 100 milk bottles where each one is one kilo.
First of all, it’s necessary to understand that the weight of a particular bottle is randomly scattered in a range of 999…1001 grams being distributed accordingly to the normal distribution. So, if I sum up one hundred random values, barely I can state that the result will always be something like 100 kilo + 42 grams (or any other particularly given number). The result must be a random value, too.
Now let me translate the task into terms of the probability theory: there are one hundred identically distributed random values, whose mean equals a kilo and standard deviation equals 1/3 gram (coming from the 3-sigma rule). There is a complex matter for me here: it’s impossible to solve this problem not involving mathematical equations, but I particularly don’t want to use them in my posts. I just state that means and variations are just summed up, and the most significant thing is that the error is dependent on the standard derivation – a square root of variance.
In numbers we’ll get the following: the mean (of the sum) is 100 kilos, the variation for one bottle is a square of the standard deviation – 1/9, thus the variation of the sum is 100/9, and, finally, the standard deviation of the sum is 10/3, applying 3-sigma rule the wanted error is 10 grams. Pay attention a relative error for 1 kilo is 1/1000 = 0.1% and for 100 kilos it’s 10/100 000 = 0.01%. This result isn’t accidental.
Because there are things to be added here, it’s to be continued.
#flood #education #math #probability_theory
👍1
Is there a limit?
Last time when I was translating the task into probability theory terms, I assumed that each separate random value is distributed accordingly to the Normal distribution, and then I applied a rule that the means and variances can be summed up. Actually, there is a more interesting way to solve this task, namely to use the Central limit theorem (CLT). As you may guess there is no way that I’ll burden my readers with a proof of the theorem or with its truly mathematical representation. Without further ado, the theorem states: there are n equally and independently distributed values with a finite mean and variance then its sum is approximately distributed according to the Normal distribution and its mean and variance are the same as in the previous post.
Explain it one more time: we get the same result with weakened conditions. It doesn’t require that each separate value is normally distributed instead of that we say that any distribution with a finite mean and variance is suitable (except heavy-tailed ones because they don’t have a mean). However, having rejected this assumption I’d need to calculate a variance of one value by the given error not relying on the 3-sigma rule.
This short article shows why the Normal distribution is so popular and important. I won’t talk about it any longer, next time I’ll return to the heavy-tailed distributions.
#flood #education #math #probability_theory
Last time when I was translating the task into probability theory terms, I assumed that each separate random value is distributed accordingly to the Normal distribution, and then I applied a rule that the means and variances can be summed up. Actually, there is a more interesting way to solve this task, namely to use the Central limit theorem (CLT). As you may guess there is no way that I’ll burden my readers with a proof of the theorem or with its truly mathematical representation. Without further ado, the theorem states: there are n equally and independently distributed values with a finite mean and variance then its sum is approximately distributed according to the Normal distribution and its mean and variance are the same as in the previous post.
Explain it one more time: we get the same result with weakened conditions. It doesn’t require that each separate value is normally distributed instead of that we say that any distribution with a finite mean and variance is suitable (except heavy-tailed ones because they don’t have a mean). However, having rejected this assumption I’d need to calculate a variance of one value by the given error not relying on the 3-sigma rule.
This short article shows why the Normal distribution is so popular and important. I won’t talk about it any longer, next time I’ll return to the heavy-tailed distributions.
#flood #education #math #probability_theory
🔥1
Unexpected problems with fundamental types
Recently I came across an article about uncommon programming languages, and there was a phrase: “Cobol has a dedicated money type”, I remembered that a long time ago my colleagues and I faced difficulties trying to represent different money amounts in C++. It seems to be a kind of a joke at first sight because C++ (as well as Java and C#) has float and double datatypes for real numbers, why isn’t it possible to use them? Because they don’t work, the float type“breaks” even in this simple example:
Printing 999999. For the doubles it’s a bit more complicated to come up with an instance, though, when someone finds such an example in your program – it won’t make you laugh. There are a couple of main reasons to be pointed out: those types can’t exactly represent most decimal fractions like 0.1, 0.2, also during arithmetical operations these numbers are “aligned” to be represented at the same degree, but the mantissa has a finite number of bits, so that a small number can be lost during that (it’s what we saw in the code above).
Well, how to store prices and things like that in C++, then? Easily, store them as a number of cents in a long long int variable, of course, you should create a separate class with a field of long long int and implement all necessary operations and constructors. Amusingly, neither the Standard C++ library nor Qt has something suitable for money representation. In SQL there is a special type decimal.
Obviously, fundamental C++ types are inherited from its predecessor – C language, which in its turn is just a high-level assembly language. So, its types are basically what CPU architecture provides: one-byte value, 2,4, probably 8 for integral types, and 4 and 8 bytes for floating-point types. By the way, I don’t claim that the floats and doubles are useless: in any task involving real physical values like weight, torque, etc. the “error” with one hundredth would be neglectable against the entire magnitude.
#job #IT #c_plus_plus #math
Recently I came across an article about uncommon programming languages, and there was a phrase: “Cobol has a dedicated money type”, I remembered that a long time ago my colleagues and I faced difficulties trying to represent different money amounts in C++. It seems to be a kind of a joke at first sight because C++ (as well as Java and C#) has float and double datatypes for real numbers, why isn’t it possible to use them? Because they don’t work, the float type“breaks” even in this simple example:
float a = 0.01;
float b = 999999.00;
float sum = a + b;
std::cout << sum << std::endl;
Printing 999999. For the doubles it’s a bit more complicated to come up with an instance, though, when someone finds such an example in your program – it won’t make you laugh. There are a couple of main reasons to be pointed out: those types can’t exactly represent most decimal fractions like 0.1, 0.2, also during arithmetical operations these numbers are “aligned” to be represented at the same degree, but the mantissa has a finite number of bits, so that a small number can be lost during that (it’s what we saw in the code above).
Well, how to store prices and things like that in C++, then? Easily, store them as a number of cents in a long long int variable, of course, you should create a separate class with a field of long long int and implement all necessary operations and constructors. Amusingly, neither the Standard C++ library nor Qt has something suitable for money representation. In SQL there is a special type decimal.
Obviously, fundamental C++ types are inherited from its predecessor – C language, which in its turn is just a high-level assembly language. So, its types are basically what CPU architecture provides: one-byte value, 2,4, probably 8 for integral types, and 4 and 8 bytes for floating-point types. By the way, I don’t claim that the floats and doubles are useless: in any task involving real physical values like weight, torque, etc. the “error” with one hundredth would be neglectable against the entire magnitude.
#job #IT #c_plus_plus #math
How copy-paste saved a month
Among developers copy-paste is treated as an antipattern, however, everyone does it. And we have to admit that there is nothing wrong with that: if it’s possible to paste a piece of suitable code, and the most important thing – to tweak and adapt it. One more time: I don’t talk about giant classes, not knowing SOLID, and so on, I say that copy-paste is a correct step as long as it takes its place sometimes before opening a merge request for code review. Nowadays, many developers manage to write code with ChatGPt, in comparison with that copy-paste is just nothing.
However, I wanted to remember when copy-paste saved me a lot of time and helped me solve a task successfully. It happened while I was working on the project of a web engine, mentioned in this post. I’d already worked there for a couple of months when I took a bug with a humble description: “Flex layout doesn’t work correctly in a certain border case, look at the picture we’ve got and at another picture how it should be”. The developers added: “There are references to the specification in the code, check them out, probably they’re helpful”. Well, it sounded like a bug solving in a couple of code lines, everything that is left to find where and what I need to insert.
Before that I hadn’t heard about the flex layout: in Qt other layouts are used and I’ve never needed to implement one – just to apply it. Having looked at the specification, I decided that it’d be simpler to use a debugger to figure out why the calculation is incorrect in certain cases. It took me 3 days, after that I opened a merge request, assuming that the task was done. It was a huge surprise when I was told that my task was to implement an entire algorithm from the specification.
I felt sad because, obviously enough, it’d take me months: the specification is written in a very vague way, and the meaning of many terms and how to bring them down on our code was unclear. I quickly realized that the only suitable way to solve this task was to find a good project from which I could copy this sophisticated algorithm. I googled the source code of the WebKit project, and rapidly found exactly what I needed there after that things got better: it was possible to “translate” the algorithm from WebKit to our project, the only thing to take into account was that WebKit important values for the task are stored in different classes and our project they are somehow mixed up. However, finally, I just copied a needed piece of code from there and pasted it into our project, lightly adapting it…I opened a new merge request, it was quickly approved, and the task was completed.
#job #c_plus_plus #IT #web #HTML
Among developers copy-paste is treated as an antipattern, however, everyone does it. And we have to admit that there is nothing wrong with that: if it’s possible to paste a piece of suitable code, and the most important thing – to tweak and adapt it. One more time: I don’t talk about giant classes, not knowing SOLID, and so on, I say that copy-paste is a correct step as long as it takes its place sometimes before opening a merge request for code review. Nowadays, many developers manage to write code with ChatGPt, in comparison with that copy-paste is just nothing.
However, I wanted to remember when copy-paste saved me a lot of time and helped me solve a task successfully. It happened while I was working on the project of a web engine, mentioned in this post. I’d already worked there for a couple of months when I took a bug with a humble description: “Flex layout doesn’t work correctly in a certain border case, look at the picture we’ve got and at another picture how it should be”. The developers added: “There are references to the specification in the code, check them out, probably they’re helpful”. Well, it sounded like a bug solving in a couple of code lines, everything that is left to find where and what I need to insert.
Before that I hadn’t heard about the flex layout: in Qt other layouts are used and I’ve never needed to implement one – just to apply it. Having looked at the specification, I decided that it’d be simpler to use a debugger to figure out why the calculation is incorrect in certain cases. It took me 3 days, after that I opened a merge request, assuming that the task was done. It was a huge surprise when I was told that my task was to implement an entire algorithm from the specification.
I felt sad because, obviously enough, it’d take me months: the specification is written in a very vague way, and the meaning of many terms and how to bring them down on our code was unclear. I quickly realized that the only suitable way to solve this task was to find a good project from which I could copy this sophisticated algorithm. I googled the source code of the WebKit project, and rapidly found exactly what I needed there after that things got better: it was possible to “translate” the algorithm from WebKit to our project, the only thing to take into account was that WebKit important values for the task are stored in different classes and our project they are somehow mixed up. However, finally, I just copied a needed piece of code from there and pasted it into our project, lightly adapting it…I opened a new merge request, it was quickly approved, and the task was completed.
#job #c_plus_plus #IT #web #HTML
🔥1
Compare it
Part 1
It’s going to be a long post, furthermore, it’ll include code, I’ve warned you.
I took a simple task that I found on a popular platform called Leetcode. Write a function taking a string and returning a Boolean value, it should return true if all the symbols in the string occur the same amount of times, otherwise, it returns false, its length is between 1 and 1000, and only English lower-case letters are allowed. Leetcode provides a convenient web-based interface with buttons “Run” and “Submit”, everything that we need just to write code and then it’ll tell us whether it’s correct or not, and if it is we’ll see how fast it works.
The task is simple, the task is understood, basically speaking, we need two cycles: the first one to count occurrences and to store them somewhere and another one to check the stored occurrences. The complexity of the first cycle is O(n), where n is the length of the string, and the complexity of another one is O(1), because the English alphabet consists of 26 letters.
Ask ourselves: “What should we try to use in a C++ program?” – right: “Standard library”. Leetcode hints the same providing a starch of the solution with the string represented as a std::string rather than old-fashioned char*. However, what does a std string provide to help us solve this task? Well, since the C++11 standard, there is a range-based for loop, perhaps, that’s all. Let’s look at the code:
This is an absolutely straightforward solution: we’ve done what we’ve written, first, it iterates over the string counting letters and storing the frequencies into the dict, and then it iterates over the dict, comparing the frequencies, also we took into account that initially the count is zero, so we should carefully assign in the loop encountering the first non-zero value.
There is a catch: this solution beats only 27 percent of its competitors, barely I’d decide to write about such a bleak result:)
#IT #c_plus_plus #leetcode #today #ToBeContinued
Part 1
It’s going to be a long post, furthermore, it’ll include code, I’ve warned you.
I took a simple task that I found on a popular platform called Leetcode. Write a function taking a string and returning a Boolean value, it should return true if all the symbols in the string occur the same amount of times, otherwise, it returns false, its length is between 1 and 1000, and only English lower-case letters are allowed. Leetcode provides a convenient web-based interface with buttons “Run” and “Submit”, everything that we need just to write code and then it’ll tell us whether it’s correct or not, and if it is we’ll see how fast it works.
The task is simple, the task is understood, basically speaking, we need two cycles: the first one to count occurrences and to store them somewhere and another one to check the stored occurrences. The complexity of the first cycle is O(n), where n is the length of the string, and the complexity of another one is O(1), because the English alphabet consists of 26 letters.
Ask ourselves: “What should we try to use in a C++ program?” – right: “Standard library”. Leetcode hints the same providing a starch of the solution with the string represented as a std::string rather than old-fashioned char*. However, what does a std string provide to help us solve this task? Well, since the C++11 standard, there is a range-based for loop, perhaps, that’s all. Let’s look at the code:
bool areOccurrencesEqual(string s) {
map<char, int> dict;
for (const auto& ch: s)
{
auto it = dict.find(ch);
if (dict.end() == it)
{
dict[ch] = 1;
}
else
{
++it->second;
}
}
int count = 0;
for (const auto& [_, value]: dict)
{
if (count != value && count)
{
return false;
}
if (!count)
{
count = value;
}
}
return true;
}This is an absolutely straightforward solution: we’ve done what we’ve written, first, it iterates over the string counting letters and storing the frequencies into the dict, and then it iterates over the dict, comparing the frequencies, also we took into account that initially the count is zero, so we should carefully assign in the loop encountering the first non-zero value.
There is a catch: this solution beats only 27 percent of its competitors, barely I’d decide to write about such a bleak result:)
#IT #c_plus_plus #leetcode #today #ToBeContinued
Leetcode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Administrative
I've made up my mind to launch a blog on Habr https://habr.com/ru/articles/831624/.
Perhaps the content here and there will overlap somehow
#administrative #today #this_channel #habr
I've made up my mind to launch a blog on Habr https://habr.com/ru/articles/831624/.
Perhaps the content here and there will overlap somehow
#administrative #today #this_channel #habr
Хабр
Игрушечная имплементация чисел с фиксированной точкой в C++
В C++ нет базового типа чисел с фиксированной точкой , в стандартной библиотеке также нет классов для них. В тоже время работа с числами с плавающей точкой (double, float) часто может быть неочевидна...
👍1
As we all know: Monday is tough
Following this I published the second part about fixed point arithmetic on Habr
#IT #habr #today #flood #c_plus_plus #math #Monday
Following this I published the second part about fixed point arithmetic on Habr
#IT #habr #today #flood #c_plus_plus #math #Monday
Хабр
Имплементация чисел с фиксированной точкой (часть 2)
Итак, в прошлый раз я представил базовую идею как можно реализовать Fixed-point arithmetic , а так же набросок кода на C++, в котором в комментариях нашли довольно много проблем (а я сам нашёл ещё...
Long pause
Since my last post here all my ‘writing energy’ has been absorbed with deeper articles published on Habr: two of them were mentioned in the channel, another one – not. Though, the latter finally attracted attention not only in terms of discussion but also in terms of likes and views bringing me correspondingly 52 likes (at the current moment) and 6 or so thousand views (the stat may be inaccurate according to the Habr). It’s worth pointing out that the articles and their topics are brainstorming results rather than coming out of working experience. One more article is coming, being finished, and scheduled to be posted in a corporate blog, there are other ideas…
Being a sober man, I realize that everything is more than just questionable in the long run: lack of motivation and everyday life with its duties have killed a multitude of intents scattered across different fields. It brings me to an image gathered from a popular fiction book: a library of never-written books living only in the minds of their authors…
Things are getting more entertaining because a couple of days ago I “put” a book on the library shelf: I was astonished by that because when I deliberately tried to make up at least something vaguely decent for a fiction book – I couldn’t. The plot won’t be given unless it turns into a real written story...
#flood #today #this_channel #habr #plans
Since my last post here all my ‘writing energy’ has been absorbed with deeper articles published on Habr: two of them were mentioned in the channel, another one – not. Though, the latter finally attracted attention not only in terms of discussion but also in terms of likes and views bringing me correspondingly 52 likes (at the current moment) and 6 or so thousand views (the stat may be inaccurate according to the Habr). It’s worth pointing out that the articles and their topics are brainstorming results rather than coming out of working experience. One more article is coming, being finished, and scheduled to be posted in a corporate blog, there are other ideas…
Being a sober man, I realize that everything is more than just questionable in the long run: lack of motivation and everyday life with its duties have killed a multitude of intents scattered across different fields. It brings me to an image gathered from a popular fiction book: a library of never-written books living only in the minds of their authors…
Things are getting more entertaining because a couple of days ago I “put” a book on the library shelf: I was astonished by that because when I deliberately tried to make up at least something vaguely decent for a fiction book – I couldn’t. The plot won’t be given unless it turns into a real written story...
#flood #today #this_channel #habr #plans
👍2
After all, an article, aforementioned in the previous post, came out, bringing positive but mysterious stats, which consist of many likes, few comments, and a dislike. The latter doesn’t sadden me but raises certain thoughts: if one doesn’t find my job interesting why just don’t skip it, taking into account that I shed light on a deeply technical and specific topic which can’t touch their personal feelings or views. I keep silent about considerable efforts spent on a little or no paid job.
Well, let me quote Marcus Aurelius Antoninus: “Begin each day by telling yourself: Today I shall be meeting with interference, ingratitude, insolence, disloyalty, ill-will, and selfishness – all of them due to the offenders’ ignorance of what is good or evil.”
In general, it has changed nothing, the plans for future articles remain in the same state as I described them previously.
#flood #today #habr #plans
Well, let me quote Marcus Aurelius Antoninus: “Begin each day by telling yourself: Today I shall be meeting with interference, ingratitude, insolence, disloyalty, ill-will, and selfishness – all of them due to the offenders’ ignorance of what is good or evil.”
In general, it has changed nothing, the plans for future articles remain in the same state as I described them previously.
#flood #today #habr #plans
Хабр
Поделить нельзя — умножить или алгоритм быстрого деления по методу Ньютона-Рафсона
Все мы в школе проходили деление «столбиком» — простой алгоритм, который несложно реализовать, вот только не очень быстрый. В прошлый раз мы рассматривали, как компилятор оптимизирует деление в...
❤1
I'm still here
A week ago, I was going to write a post in the spirit of “long time no see but…”, it didn’t come true, so this week I’m going to give it another try. However, another thought came to my mind: little by little winter came to my place, currently it’s a true Xmas view in my window as well as in the neighborhood, and, obviously enough, it means that the year is about to finish…isn’t it time to sum the results and make a Happy new year’s resolution?
Regarding the former: a half year ago I began writing content for this channel and for a Russian twin of this channel, a month later I made up my mind to publish it on Habr. Both activities met moderately positive acclaim. At the moment there are 5 technical articles there, and most of them are mentioned in the channel. As a content maker, I realized a simple thing: it takes time and effort, especially the aforementioned articles, no way to write one in a day – in the best case it takes 2-3 days. The task is quite versatile: choosing a good topic, finding sources, writing code, creating illustrations, and last but not least making up a readable and coherent text minding the grammar and the register.
Now we’re getting to the resolution part: in spite of the fact that I do enjoy writing my articles, there is no way to create content of this level on a regular basis. For instance, I was planning on the article about cryptography, I did write the code and read a lot of related math stuff, but it’s already been two months and I can’t start arranging it all together due to a lack of time and energy. Perhaps, our cold weather isn’t the last factor why it’s so but a more major role played by my job and everyday chores. There is one unpleasant observation staying true through the passing years: the closer to the end of the year it is the more tired you are, on top of that even a humble celebration of it makes some fuss itself. The best thing I can do in terms of blogging is to drop an average-sized post once in several weeks.
Perhaps, that’s all that I wanted to say today.
#flood #superflood #today #this_channel #plans #habr #end_of_year
A week ago, I was going to write a post in the spirit of “long time no see but…”, it didn’t come true, so this week I’m going to give it another try. However, another thought came to my mind: little by little winter came to my place, currently it’s a true Xmas view in my window as well as in the neighborhood, and, obviously enough, it means that the year is about to finish…isn’t it time to sum the results and make a Happy new year’s resolution?
Regarding the former: a half year ago I began writing content for this channel and for a Russian twin of this channel, a month later I made up my mind to publish it on Habr. Both activities met moderately positive acclaim. At the moment there are 5 technical articles there, and most of them are mentioned in the channel. As a content maker, I realized a simple thing: it takes time and effort, especially the aforementioned articles, no way to write one in a day – in the best case it takes 2-3 days. The task is quite versatile: choosing a good topic, finding sources, writing code, creating illustrations, and last but not least making up a readable and coherent text minding the grammar and the register.
Now we’re getting to the resolution part: in spite of the fact that I do enjoy writing my articles, there is no way to create content of this level on a regular basis. For instance, I was planning on the article about cryptography, I did write the code and read a lot of related math stuff, but it’s already been two months and I can’t start arranging it all together due to a lack of time and energy. Perhaps, our cold weather isn’t the last factor why it’s so but a more major role played by my job and everyday chores. There is one unpleasant observation staying true through the passing years: the closer to the end of the year it is the more tired you are, on top of that even a humble celebration of it makes some fuss itself. The best thing I can do in terms of blogging is to drop an average-sized post once in several weeks.
Perhaps, that’s all that I wanted to say today.
#flood #superflood #today #this_channel #plans #habr #end_of_year
❤1