Developer's notes
4 subscribers
2 photos
1 video
16 links
Developer's notes: memories about projects, tasks, and advice to the beginners
Download Telegram
Unusual project.

Some time ago (but within the current decade) it happened to me to be a senior C++ developer in a famous international corporation which doesn't work in Russia any longer. The corporation works according to oursource/outstuff business model, particularly for this project out customer was one German automotive firm. My responsibility there was an unusual project that I always struggle to describe. Let's judge yourself about that: desktop application for Windows written in C++ Qt\QML without any network interactions and even without SQL-queries I mean at all. Well, what the hell can it be then? Perhaps, it appears to be some kind of crap: the app parses XML-based files and provides handy graphical user interface to edit those files. That's all. As a result: lots of untrivial tasks had been done almost without making usual forms. #job #Qt #QML #C++ #English #automotive #c_plus_plus
1
Weird project.

To cut long story short, the company from https://t.me/SomeDevelopersNotes/4 decided to leave Russia, the developers were offered to move to Serbia with the same (humble) salaries, as a consequence most of them (including me) made up their minds to change job in pursue of better conditions.

So, once upon time I found myself working in a Russian company whose main niche is "import substitution". Surely an interview that I passed to get this job as well as interviews in IT industry in general deserves its own posts, so I'll keep silent here about it. Getting back to the job, initial project description given by a team leader sounded pretty interesting: web-engine, no deadline, take your time to dive into it. In the reality it turned out to be a small poorly functioning library written in C++\Qt which provides a highly inconvenient QML-component. All this crap can render only very limited subset of HTML tags and there was another application also developed by this company where to this component was integrated. Because the current functional covered all the requirements there was no actual business tasks and there weren't even planned in the foreseeable future. The team leader gave tasks according to the idea: "we're developing a Chrome substitution". As a result, 6 months later the company realized that no one needed the project, the budget was optimized. #job #C++ #Qt #QML #weird #English #c_plus_plus
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:

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
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:

    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
🔥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:

    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