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