C ++ in the service of orthodontics: interview with Mikhail Matrosov, CAD developer at Align Technology







Mikhail Matrosov ( mmatrosov ) is a leading development engineer at the Align Technology R & D office in Moscow. His specialization is very unusual - he is developing a specialized CAD-system for the design of orthodontic appliances.







Mikhail has been participating in C ++ Russia since the very first conference. This year, at C ++ Russia 2019 Piter, he will give a presentation on ā€œQualifiers, Qualifiers and Templatesā€ . You can also know him at the courses from Yandex "Fundamentals of C ++ Development: Brown Belt" and "Fundamentals of C ++ Development: Black Belt" at Coursera, in the creation of which Michael co-authored.







The conference is already around the corner, but for now, catch an interview with Mikhail, where we discussed his work at Align Technology, the migration of legacy code, the preparation of online courses and reports, as well as the features of C ++. Questions were asked by Pavel Filonov (C ++ Russia program committee) and Oleg Chirukhin (journalist of the JUG Ru Group).







At the junction of technology and medicine



Pavel: Tell me what your company is doing.







Michael: Align Technology is a pioneer and market leader in clean orthodontics. This is such a thing that is being done all over the world now instead of braces. If previously a metal wire was placed for tooth straightening, and they ran with it, now instead of that you put on transparent plastic mouthguards (liners), which are made individually for each patient. Recently I tested on myself the products of our company, a very funny feeling!







Pavel: So you have such dogfooding, yes, it turns out?







Michael: Yes, sort of. In fact, if you donā€™t know, itā€™s very difficult to notice that the person is in the liners. Unless, at first, out of habit, small speech defects appear, but even they are difficult to notice.







Pavel: And what does C ++ have to do with, which we will talk a lot about today?







Michael: Great question. When the company was just in its infancy, two cheerful Pakistanis took in it some special plastic (I donā€™t know where they found it from), which should be non-toxic and inert with saliva and other substances in the mouth.







Then they took a model of the patient's jaw, which they knew how to do for a very long time. For example, to make crowns, a person was given a bite of something like a special plasticine. There remained a cast of teeth that was filled with material. So they got a copy of the jaw, and they pulled plastic on it (somehow they warmed it up), and the mouthpiece is ready. That is, this entire market literally 20 years ago was completely analog.







Now the volume of production in the region of 300-400 thousand liners per day (please evaluate the scale). These are gigantic manufactures, therefore they are completely automated.







To create a liner, we print molds on a special 3D printer. This is, in fact, a copy of the patient's jaw during treatment. We model how the jaw will look in a week, two, a month, a year. Then we start the thermoforming process - we take a plastic tape, warm it and pull it onto the mold. Cut off and get a plastic liner.







At the moment, no one is already casting patients, but using three-dimensional intraoral scanners. We have guys doing this in a nearby office. This is probably the most ā€œwow partā€ of our production. There, in real time, a special nozzle leads along the jaw and build its shape. Information is uploaded to the company's servers, processed and sent to our specialists (technicians). They can edit the scan, remove noise.







Then treatment is planned in a specialized CAD system. This is a very complicated thing, because no one knows what a proper bite is. Each doctor has his own view on this matter. We are currently working to formalize approaches to treatment, but this is not yet in the prod.







But back to C ++. There is such a problem, for example. Molds are printed on a special 3D printer using laser stereolithography technology. There is a large tub with a special photopolymer liquid. They shine on it with a laser and it hardens. First, they shine on the very bottom of the printed model, then a little higher, even higher, etc. And so, inside the fluid, a solid model appears from bottom to top in layers.







Printing one mold by one would be impractical. The vat is quite large and you can put about a hundred molds into it. But they must be compactly arranged. The shape of the mold is similar to a horseshoe - that is, non-convex and rather complex. And they are all different. It turns out an interesting task of tiling a rectangle with complex figures.







Here in this video from the specified time stamp you can see how it looks.







This is just one example, there are a lot of tasks.







Pavel: Your descriptions are like high-tech calculations. Languages ā€‹ā€‹such as Fortran have historically performed well in them. At least you can still see the echoes. Why exactly C ++?







Michael: Well, not Fortran, it would be very powerful. At the very beginning of development, the main product was this very specialized CAD system - a desktop application for Windows. Therefore, a language was needed for efficient computing and at the same time for developing the application itself. There wasnā€™t much choice at that time - only C ++.







Now we have a zoo of languages: JavaScript and TypeScript for the web, Java for mobile applications, Go for servers, Python for automation, and a lot of little things. Basically, a standard stack. And in science-intensive and computationally complex applications, C ++ remains.







The higher the position, the wider the horizons.



Pavel: You mentioned your position as a leading engineer. And so I noticed such a strangeness. If a novice C ++ developer from your company was asked what he was doing, he would say that he was spinning some kind of super framework based on templates, which based on booststage does server balancing, and technologies would immediately fall off.







When you are asked what your company is doing, a whole story begins about the business: where is the money, why is it important, etc. Does this somehow correlate with your position? What is this view of processes, technologies, tools?







Michael: Yes, perhaps. But besides, if I start immediately telling about how I cross trees (though I donā€™t do it myself), it will not be clear to everyone. For example, dudes from Yandex, Kaspersky Lab can start with technology, because everyone knows their products. We are talking about liners, about which a small number of people know. Therefore, it is necessary to explain what it is.







Regarding how this correlates with the post. On my grade, I have to at least understand the elements of our workflow of current systems that work together. After all, if something changes, this can affect the production, the site of doctors, the interface with which technicians, doctors and business analysts interact. That is, yes, there is a correlation. With the growth of the grade you need to better see what is happening in the company.







Pavel: Have you thought how the introduction of new technologies, say, those related to C ++, would affect the workflow? Few people look at new features of the language. And if not, then tell us about how you recently implemented tools?







Michael: I donā€™t remember about C ++ offhand. If we take the tools, the last thing we screwed up is a cloud-based logging system. We specifically use Splunk for this. Initially, the platform was under the desktop, and the migration to the cloud is now in full swing. Therefore, we screw, in particular, cloud-based logging. Our manager quickly learned to make queries and build beautiful dashboards, display real-time charts. I was very pleased. I sent it out to everyone and said, see how we vary the operating time of such a complex algorithm, what is the reason? They began to understand, we realized that we have almost no multithreading on test agents. Something is constantly being introduced.







C ++, Legacy, cross-platform and everything, everything, everything



Oleg: Do I understand correctly that you have rendering in the browser?







Michael: Yes, there is.







Oleg: Browser technologies are constantly changing. Does it somehow affect? For example, the new JS, Shading Language , something like that.







Michael: It affects, but itā€™s a little boring here. In terms of rendering, the scene is pretty simple. We donā€™t have any incredible special effects.







Pavel: Good. But you said that you started with a desktop application, where C ++ was the best solution that combined all the advantages. When the business began to grow with the product, you began to develop other platforms. Some code went to the browser, some to the backend, some to mobile phones. Did the ā€œpositiveā€ core remain on all platforms?







Michael: Movement to other platforms began two years ago, and for our scale this is a short time. Therefore, our first cloud solution was a desktop monolith, from which, roughly speaking, the GUI was thrown. About a year and a half ago, we isolated the conditional kernel and the binding around it, so we were able to compile and run it already under Linux. It was a big breakthrough. Linux was important to us primarily because cloud Linux machines are much cheaper.







Now we want to separate the computing core in C ++, where all complex calculations will take place, from business logic that describes what to do and in what order, where the case came from, what type of product, what the doctor has the right to do and what not, and that is all.







Pavel: You probably already have a roadmap of this process, since you talk so well about it.







Michael: We tried many times to create a roadmap. We understand where we seem to be able to move, taking into account the 20 years of Legacy (you canā€™t get there with a half dollar, you need to think about it).







Interaction of positive projects is now done in a simple way. Of these, it is the C ++ interfaces that stick out, so they only get together to make sure there is one compiler. A total of about 250 projects, each going to its own dynamic library. And we combine them in different ways for specific tasks.







About 10 teams work on the system. Each team recruits a subset of these projects, usually 50-70. Now we are moving in the direction that some service will be created on their basis. We define a strict API for the service (based on protobuf or something else), and make a standard scheme of interaction between services. It is difficult to call the process the separation of computation and logic, but these are the first attempts at componentization.







My team and several others have already begun to do this. You immediately feel how much funnier when you collect a monolith from not only 250 projects, but only from 70. And there is no longer a situation where someone changed another module that interacts with seemingly completely unrelated things, and something broke . It has a cool psychological effect. And while we are trying to get away from a healthy desktop monolith by allocating conditionally 10 small monoliths to our services.







Pavel: And during this process you did not consider whether the modules that are about to be promised to be loaded in some form can help him at any of the levels?







Michael: It was this process and the Linux migration process that Conan helped us with. We had a serious problem with third-party management. I talked about how we used Conan at C ++ Russia 2019 in Moscow.









The ā€œplusā€ modules would help to solve some problems with the compilation time, from where, in fact, it all started, why everyone so wants the modules. Reusing positive modules to interact with the service is foolish, because they will communicate at some language-agnostic level (protobuf), and rightly so. Maybe we would be able to perform componentization and not build our 250 projects from the source each time, but put them in Conan's packages. And if, for example, folding dlls is inconvenient for certain reasons, then assembling into modules is an option.







But I canā€™t say that we are waiting for some feature that will change our approach to development.







Pavel: You mentioned that Conan helps you solve package management problems. In my opinion, about 3 years ago, the C ++ community only talked about this. The first reports appeared, the first prerequisites. And now you say that it already works in production.







Tell us about your experience of project evolution. Was the transition process painful and worth it?







Michael: Definitely worth it. We are satisfied with Conan. There are some flaws there, but managing dependencies in C ++ is a very difficult task. Therefore, it is obvious that there will not be a simple tool to solve it.







With Conan and the process on it, we have achieved a balance of task and solution complexity. We initially said: ā€œOkay, we want to highlight such and many sets of compilers and configurations, then build dynamic libraries (rather than static ones) by default, make a certain small set of restrictions,ā€ and we began to build a system within this set of restrictions. We have a wiki page ā€œHow to create a Conan recipe for a libraryā€, which takes into account all the specifics of our system. The page is quite large and not very simple. But, again, we have reached a balance of complexity, so I am pleased with the transition.







Pavel: And here, by the way, at the upcoming C ++ Russia 2019 Piter Denis Panin from NVIDIA will talk about the alternative represented by vcpkg . Would it be interesting for you to go to the report and listen to how they are doing in other tools?







Michael: Yes, it would be interesting. I used vcpkg a bit, but, in my opinion, there is very little flexibility in vcpkg. And I canā€™t imagine how we could build a system with our requirements based on vcpkg. But if I need to quickly take and test some kind of library, then I wonā€™t download it and read Build Instructions, that there you need to specify how to register dependencies, this is all the trash. I will see if it is in the vcpkg ports. If there is, then quickly put it, experimenting with it. If all is well, then Iā€™m going to write a conan recipe for her.







Pavel: Let's continue about the introduction of new tools and approaches. Have you encountered the fact that engineers come running with burning eyes from the conference, where they were told about a new cool thing, and they want to insert it into the project? How do you usually react to such things? Or do you resort like that after every conference?







Michael: There is just a great story. When I just started working in the company, they wrote a feature, and it was necessary to make a configuration for it. Moreover, a feature can have several different versions, and the values ā€‹ā€‹of specific properties can be rummaged between different versions. And I came up with a cool YAML-based scheme where there was inheritance and redefinition of properties. He wrote it for about a week, covered it with tests. And at the very beginning the manager came up to me and said: ā€œListen, Michael, maybe you donā€™t need to waste time now and make such a flexible scheme?ā€ But he could not convince me. My eyes were too burning.







After a couple of years, I look at this code and do not understand why it was so difficult to do. This happens, but, fortunately, since then I have become smarter. In addition, usually developers are very rational people, you can talk to them.







It used to be that someone was pulling in dubious third-party decisions. It is unclear by whom they are developing, the last update was 5 years ago, it has not been checked whether it works under Linux, they generate any reports in a proprietary format that you canā€™t convert to anything. And we sit and do not understand what to do next. Most of these third-parties were added many years ago, but it happens that something similar happens now.







Therefore, we came up with a fairly simple thing - a third-party checklist. If you want to drag a third-party, just go through the checklist items: cross-platform, support level, license, which analogs, development support level (how many maintainers support, which community). All points are obvious, but there are a lot of them, and when you type third-party, you wonā€™t remember everything at once. The situation has become better, and we are watching what is being added.







Itā€™s also cool that earlier it was easy to drag a third-party and assemble it, for example, only in a release under ā€œWindowsā€ and 32 bits. Now, in principle, there is no such possibility, since you must put it in Conan. And if you drag third-party, you will have to make sure or explicitly indicate that in some configuration it is not going to. Thanks to this, the left third-party began to be added much less.







Oleg: And what about the third-party, which live very little? For example, some left-pad from JavaScript. He goes on your checklist. It is often updated, maintained, made by packages.







Michael: There is no such thing. In C ++, third-party is usually a thick thing. And third-party solutions that perform small functions are not used. Indeed, in C ++ it is not so simple to add third-party. And this is not JS, in which each one has its own module.







We have conditionally pulled 80 third-party, half of which I have never seen. Or some kind of hellish geometry that was written 15 years ago at some university, and we have it.







Oleg: With Conan, it's easy to add a third-party.







Michael: Conan is easier, but still far from the same Python where you write pip install and you're done. C ++ has a very complex ecosystem: different operating systems, compilers, toolchain, libraries, standards. Most libraries have a bunch of options.







They like to ask us: ā€œWhy are you writing your library recipes, but not taking them from Conan-center?ā€ I looked periodically from there recipes, but they do not suit us. We are doing better. For example, our recipes take care of debase symbols, and add a binding to the sources in them. So when you get a third-party library from the debugger from Visual Studio, the sources are loaded automatically.







So with Conan is much better, but still far from the convenience of other languages.







Oleg: Are there any flaws in Conan itself that I would like to correct?







Michael: Yes, there are drawbacks, but technical.







Conan has methods that conditionally are responsible for generating packages and for connecting the generated packages to your solution. Ideologically, these are two different stages, and I can change one without changing the other. When I change the way packages are connected, I would not want to regenerate binary packages, because they will be exactly the same. You cannot do this in Conan, because the recipe is one entity. If you changed the recipe, then formally you have to change the version and generate new binaries, which is inconvenient.







Features of the transition to new standards



Pavel: Let's talk about new standards. In addition, your product already has some history.







Now we come to the conference, where every three years they tell us about new wonderful features. For example, at C ++ Russia 2019 Piter there will be three reports on upcoming changes in the language. Do you have any experience migrating the old code base, which corresponded to the old standards, to what was offered or will be offered?







Mikhail: Yes, I had such an experience, talked a little about it at C ++ Russia 2019. We had a migration from Visual Studio 2013 to Visual Studio 2017 and gcc, that is, we simultaneously added Linux support and updated compilers from Microsoft.







The problems in the code were much less in comparison with organizational, technical, infrastructure problems, CI and the rest of the tuning. And our problems in the code were primarily related to UB, which, after updating the compiler, started firing. Although C ++ spread rot for years of backward compatibility, but it helps. Now we compile everything under C ++ 17.







Vorings are not synchronized when developers collect under Windows, push into CI and only after that they begin to assemble under Linux. But there were no significant problems.







In C ++ 17, some obsolete things were removed, but we spent only a few hours cutting them out. For example, the log4cplus library used std :: auto_ptr in headers, but in new versions it was already replaced with std :: unique_ptr, so it was enough to simply update the library.







So the migration to the new standard was relatively painless. And given the size of our code base, I am surprised how few problems we have encountered.







About the brown and black belt in C ++



Pavel: You and I are already talking about the existing processes, where developers with experience already work. Let's give food for thought to novice developers who are just learning. What C ++ standard would you recommend starting with?







Michael: We must take the latest standard right away. You will not learn STL in the same C ++ 98, since STL without lambdas makes no sense. If you look at the courses "Fundamentals of C ++ Development: Brown Belt" and "Fundamentals of C ++: Black Belt" on Coursera, then we already write in C ++ 17. For example, we use structured bindings.







Pavel: It's good that you mentioned these courses. As I know, you also participated in their development. Tell me how you became a co-author and what do you see interesting there for yourself?







Michael: Ilya Shishkov from Yandex is engaged in all this, and we have long-time acquaintances. He once asked me if I wanted to create a C ++ course. He had a lot of people from Yandex who were well versed in C ++, but there werenā€™t enough people who could tell everything simply and clearly. I like to explain, convey thoughts and organize material, but I havenā€™t worked in this format yet. I understood that it would take an order of magnitude more time than, say, preparing a report for the conference. And the question was whether they would give me working time. Therefore, I went to the leadership with this idea, explained that we will be promoted from this, that I can stick the Align Technology sticker on the laptop in the frame.







Pavel: You said that preparing training material is an order of magnitude more difficult than a report. Why?







Michael: First of all, the report is a dialogue. I guess I will have an audience. If during a speech I see a lack of understanding in the eyes of the audience, then I stop and explain in more detail. And when you are in the studio with spotlights, and the camera is looking at you, you need to select words very accurately, because there is no feedback. Secondly, there is more material, and it needs to be broken down into short but complete fragments. We need to clearly think through the structure. Thirdly, in the report I can tell either something completely new (our experience) or something that people are not familiar with. There is value in the information. And here I am not saying any new information. All this has long been known. Here all the value in the comprehensibility of the presentation. And you have to pay especially much attention to this. For example, on a brown belt, I made a series of slides, scratched my turnips, discussed with the guys, and decided to redo everything. By the way, for the very same reason, I believe that tutorial reports should be of the highest quality. If you have already decided to explain something that is already known, you need to do it well.







It's hard to be a speaker



Pavel: By the way, about the topic of your reports. You usually touch on different topics related to practical tasks. How do you come up with themes?







Michael: Usually I take those topics that I had to understand. I recall what I was fucking with over the past year and what it would be interesting to talk about.







Pavel: In my opinion, you always manage to make your reports ā€œtransparentā€ to the audience. The problem, tool and methods are clear. How do you manage to maintain ā€œtransparencyā€ and clarity, even when you go into complex topics?







Mikhail: A basic presentation on how to make presentations that is distributed to all speakers helps a lot. Runs also help. Just take not your familiar expert, but some middle one. This way you will learn how the audience responds.







I was also helped by the experience of conducting C ++ seminars in graduate school. I prepared materials for students, read the standard. And over time, I can say that the seminars were disgusting. It was incomprehensible, difficult, a lot of concentration on the details. I am still ashamed of those students. At some point, it came to be understood that this should not be done.







Itā€™s very important to understand why you are giving a report. Then I wanted to figure out all sorts of chips, and it does not matter that the students do not understand, but I'm interested. Now I want my report to be understood. Therefore, on each slide and sentence I ask myself the question "is this understandable?" This is helped by feedback from the audience, so practice is important.







Pavel. You constantly participate in C ++ Russia and you were even the very first speaker. Which conference did you like the most?







Michael: The last thing I liked about the organization. But the very first, obviously, was the chamber. On it, in fact, I met with Ilya Shishkov. But the conference where I threw balls into the audience was the most memorable.







Pavel: I think that all the participants remembered that report. And if we talk about topics, what trends do you see? What did they talk about in 2015, will they talk about in 2019 and even in 2020?







Michael: I am a pragmatist, so when I go to the conference, I highlight what is interesting to me. Iā€™m not ready to say about any trends. But it surprises me that at conferences conferences on the basics continue to appear, which do not bring anything new, but such reports are really interesting. Even in those reports that I did, he did not tell almost anything new. Only about things that are built in practice to solve a specific problem.







I recall a report from CppCon 2018 about template functions . It would seem that these are just template functions, but in an hour I learned a lot. After all, C ++ is extensive. And under what you have been using for many years, there are many nuances.







My next report can also be attributed to this category. There will be a little bit about newfangled chips, but the best part is that it has been around for many years.







Pavel: What will your report be about?







Michael: The report will be about const, volatile, static, constexpr, inline, extern and how they interact with each other. For global entities, class members, local variables, etc.







Pavel: Will there be completely fresh consteval and constinit?







Michael: Iā€™ll tell you about this at the end of the report. It was very interesting to me, because I didnā€™t understand this very much, it was useful to understand. Frankly, in the first 3-4 hours of the study there were more questions than answers.







Oleg: By the way, is it true that Visual Studio does not fully support constexpr?







Michael: Visual Studio supports them well. At least I tried the basic functions. True, I have not tested constexpr lambdas.







Oleg: I just saw a bunch of internal bugs that developers say: to use this feature, you need to rewrite a half-compiler, so we can do without it.







Michael: As a user of Visual Studio Iā€™ll say that it has become much better. I well remember what happened in 2010: I get a static variable in lambda, and the compiler crashes. Now Microsoft's support for new features pleases.







Pavel: In the subject of your report. There are already five words for immutable entities: const, constexpr, constinit, consteval and, unexpectedly, final. Why isn't final called, say, constfinal?







Michael: final, unlike other keywords, is associated with polymorphism. I will only mention it. Itā€™s good that we donā€™t have a constfinal, it would be too much.







Pavel: You said that you like to take the conference program, emphasize in it what you are interested in, and go to listen. Did you manage to do this with the current conference program?







Michael: No, I always do this before the conference itself, because the program can change. Even at least two reports that used to be at different times can stand in parallel.







Pavel: So you only know about your report?







Michael: No, the JUG Ru Group spammers me with those who will speak at the conference (smiles).







Pavel: Thank you very much for the pleasant interview. What would you like to say to the potential participants of the conference?







Michael: Remember that the conference is primarily networking and dating. So if you are in the corridor and have an interesting conversation, but the report begins, itā€™s okay to miss it. Then look at the notes.







Pavel: And the last question. Do you think itā€™s more interesting to attend a conference as a participant or speaker?







Michael: Speaker, of course. Because during lunch, the participants are standing around the tables, and the speakers are having lunch sitting (laughs).







Mikhail Matrosov speaks this Friday at C ++ Russia 2019 Piter with the report ā€œQualifiers, Qualifiers and Templatesā€ . There are only a couple of days left, tickets can be purchased on the official website of the conference .



All Articles