Most recently, I participated in a curious project. Since the company financing this project “opened the cards” and even made a website dedicated to its results, I decided to tell you about it, dear habrayusers.
When creating interactive applications, it is often necessary to choose between two alternatives: a desktop application under Windows or a web application running in a browser. The main motto of the p2js project is “One source code - two platforms”. So, if in two words, p2js is a translator of programs written in Delphi to javascript. A lot has been written on the project site about how this happens. I will not repeat. I personally made a couple of discoveries for myself:
The amazing flexibility of javascript along with closures allows you to work wonders. Well, for example, how to make the transfer of arguments by reference. The argument through which abc is passed is replaced with the {get: function () {return abc;} object, set: function (v) {abc = v;}}. Inside the function itself, the argument assignment is replaced with a call to the set method. Isn't it amazing?
Refactoring code when translating modal dialogs. Modal dialogues are often used in desktop applications, and on the web this is considered bad form. Browser manufacturers are very reluctant to support this feature. And some of them (Opera, Chrome) and are not going to do it under any circumstances. To be honest, I didn’t really believe that there is an opportunity to rebuild the program code in such a way as to create its complete “modeless” equivalent. However, it still managed to do it. For myself, I concluded that it is always possible to refactor the source code so as to abandon the modality (meaning the true modality, that is, the dialogue with its own separate message processing loop).
The main forces of the team were spent on creating an analogue of VCL (this is a library of components in Delphi and C ++ Builder who does not know). It was based on the famous Ext JS library. For myself, noted the following. Almost all VCL components (and their MFC counterparts, etc.) are aimed at changing their properties at runtime. In such libraries as Ext JS, jQuery, etc., everything should happen “before rendering”. Any further change in the appearance or behavior of the component causes difficulties. In order to make sure of this “integrally”, it is enough to count the number of setters, for example, in Ext JS. Well, a couple of three will find ...
IE - ...! This browser, many curse. Mostly for violating css and html standards, or lagging behind other browsers. I will add my spoon of tar in a barrel of tar. Anyone who tries to work with scripts in this browser will get a lot of unforgettable impressions (especially from the developer’s tools).
Now the answer to the question that will still be asked - why? A company that needs it has a product in which ~ 1 million lines of source code. Basically the product is written in Delphi. Their customers want the product to work on two platforms. Of course, it was possible to hire as many programmers and testers who would repeat the creation in 3-5 years. And you can broadcast and have a solution on both platforms.