In august 2018 I decided to develop Enigma in Free Pascal. The main reason was that Oracle terminated the support for JavaFX. A company called Gluon would support it as an open source project, but I did not believe that JavaFX would last. Swing and SWT were no alternatives for me and using a web-interface in a native application had severe drawbacks.
I made some comparisons and Free Pascal was the clear winner. It was object oriented, open source and had an exceptional good way of handling the user interface. I knew the language from previous experiences, though that was some 15 years ago.
So I happily started coding. At first everything went well but as the application grew I experienced some stumble-blocks. The editor, with the beautiful name Lazarus, was good but it paled in comparison to intelliJ, the Java editor I was used to. Unit testing was possible but it missed some essential techniques, like mocking and calculating the test-coverage. And the way the source was handled, in units, files with mancy classes, was cumbersome. OK, I could have created small units but then I would have had problems defining the imports. I expect to be using at least 1000 classes after some further development, so this became a problem.
I found myself coding less and less because it was not so much fun anymore.
At the end of december 2019 the first version of Enigma was almost ready. It could calculate and draw a chart, work with configurations and used a database to store the essential information.
But I strongly felt the need for an alternative.
So I made a new comparison. Then I found that JavaFX was not dead. This was a big surprise for me. I expected it to slowly die after Oracle pulled the plug, but the open source community decided differently. JavaFX is alive and kicking and the support by Gluon works very well. Several new releases have been published while I was working with Free Pascal.
So I decided to return to Java. I was delighted with the efficiency of intelliJ and started coding. About 11 weeks later I almost completely rebuilt the codebase as writtin in Free Pascal. I am sure that future development will be fast as I’m using the perfect tools ànd coding is again fun for me.
I expect to have a first (beta) version, which will be 2020.1, available in May this year.
A new sourceset will then be posted at GitHub.
Category: Technical decisions
Some progress…
I knew that Free Pascal (FP) differed from the Java environment I used to work in before my recent retirement. But it still took me some efforts to adapt. The main problem I had was using automated testing. FP has excellent tools for unit testing, like FPC which I use. However, unit testing requires the testing of only one component and not any related components. To do so in a Java world, you would use mocks or fakes. FP has no viable solution for mocks, so I used fakes. That did not work out. Fakes require the use of interfaces (object interfaces, not just the unit interfaces). And good solutions use Dependency Injection (DI), which is not available in FP but you can mimic it using the Factory pattern. I ended up with too many components, interfaces and fakes, to be maintainable. So I skipped Fakes, I skipped object interfaces (at least as a default approach), I skipped factories, and I ended up with nice clean objects. In Java you would call it a POJO: Plain Old Java Object, in Pascal that would probably be a POPO 🙂 )
That means I cannot always use unit testing in the strict sense. And obviously, I need to test as much as possible to get early feedback on any error I make and to prevent bugs. I used Integration tests for all back-end functionality. I use FPC to implement these tests, so technically they start as a unit test but the functionality is different. The integration tests work with a greenfield for the database which is populated before a range of tests start. This approach appears to be useful.
Finishing release 0.6 will still take a few months but I hope to have it available, including documentation, user manual and all tests at the start of 2020.
Automated testing
Release 0.2 is finished and I started working on release 0.3. I will push the resulting code to GitLab so it will be available to anyone interested.
Release 0.3 will focus on refactoring the current application. Part of the refactoring will be the use of interfaces. Not the interface-parts of the units but interfaces for the objects. These interfaces will help in making the objects more loosely-coupled but also be a great help in automatically testing the code.
Free Pascal supports unit testing but it does not support mocking objects. There is a mock-tool but it is pretty old and not supported anymore. As an alternative, I will use Fake objects; in short, ‘Fakes’. A Fake implements the same interface as the original object but gives hardcoded answers instead of the real thing. If you write a unit test for an object that uses the results from another object, which again will have its own dependencies, you might end up testing a whole range of objects instead of the single object. That is where Fakes come in. They replace the objects that are not tested in the current unit test and make it possible to test just one class per unit test.
After I finished the code of release 0.3 you will be able to check the code, including the Fakes, yourself.
Free Pascal vs Delphi
Shortly after I started working on Enigma using Free Pascal, a free version of Delphi came available. Embarcadero introduced a community edition of Delphi. You can use this edition if your yearly profit does not exceed $ 5000. For the Engima project that is an easy condition as there will be no profit whatsoever. The community edition is a welcome addition to the paid version that will cost you several thousands of dollars.
It is a nice opportunity but I decided to stick to Free Pascal. Why? I do not believe the official Delphi version has essential advantages compared to Free Pascal. The only advantage I can see is Firemonkey, visual components for Android, that are currently not available in Free Pascal. But as I will focus on a Windows version, for now, this is not an important advantage. Free Pascal, however, does have advantages compared to Delphi, mainly its support for Linux. And more importantly: you can rest assured that Free Pascal will be available for some time and will remain free. There is no guarantee that Embarcadero will continue the community edition forever. I still remember the end days of Borland, when a free version of Delphi was discontinued.
So I will place my bets on Fee Pascal and Lazarus.
Enigma: A new project for astrology software
Enigma is a new software project, aimed at astrological research. I just started it and there is not anything to show yet. But if you are interested you might want to follow my progress.
I have been experimenting with software for astrology for a long time and I used quite some programming languages and techniques in the process. Some of these approaches were reasonably fruitful and some were dead ends. But none of them was sufficiently effective for building the kind of application I wanted to create.
I decided to start from scratch again, this time ignoring new and sexy techniques and focusing on astrological functionality. And I will describe my progress in this blog.
This blog is aimed at other developers of astrology software. It will not be useful for astrologers who do not program. And it will also make no sense to developers that are not versed in astrology. I suppose I will have a pretty small audience…
A new start
I terminated all my previous efforts and started again. This time with Free Pascal. The main reason is the support for RAD; it allows me to build User Interfaces in an effective way. It also runs natively, resulting in speedy performance. I need that because Enigma will support analyzing large amounts of charts.
I will use the following techniques:
- Free Pascal and the Lazarus IDE for coding.
- SQLite as the database.
- Swiss Ephemeris for the majority of the astronomical calculations.
- FPCUnit for unit testing.
- JSON for exporting data.
- GitLab as the code repository.
Back to Pascal
I am returning to Pascal and this was my most important decision.
I used Pascal and similar languages like Delphi and Modula-2 for years but that was a long time ago.
Computer programming became my profession and that meant I had to learn some other languages; the major one being Java. I liked Java very much; I used it for my day job and it only made sense to use the same language for my private projects.
But Enigma is a native application and that is not something Java is very good at. OK, you can use Swing or JavaFX. But Swing looks pretty awkward – you can change that but only with a lot of effort – and Oracle has abandoned its support for JavaFX: it will not be part of the upcoming Java 11 release.
Besides Swing and JavaFX, I also tried a solution with a backend written in Kotlin and booted with KTor, a JavaScript UI (using Vue.js), and Elektron to wrap everything in an application. It works but it creates extremely large executables – 100+ Mb for Hello World – and it also involved a lot of JavaScript related techniques. Vue.js is probably the most straightforward solution to a JavaScript frontend (compared with Angular and React) but it still required a lot of effort and additional tools to get a running environment. The JavaScript world changes extremely fast and you need to change along because there are so many dependencies on browsers and additional tools that also change rapidly. How long will Vue.js last?
What to do?
I needed a pragmatic solution and I had some essential requirements.
- A language should support Object Orientation.
- It should support Unit testing.
- A reasonable number of developers must be using it.
- It should be affordable as my Enigma is non-commercial.
- It should support an effective way of building a UI.
These were Must Haves. Additionally, there were some Should Haves: preferably no large runtime solution to ship, the ability to access existing compiled libraries without using a port. And of course, the language should be fun to work with.
Free Pascal and Lazarus to the rescue
Based on my Must Haves, two solutions were available. C# combined with the free version of Visual Studio and Free Pascal with the Lazarus IDE. I used C# once and I was impressed with the language and with the RAD support in Visual Studio. But C# does not fulfill one of the Should Haves: it required the installation of the .Net runtime environment.
Free Pascal and Lazarus, however, do fulfill all Must Haves and all Should Haves. Object Orientation is optional but fully implemented, Unit testing is available, looking at the Tiobe index it still has a reasonable amount of users – about 1% – and the community is certainly very active. It is very affordable (free) and it has excellent support for building a UI based on RAD. Also, the Should Haves are being covered: no additional runtime, easy access to existing libraries, and it sure is fun to work with this environment.
I decided to switch to Free Pascal and Lazarus.
Open Source
Enigma will be free and open source. I consider this important for research software: make everything controllable.
After a 0.0 version is finished I will push the code to GitLab where you can obtain a copy. This version will not be available for regular download: I will make only the source available.
I expect to need at least a year before I can deliver a first more or less useful version for end users.