Translator from Delphi to javascript
Most recently, I participated in one interesting 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 habrayuzers.
When creating interactive applications, you very often have to make a choice between two alternatives: a desktop application for 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 a nutshell, p2js is a translator of programs written in Delphi in javascript. A lot has been written on the project website about how this happens. I will not repeat myself. Personally, I made a couple of discoveries:
Now the answer to the question, which is still asked - why? The company that needs this has a product in which ~ 1 million lines of source code. Mostly 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.
When creating interactive applications, you very often have to make a choice between two alternatives: a desktop application for 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 a nutshell, p2js is a translator of programs written in Delphi in javascript. A lot has been written on the project website about how this happens. I will not repeat myself. Personally, I made a couple of discoveries:
- The amazing flexibility of javascript along with closures allows you to do wonders. Well, for example, how to make the transfer of arguments by reference. The argument through which abc is passed is replaced by the object {get: function () {return abc;}, set: function (v) {abc = v;}}. Inside the function itself, the assignment of the argument is replaced by a call to the set method. Isn't it amazing?
- Code refactoring during translation of modal dialogs. Modal dialogs 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) are not going to do this under any circumstances. To be honest, I didn’t really believe that it was possible to rebuild the program code in such a way as to create its full “non-modal” equivalent. Nevertheless, it was still possible to do so. For myself, I concluded that it is always possible to refactor the source code so as to abandon the modality (meaning true modality, i.e., a dialogue with its own separate message processing cycle).
- 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). The well-known Ext JS library was taken as a basis. For myself, noted the following. Almost all VCL components (and their analogues, such as MFC and others) are aimed at changing their properties in runtime. In libraries such as Ext JS, jQuery, etc., everything should happen “before rendering”. Any further change in the appearance or behavior of the component is difficult. In order to make sure of this “integrally” it is enough to count the number of setters, for example in Ext JS. Well, you’ll find a couple of three ...
- IE - ...! Many scold this browser. Mostly for violation of css and html standards, or lagging behind other browsers. Add my fly in the ointment barrel. Anyone who tries to work with scripts in this browser will get a lot of unforgettable impressions (especially from the developer tools).
Now the answer to the question, which is still asked - why? The company that needs this has a product in which ~ 1 million lines of source code. Mostly 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.