Archive

Archive for October, 2016

The Lazarus conflict, what happened

October 31, 2016 12 comments

Apparently my post about Lazarus and the way I was treated hit a nerve. And in true Lazarus forum tradition, the most loud of my critics is also those that know little or nothing about the case (yet paradoxically also one that is at its epicenter). But I’m getting a bit tired of this so this post is me drawing a line in the sand. People can make up their own minds if I have acted wrong, but I’m putting this behind me. So here is the full story and that should be the end of it.

What I truly feel about FPC and Lazarus

First let me underline that FPC and Lazarus are fantastic products. Both represents a herculean effort – and I applaud and give my respect to the key members that have built this from scratch. It is custom to pay your respect when a fellow student graduate with flying colors, and to stand up and applaud when a scholar or scientist has his research verified and papers published. And the core developers behind Freepascal and the Lazarus IDE deserves both. I have no problem with FreePascal or Lazarus, but it’s clear that some of the members on their boards have a problem with me.

During FreePascal and Lazarus long voyage, the core developers have done a remarkable thing: they have written everything themselves. Rather than falling for the temptation of “borrowing” a little here and there, these guys have run a tight ship. Considering the size of the codebase and the amount insight and skill Freepacal and Lazarus represents – that is so impressive that any object pascal developer cannot but show admiration for these achievements.

But the conflict did not start with Lazarus or Freepascal, but with a nickel & dime operation in Greece: Pilot Logic.

GPL violations

A couple of years ago I had a look at Pilot Logic’s fork of Lazarus. Not really my taste, but I was impressed by the overwhelming amount of libraries and packages they offered. Wow, these guys must work 24/7 to produce so much code! And the libraries were of high quality as well.

Building a large repository of code is not hard if you ignore laws, regulations and morality

Building a large repository of code is not hard if you ignore laws, regulations and morality

Then suddenly I realized that I was looking at my own code. They had taken one of my libraries and blatantly renamed every class, data type and function. But what really pissed me off was that they also deleted the license in the header of every unit and replaced it with their own! My name was completely erased from my own codebase, but more importantly, so was the modified license. A license modified so that my name and the files could be used by anyone – but never altered. Bugfixes could be committed, but the library was to remain as it was unless you had written permission from yours truly to do otherwise.

What Pilot Logic had done was not just theft, but to gravely misrepresent someone elses intellectual property. And those units were never free to be altered like already stated. But everyone that has asked me to use the code in their products, commercial or otherwise, have gotten a positive reply. Just ask and leave the header-text alone. That’s not too much to ask for a library that took me so long to write.

But I would never have agreed to the utter re-branding of my code. If you look at other projects, like the Jedi code library and components – they have done a pretty great job by simply asking. Why should this be so hard for Pilot Logic when everyone else seems to manage just fine? Most people are kind and open if you just show them ordinary, universal respect. You don’t take someone elses work, brand it as your own, adapt it to your codebase – and then blatantly delete/ignore their complaints; Nor do you finish by blocking the original authors from the forum so their voice is silenced. That is the act of cowards and thieves.

be careful when you cast out the devil, lest you cast out the best in you

But it didn’t stop there, turned out they had done the same with libraries and code belonging to two of my best friends. I was quite shocked to learn that both of them had registered with Pilot Logic’s web forum earlier, posted their complaints, but were subjected to the same treatment: verbal abuse followed by their accounts blocked.

A pattern started to emerge here. If something occurs once, it can be an accident. Twice, we call that a co-incidence (from the latin word con; meaning “with”). But three times? My gut feeling told me there was more to this than meets the eye.

To see if we were the only group of people who has been subjected to this treatment after having their code rebranded – we decided to publicly ask other Delphi developers. The response was overwhelming. On Delphi Developer (Facebook group with 5000+ developers) alone more than 30 coders voiced more or less the same story: first their code was taken, re-formated, all licenses and even their names scrubbed clean, and any complaints they had made to Pilot Logic was ignored followed by a ban from their forums.

Glenn Dufke which is one of Delphi Developer’s moderators together with Peter Dunne decided he had enough. He works with data analysis and is very good at what he does. He basically took the CodeTyphon codebase and its libraries and ran the whole thing through a file analysis program, comparing against a truck-load of Delphi libraries.

The result was beyond any reasonable doubt. Pilot Logic had pretty much taken code from every popular open-source Delphi project out there, re-branded it and presented it as their own. The same story kept on coming: complaints deleted, emails ignored and forum accounts blocked.

Stolen Firemonkey code

The biggest mistake Pilot Logic had done was to include code from VGScene. This product is no longer available because Embarcadero bought that framework lock, stock and barrel. They also hired the author. The result? Oh nothing big, just that framework we call Firemonkey today! VGScene and all its code was never open-source, it was a commercial product with a copyright clause carved in stone. No human being capable of reading English could possibly misunderstand the legal status for VGScene, neither before or after it was sold to Embarcadero. Every line of code in VGScene belongs to them.

VGScene here running on OS X. Today its called Firemonkey

VGScene here running on OS X. Today its called Firemonkey

The only people who can legally use VGScene today, are those who bought the initial product when it was on sale. I actually own a legal copy myself. But I sure as shit would never even consider rebranding it as my own. Besides, why go for the prototype when you can use the finished product in Delphi?

Yet here was Pilot-Logic using and distributing Embarcadero code. And they knew perfectly well that VGScene is Embarcadero’s property. That is not just theft, but a very real, very tangible threat to the whole Freepascal and Lazarus community. Even if FPC and Lazarus are clean as a whistle (which they are), legal proceedings of this nature can go on for years. And it would cost a fortune regardless that Codetyphon is a fork and not Lazarus itself. Codetyphon is not Lazarus, but judges and lawyers might not make that distinction.

If Embarcadero found out about this and decided to enforce their legal rights, Freepascal and Lazarus could find themselves in the proverbial eye of a real typhoon; a legal one; all of it thanks to Pilot Logic’s disregard for laws and individual programmers work. They should change their name to Pirate Logic. And to be honest, Freepascal and Lazarus would not survive a legal battle with Embarcadero. Development would have to cease until the differences between the products had been established.

We also found code from GLScene in their codebase, code written by Eric Grange. Eric was previously in a legal case against Embarcadero since Firemonkey, which is VGScene on steroids, contained code copied straight out of GLScene. It was code Eric had written (he was a part of the GLScene project), and thus – Embarcadero found themselves shipping code they had no legal right to use. Turned out the VGScene author had copied quite a lot out of GLScene and rebranded it. Just like Pilot Logic had done.

So the threat to FPC and Lazarus was very real. Had Embarcadero known about this they would have shut down Pilot Logic completely in a matter of days, and the next logical legal step would have been a source-code analysis of both Lazarus, Freepascal and associated forks.

A great database

A great database

I should perhaps mention that the memory-mapped file classes that is/was distributed in the user library contribution section of FPC is actually pirated as well. It belongs to DBISAM and was written by Elevate software. I know this because I own a source-code licenses for this old gem. My favorite database engine that I used daily for many years. When we did a procedure-by-procedure comparison there was no doubt left: this was stolen code.

But again, it was not FPC or the Lazarus organization that had stolen it, but rather a third-party (individual in this case). But that doesn’t change the fact that it would have been FPC/Lazarus that would suffer the consequences. If I have links to pirated software on my website, I am in fact contributing to piracy regardless of whether im aware of it or not.

And this type of conflict was exactly what I wanted to avoid. Not because I represent any aspect of either FPC or Lazarus – but because “Pirate Logic” had bloody taken my code and mangled it! I also understand the value of both Freepascal and Lazarus, and recognize how important they are for object pascal in general. The world would be a much darker place without FPC and Lazarus. And I never tried to represent the Freepascal organization in any way. I don’t even know where accusations like that come from (although I have a pretty good idea who planted it).

So myself and others set out to inform the Lazarus community about Pirate Logic‘s disregard for intellectual property, how they misrepresent code written by others – and we also supplied concrete evidence for all of it.

We never confronted Pilot Logic on behalf of anyone but ourselves, regarding our code and how it had been renamed, rebranded and had both our names and its license removed. The fact that pieces of VGScene had been located in the codebase should light a fire under any programmers behind – because that puts you in direct conflict with Embarcadero.

And the more we investigated and compared packages, the more license violations we found. In the end we had to inform someone about this – otherwise Lazarus and FPC could end up taking the rap for something they didn’t do. So we never blew the whistle on this to cause harm, we did this so that FPC and Lazarus could take the necessary steps to avoid harm.

Kill the messenger

I posted a clear-cut warning on Pilot Logic’s forums that I would contact a lawyer if my code was not immediately removed; And I was prepared to do this. It was infuriating because Pilot Logic showed no respect for the hours, weeks and months we had invested in our work. And I mean normal human respect and decency. It costs nothing, it opens doors and it builds communities.

rogears_logo_colour_whitebackground-squarish-900pxAs a comparison, take a look at Remobjects; Remobjects SDK contains a lot of open-source code. And Remobjects as a company have deployed this without breaking a single law or license agreement. They just leave the units unaltered and then build components around it. Like their Indy channels, BPX server channel, Synapse channels and a few others I don’t remember right now. Remobjects have respected the licenses of each library down to the letter. That way they can deliver the functionality without re-inventing the wheel and at the same time respect the original author(s) wishes. Remobjects is a perfect example of how you deploy open source correctly. Pirate Logic is the exact opposite. Their modus operandi is how you destroy communities, break the law and piss people off.

I mean, would you go to a bookstore and buy a novel, then scan the pages, rename the characters, change the title – and then publish it under your name? No. That’s not even something you would do with books that are free! Sooner or later someone will recognize it and you face the consequences.

You might not know this but the most open-source licenses are very well protected. The Mozilla foundation, Apache foundation and Gnu Linux foundation offer free legal support to programmers when their licenses have been broken. Because any breach of such a license is not just unfair to the author, to you and me, it indirectly represents a threat to open source in general. If one get’s away with it – more will follow. This is why the Linux foundation support developers rights with an iron fist.

And with the evidence, analysis and 1:1 examples of piracy we had collected, Pilot Logic wouldn’t stand a chance.

Defending FPC and Lazarus

With the complete lack of respect demonstrated by Pilot Logic, I was both angry and frustrated at the same time. Angry about their behavior but also worried for Freepascal and Lazarus. It would be devestating if these got entangled in a lawsuit because some guys in Greece decided to use code belonging to Embarcadero, Elevate Software and all the developers who got their code kidnapped and rebranded. It really is a textbook example of how to kill both open source as a concept and international law at the same time.

But the worst part was that a fork of Lazarus was now shipping with Firemonkey code inside it. That is not just illegal in any civilized part of the world, it is disrespectful and had the potential to cause serious damage to Freepascal and Lazarus, who would risk becoming guilty by association. Even if Lazarus and Freepascal is clean and follow the rules (which they do. The maintainers of both compiler and IDE have done a great job keeping things clean), there is no denying that there is a lot of code moving between Lazarus and CodeTyphon. Lazarus could end up using copyrighted code without even being aware that it is stolen to begin with.

Lazarus: write once, crash everywhere

Lazarus: write once, crash everywhere (just kidding!)

When I posted the information we had found, I expected the Lazarus and FPC community to be thankful. I know I would be very happy if someone pointed out to me that one of my suppliers was dealing in stolen goods. Because then I could take steps to exclude that code until its origin was clearly identified. I would either implement something similar from scratch, or (drumroll) contact the original author asking for his or her’s permission. Which is what Pirate Logic should have done in the first place!

Instead, they decided to kill the messenger. I was branded a devil (literally) and accused of inciting a “civil war” in the object pascal community. I kid you not, those were the words they used: “a civil war”. So instead of being thankful that we blew the whistle on the dodgy practices over at Pilot Logic and thus helped them avoid a potential showstopper — they turned right around and made us scapegoats. Like it was our fault that these crimes had been committed!

That’s like blaming the red-cross for war; or Greenpeace for whaling because after all, they were there. So yes let us quickly find someone to blame so we can continue to live in la-la land where weird-ass conspiracy theories and ego-massage is the spice of life.

Did I just walk into a cartoon?

I was shell-shocked at the response. After 2-3 full pages of accusations I just left the forum. Apparently they kept it going for quite some time, I never really went back to check. This was a side of the object pascal community I had never experienced before. People so openly paranoid and desperate to shift blame that they forgot all about who and what we blew the whistle on. Yet they managed to twist the whole ordeal into being about them. Sorry guys, but it was not about you – but about Pilot Logic.

The next day they issued a public warning about a possible breach of licenses (or words to that effect) in Codetyphon’s codebase. So after treating both me, Peter and Glenn as crap for helping them out, they still took advantage of the information and used it to save their sorry asses.

The number of lies being told on the Lazarus forum about me, especially by one individual which is at the epicenter of all this drama, has reached a height where Lazarus users have started to question this person’s credibility (he is one of the administrators). The nature of lying is that it can only survive through more lies. Which is where this individual finds himself today. And clearly lacking the balls and spine to admit his mistakes, he has painted himself into a corner. And I have you right where I want you – because we made time-stamped and digitally signed PDF’s of the original threads. Both on Pirate Logic’s messageboard and the Lazarus forums. So keep it up. Perhaps those PDF’s will find their way to Google+, Facebook and every syndication channel you can think of. What will you do then? Accuse me of being an alien? Or continue with the mentally ill claim that I am in fact an undercover Microsoft employee out to destroy object pascal.

You guys are so messed up I dont even know where to start.

End of story

Loke, ancient of days, son of heaven and hell

Loke, ancient of days, king of Niflheimr, bringer of light. Lucifer the morning star.

Well, that’s all folks. If you were hoping for more excitement or drama, there really is nothing to find here. The drama sadly occurred on the Lazarus forum with a handful of members whipping the whole thing into a frenzy. A storm in a glass of water was we say in Norway.

This whole case should have been a footnote. We informed the forum of what was taking place, and expected a simple “thanks, we will look into it” in return. Nothing more, nothing less. It’s like “oh by the way there is a storm on the way, you better cover up your garden furniture and get that sweet grill into the garage“. I have neighbours that tell me that, and I do the same with them. We look out for each other.

And the same applies in Delphi. When I find a crack or some website with serial numbers, I send it to the company that is being robbed. Last one I helped out was PaxCompiler. Not because I expected to get anything in return, but because as a community we depend on people helping us out. Kindness costs nothing. And stuff like this has to be dealth with head on.

Not in my wildest dreams (and im pretty creative) would I have imagined the shit-fest that followed on the Lazarus forums, or how nasty and personally insulting this group would become. Everyone warned me about Lazarus, but I didn’t believe them. I am positive, I always give people the benefit of the doubt. I always chose to focus on the best outcome. But when that is disproven, I never give them a chance again. This is an old codex of living, probably out of date by centuries – but it’s a healthy one. Always think positive. But when you face negativity, deal with it.

You, the reader, are free to believe what you want. I have now told my side of this story – and I am putting the whole circus behind me. I actually did that a long time ago, until I was told that someone quit their job because the boss is one of my friends. This individual, who is also a Lazarus admin, used my name as an excuse to cover up his incompetence. And this was the same guy that whipped up this shit fest to begin with. So he clearly has an axe to grind with me.

But hey — if you so desperately need someone to blame for your own mess, I’ll play along. I have no problem being the devil in the deck. Of-course people talk, both about me and others. Just like we talk. People do that. And my blog have articles that deal with subjects most people don’t touch out of fear of stigmata. If everyone liked me I would be worried, because then you can’t trust anyone. I am under no illusion about the facts of life. But I am secure in my own self enough to deal with these subjects, and I have no problem taking the heat for it – as long as it is just and fair.

If I make a mistake I apologize, publicly. That is what you do when you have made a mistake. You don’t try to wiggle your way out like a snake by blaming others. You stand for what you have done. And I expect nothing less from others.

A healthy eco-system, be it natural or digital, depends more on those that dare deal with and write about the negative sides as well as the positive, more so than those who pretend everything is ok. This is also the distinction between the Delphi community and the Lazarus community. The Delphi community is much better at dealing with things like this in a civilized manner. Perhaps Delphi users are more willing to grab the bull by the horns because we make a living from object pascal and have more to lose if piracy is left to fester.

But not everyone is negative over at the Lazarus forums, of course not! Most are kind, easy-going and good people. But there are a handful of individuals that does more harm to the organization than good. One of them is an admin that in my view – is abusing his position and enjoy bossing people around far too much. But that’s for the FPC and Lazarus project leaders to sort out.

We should be thankful for the devil, because his job is to make sure life doesn’t stagnate. All good stories have a devil in it. In fact: be careful when you cast out the devil, lest you cast out the best in you.

And it’s Loke by the way, I am Norwegian after all.

Building a kiosk system with Smart Mobile Studio and ARM SoC

October 29, 2016 2 comments
Kiosk systems comes in all shapes and sizes

Kiosk systems comes in all shapes and sizes

Not sure how to define a kiosk system, but it would perhaps be something like “a multimedia driven information booth with user interaction allowed”? Most kiosk systems run your application in full-screen, have a touch capable display(some also have keypad or a full keyboard). Occationally you spot some mouse devices, but that is typically “homebrew”. We can do better.

You really want as little exposed hardware as possible. A mouse just screams “please cut me, cut me now!” to any teenager within miles, and it wouldn’t last an hour at a public library or museum. So touch screens – preferably with a secondary protective layer (an extra plate of thin plastic to protect the screen) is the way to go for public service machines.

Ok, lets look at the demographic for potential customers. This is something you should always do before starting a new (commercial) project. You should also check out the competition and find and angle where you have the advantage, where you can compete. It can sometimes be as simple as good service, better docs or a more friendly user interface. There are a ton of really bad software out there that survives and sells just because their service department does an outstanding job. So don’t limit your thinking to purely technical excellence (like we programmers typically do). Look at it from all angles. Under-do the competition is a catch phrase coined by 37signals in their book Rework (a great book by the way); it simply means: make sure the basic functionality is extremely well made and solid. Focus on the basic functionality rather than playing catch-up with every new “thing” on the market.

Ok, here are some examples of where you would offer your services and sell your kiosk systems:

  • Ticket booths for public offices
  • Ticket booths for pharmacies
  • Information booths for physicians and hospitals
  • City bicycle rental
  • Airport information stalls
  • Museum info booth
  • Library inventory booth
  • Paint color-mixers for hardware stores

I could go on forever, there are thousands of potential customers.

Hardware

The hardware I am using is the Raspberry PI 3 model b. This is probably one of the most affordable embedded platforms you can buy. And model 3 packs quite a punch to be honest. You could buy one of the clones like the Banana PI (there is also an orange pi or whatever it’s called) and save a buck or two – but seriously: at $35 a pop for the original I would honestly not bother risking it. There are subtle incompatibilities between the clones and the real deal – so you could end up “saving the pennies while wasting the bills” as they say. The way to save money on hardware is to buy in bulk. End of story.

The fantastic Raspberry PI 3

The fantastic Raspberry PI 3

Next, you need a touch screen. The size is naturally only limited by the size of the booth and your budget. For this article series I will be using a small 10″ form-factor. I can recommend a visit to AliExpress.com, never had any problems ordering from them. But stay away from Wish and Geek – these websites will lie, steal and sell their own grandmother just to make a buck. I have nothing but bad experienced with them (like never getting what you ordered). So stick with AliExpress or even better RS components.

display

Touch screens have become ridicules cheap lately

If you have $5 to spare, please buy a remote control. Being able to stop, restart or display an “admin panel” purely by clicking a button on a remote (that only you or your client have access to) will save you so much razzle. You don’t want to mess about with

Besides. Once you know how to code your own set-top-box like I’m showing you now, why not go all out and create your own movie player? Chrome can play pretty much everything out there – and you can get plugins for VLC. Plex eay your heart out!

I have actually had my own NAS running for quite some time now, coded completely in Smart Pascal. And believe you me, its much better than many of the commercial products I see out there. If you are interested in contracting me for projects, contact Quartex Components.

Anyways, what you can do with a remote control is only limited by your imagination. But above all it just looks cool. In fact, buy it because it looks cool and always have sunglasses on when you click the admin button.

This set me back a whopping $4 from Banggood.com!

This set me back a whopping $4 from Banggood.com!

Linux for HTML5?

fullpageosBut now you are thinking: Smart compiles for JavaScript, how the hell are we going to display that full-screen? Do we have to first load the Linux desktop and then manually start a browser?

The answere is: nope!

Our operative system will be a modified version of Debian, one especially tailored for full-screen, HTML5 kiosk displays. And it so happens that there are quite a few such distributions on the market. Most of them completely free as well. JavaScript is after all the leading programming language of our time. As much as 50% of all software being written on this planet right now, is written in JavaScript. We didn’t set out to create Smart Mobile Studio just for the hell of it, but rather because we knew this was going to happen all the way back in 2010. It was inevitable and the factors in the market (and socially) all pointed to the same.

For our Smart Pascal kiosk system we will be using FullPageOS which basically skips the whole desktop thingy and boots directly into Chrome in full-screen. No desktop, no “oh damn the user just minimized the browser window“, just chromium rendering our awesome code directly to the frame-buffer. But you still have Linux ticking away beneath the hood with all the perks and power that represents.

So jump over to Github and download the latest binaries here: FullPageOS. I have also setup a mirror over at Quartex Components. So should for some reason github spontaneously burst into flames, I got you covered!

Next, we will be modifying the distribution slightly. We want to start node.js as a service when the device starts. The easiest way of doing that is to install something called PM2, which also gives you clustering capabilities and drill-down analysis at the same time.

PM2 is node.js equivalent to Microsoft windows service console. It gives you the ability to define if a node.js program should run as a service, if it should be re-started on a crash, logging, distribution – and much more.

We will just be using the automatic restart feature in this tutorial, but I have to tell you, PM2 is a powerful piece of engineering capable of a lot more than that. The most important being that it adds clustering capabilities to your node.js programs if you need it.

If you tell PM2 to run your Smart Pascal server in cluster mode, it will utilize all the cores your CPU has to offer. This is imperative since the JavaScript virtual machine is single threaded, event driven and async by nature.

You can also setup a traditional network cluster, with X number of physical devices dealing with your payload, while a central server act as a dispatcher delegating tasks in good old round-robin style. And the best part? You don’t even have to change a single line of your code to use this. PM2 takes care of everything for you, clustering mode is just a command-line switch. Now that is awesome if you ask me.

PM2 makes clustering and process monitoring a snap. You can even check out the state of your back-end node processes remotely

PM2 makes clustering and process monitoring a snap. You can even check out the state of your back-end node processes remotely via a secondary fancy HTML5 dashboard

You can check out PM2 here: http://pm2.keymetrics.io/. We will be installing that after we have prototyped our server -because during development you want errors to surface so they can be fixed.

Smart Mobile Studio

photoNeedless to say you are not in Kansas any more and Delphi is not really suited for this line of work. Object Pascal and C++ is great for a lot of things, from desktop applications to large-scale eco-systems. But for IOT the full might of Delphi or C++ builder is quite frankly overkill. In this part of the IT forest, python, node.js and bash rule supreme.

So whip out your trusty copy of Smart Mobile Studio and get ready to make those ARM cpu cores purr like a kitten!

The code thing

Since I work on the Smart Pascal RTL, we often have this problem where I blog about or demonstrate code that is not yet publicly available. The reason I blog about new features is naturally to show people what is going on, what they can expect from the next update and so forth.

For this project I will try to avoid non-released features as much as possible so everyone can execute and work with the code. But I will also include code from the new RTL whenever there are no options.

Just keep in mind that any RTL code is copyright. You are not allowed to use it without owning a proper license.

When this tutorial is done you will have a working kiosk system. What media or features you want to deliver is up to you, I’m just here to get you going 🙂

The architecture

Right! With the Linux distribution, node.js and PM2 taken care of, let’s look at the software architecture. What we are going to do is to divide our kiosk system into two parts. Two applications.

  1. A node.js server
    • database access
    • image and media serving
    • filesystem access
  2. A visual smart mobile user interface
    • Menu system
    • User interaction
    • Displaying information
    • Fancy CSS3 effects

Node.js is very different from the browser JSVM. First of all it executes with the same level of access to the filesystem, network, pipes, threading etc. as a normal executable. It basically gives you the same features Freepascal or Delphi would give you. Node.js is not sandboxed like the browser’s JSVM is. There are no restriction on database size, file size or anything like that.

This means that by dividing our application architecture into two parts, we get to enjoy the best of both worlds. We will isolate any low-level stuff in our node.js server (and more importantly: access to the content our booth is going to display). So our visual application needs only care about presenting information and keeping a dialog going with the node.js backend.

By using Chromium as our browser we ensure that the rendering process makes use of the GPU, which is quite important for embedded devices. HTML5 is demanding and rendering it all via the CPU alone would, well, suck.

But our simple architecture allows us to put our application logic in the front-end, and then reduce our node.js backend to a simple command server, almost like a DLL or library. But with perks. Loads of perks.

This model also helps us to abstract the display from changes or updates to the back-end server. The display interface could not care less if you are using sqlite as your database or a $200.000 a month Oracle monster. It doesn’t need to know where the server obtains images, music or files. All it needs to know is the commands and response codes.

It also means we can fragment and do clustering. If you have, say, between 50-100 booths operating on the same network, we could in fact push the node.js server to a dedicated server machine. The clients running on the Raspberry PI wont know the difference. Nor would they care as long as they can connect and get the response they need.

 

Developing on Windows

Before we start assembling the parts and jousting with Linux, I want to teach you a little trick. When people get a Raspberry PI they tend to do changes to their in the worst possible way: Namely to either use a second USB stick to move files between their PC and the RPI, or (better) install samba so they can copy files over the network.

QEmu makes it a bit easier developing for the PI

QEmu makes it a bit easier developing for the PI

Both solutions are “ok”, but they are time-consuming. And after having copied your Smart Mobile Studio compiled code over for the 78’th time, odds are your frustration level will be through the roof (yes we have all made this mistake at some point).

The trick is to run Raspbian on Windows through qemu. Just like you would run Windows or Linux through VMWare or similar products, you can actually do the same with Raspberry PI (although only model 2b is supported to my knowledge).

You can download the whole system image from Sourceforge here:
https://sourceforge.net/projects/rpiqemuwindows/

Alternatively, I did a mirror of the distribution and you can download that from Quartex Components, right here (but please use Sourceforge first, this link is only for emergencies like if the owner is kidnapped by aliens or moves to Tibet where he intends to live as a goat or something): QuartexHub-Public

Once downloaded, just unzip to whatever location you like.

 

Just click the "run.bat" file and Raspberry PI will run on your desktop

Could not be simpler to use

Notice the run.bat file? This simply starts qemu for ARM and loads the operative system disk image. The disk image is stored inside the qemu folder, cleverly disguised as:

2012-07-15-wheezy-raspbian.img

Here is the full file-list inside the folder. You don’t have to understand or know what this is to use it. Once inside Raspbian you can install Samba (google it, its out of scope for this article to explain) so you can share files between your Windows host and the QEMU Linux installation.

QEmu is not the fastest horse in the stable so to speak, but it's highly flexible and free. So.. La-di-da

QEmu is not the fastest horse in the stable, but it’s super flexible and free!

Homework

No I didnt see you playing with your sockets SIR!

No I didnt see you playing with your websockets again SIR!

In the next installment of this article series we will create a websocket server for nodejs and a then use the websocket client in the VJL (the Smart Pascal run-time library) to communicate with it.

We will be sending whole objects over the wire, which sounds very complex and hard, but it’s almost a one-liner under Smart. All JavaScript objects can be serialized to JSON and un-serialized back to an instance on the other side, so this is a piece of cake.

The main job will be to establish a simple, fast, lightweight ASYNC protocol that ensures a snappy and responsive user-interface.

We will also dig into TFileStream which is exclusive for node.js and last but not least, use SQLite for our database needs (Raspberry PI is an embedded system after all, so resources are sparse).

When the coding is done we will perform the required changes to the Linux distribution, hook up the hardware and feel the thrill of having constructed our very own remote-controlled kiosk system!

Your homework assignment is to install node.js on your Windows PC, create a new node.js project in Smart Mobile Studio and look at the API units. You will find the node.js API units under $RTL\NodeJS\ (check links created by our installer in the start-menu program group).

In the next update of Smart Mobile Studio you will have plenty of high-level classes dealing with all that low-level stuff. But getting to know the classes and datastructures node.js expose beneath it all is very useful. It will help you build better node.js servers later on.

Have a good weekend!

Apparently I am the devil

October 27, 2016 12 comments

This has been quite a week for me. Apparently my post on C# hit a nerve and I have so far gotten around 34 hate-mails. That’s a first even for me. I have been out a rainy day before as we say in Norway, but hate mail over programming? If facts hurt you that much then please seek professional help. With great haste I might add.

Jon is the devil

But the biggest shock was getting a phone-call today. From a friend of mine who runs a Delphi company. They have recently started to use Smart Mobile Studio for some light mobile clients, projects where Delphi would be overkill or to demanding.

A while back he hired a guy from the FPC / Lazarus team (both products that I love by the way!). When this coder, who shall remain anonymous, found out I was a personal friend on Facebook — he bloody went and quit his job!

Just way to go! Group-hug, starbucks on the house and pat on the back

Just way to go! Group-hug, starbucks on the house and pat on the back

Apparently he could not find it in his heart to work for a company that regarded me as a friend. Because, in his words, I was lucifer himself. Why? Because I pose (in this deranged individual’s mind) a threat to Freepascal and all the work they had done.

I’m not sure what to even respond to this. My natural instinct is to lay down on the floor and laugh until I cant feel my legs, but at the same time I feel a bit sad. Sad that grown men, adults, people who probably pretend to be role models for their kids, can even do shit like this.

That FPC forum again

The freepascal community is widely known as the most unfriendly community in the history of mankind, but this particular case really is the mother-load of insanity. We are bordering on fundamentalism here. You are one AK-47 away from being the first hands on pascal terrorist. With a manifest written in pascal of course. Death to the JavaScript infidels! Node.js must die! Did you see the fangs when Jon smiled? He’s a witch!

Sadly, my involvement with Freepascal and Lazarus is insignificant at best. But they dont like people who hit back when bullied, and this has festered into the conspiracy nutters they represent today.

I once had plans to help freepascal by writing an alternative IDE. Something roughly 100+ other developers also wanted by the way. I also helped out by submitting code to get special folders on Windows, Linux and Unix through a common set of functions. And that’s about the extent to my involvement with their codebase.

Quartex IDE uses both smsc and fpc as its compiler. I never finished it because the fpc guys were utter nutballs about it. But it works, and it works very well!

Quartex IDE uses both smsc and fpc as its compiler. I never finished it because the fpc guys were utter nutballs about it. But it works, and it works very well!

I also warned them, together with two others, both respected members of the Delphi community, that a popular fork of Lazarus was breaking every possible GPL rule known to mankind (!) — And I did this in order to protect Lazarus/fpc from getting caught in the middle of a potential lawsuit.

If protecting Lazarus from harm is a diabolical, hellish act of evil – then I guess am guilty as charged. And I would do it again because Freepascal and Lazarus deserves to be protected. It is a cornerstone of the pascal community.  It’s only so damn sad that many of its representatives (especially the self-proclaimed ones who couldn’t code a compiler if their life depended on it) practically molest and insult new users for no good reason. So much so that people avoid FPC and Lazarus because of it.

If you dont agree with me then you are evil! Bu frikkin hu!

I heard he said that she said that maybe he meant that .. oh for the love of god pick up the phone and get the facts!

But people quitting their job because I supposedly am Lucifer incarnate, that’s a new high. Or low, or whatever comes natural. Coming face to face with mental illness on this scale is new to me, so I need some time to digest this.

But dude, seek help. Professional help. Call your doctor and get a huge glass of Valium, take two pills and contemplate every possible meaning of the phrase “social refactoring“.

You need to set some serious break points in your reasoning. Because quitting your day job over a misunderstanding on a web-forum, that my friend is reason in ruin.

You see, if I was full of shit; If I produced crap code, or indeed – if my predictions and analysis of trends were wrong (which they rarely are) – then you could sink me quite easily. But when that is not the case, when in fact I write pretty good code, when I share my knowledge and help people the best I can, when I keep up to date and invest back in the community I love so much; then the situation is very different.

Mom! Jon made a basic compiler that emits object pascal! That is just evil!

Mom! Jon made a basic compiler that emits object pascal! That is just evil!

You will discover that I can bite back and be just as nasty as you. But I choose not to, because you don’t treat people like that. If growing up has a perk it’s that you understand the value of kindness and companionship, of community and helping each other.

So why not solve this like a civilized, normal human being? just ask. Give me a call, get the facts. Dont sit there like a 14-year-old girl and base your assumptions on rumors. If in doubt, just call me up and ask. Then we can put whatever misunderstanding there may be to rest. You might even discover that I’m actually a nice guy!

Now back to the Delphi community where people are friendly, positive, creative and easy going!

require.js for Smart Pascal

October 26, 2016 5 comments

I guess it had to happen. And why not? If you don’t know what require.js is then you can read up on it here: http://requirejs.org/ and also check out their repo on github. I’ll show you how to get this going for Smart Mobile Studio.

Require.js

Ever looked at a node.js program? Notice how they always start with require? It’s just all over the place. Well fret ye not, it’s basically node’s equivalent of pascal’s uses. Except, it also deals with code modularization, resolving dependencies and file-loading at the same time.

I don’t know what’s up with these JS developers. Brilliant coders and I love them for it, but they have this tendency to just stuff everything under the sun including the kitchen sink into a single package. This is what happens when they replace C and Pascal at universities around the world 🙂

require.js can be divided into 4 aspects:

  • Defining dependencies that must be in place before a piece of code executes
  • Loading JavaScript files en-mass and getting a nice callback when the files are ready
  • Loading of code modules, ala DLL files in a clever way
  • Support for plugins, there is a whole bunch available (check the website)

Loading JavaScript files en-mass

To be honest the VJL already have this. It’s been a part of our RTL for ages now. If you look at the unit SmartCL.FileUtils.pas you will find a class called TW3Storage sporting routines for loading not just scripts -but images, text-files, sound files, XML and even CSS. So in your face require.js! Ha!

It has the following interface:

  TW3Storage = static class
  public
    class procedure LoadXML(aFilename:String;
          const OnComplete:TW3XMLDataReadyEvent);

    class procedure LoadFile(aFilename:String;
          const OnComplete:TW3TextDataReadyEvent);overload;

    class procedure LoadFile(aFilename:String;
          const OnComplete:TW3StreamDataReadyEvent);overload;

    class function LoadCSS(const aRel,aHref:String;
         const OnComplete:TProcedureRef):THandle;overload;
    class function LoadCSS(const aRel,aHref:String):THandle;overload;

    class Procedure LoadScript(aFilename:String;
          const OnComplete:TProcedureRef);overload;
    class procedure LoadScript(aFilename:String);overload;

    class function LoadImage(aFilename:String;
          const OnComplete:TProcedureRef):THandle;overload;
    class function LoadImage(aFilename:String):THandle;overload;

    (* This function is for batch-loading an array of images.
       The callback will be invoked when all images are successfully loaded *)
    class Procedure BatchLoadImages(aFileNames:TStrArray;
          const OnComplete:TProcedureRef);
  End;

So we have little need for require.js when it comes to loading files. There is actually very little require.js (on the surface) has to offer the Smart RTL. Having said that – require.js is not just about loading files. It also deals with module declarations and dependencies when loading these – which is what a Delphi programmer would call a DLL file.

So I think it’s wise to include it for the future, because pure JS libraries is something we will be adding to the codegen later. I wont set a date for it, but I have already added quite a bit to the codegen.

As a bonus, the keyword “require” is already marked as a reserved keyword for node.js, so the syntax highlighter in Smart Mobile Studio (im testing this on version 2.2.1.4542 which is older than the current release) will highlight the keyword as an intrinsic procedure in SmartCL based projects as well. Neat and fits like a glove!

requirejs

Require is a reserved word in node.js

Right. Loading files is well and dandy, but what about the modules? I havent really bothered with that just yet. It’s there, and it shouldnt be to hard for a crafty Smart coder to complete it, but I want it to remain dormant until we have time to make it an integral part of Smart. No point in adding something super-cool and just expose it in the IDE. And we have our work cut out for us as it is (!) So let’s finish the backlog before we start with the DLL standard.

Also, Smart is package based just like Delphi and Lazarus, so the whole JavaScript “module” system is a bit of a mess really. It works, but elegant is not a word I’ll use to describe some of the JavaScript solutions out there.

You want it now? Ok, here you go!

Yes, this time you can actually get it now. I have written the wrapper in such a way that you can just download require.js, stuff it in a library, then add a unit to your RTL folder. I know I have irritated you with all these previews. Since this unit have no special dependencies you can assemble it in 10 minutes or less.

Click here to download both the test project and the library files if you don’t want to follow the tutorial.

First, download require.js and put that in the  $root\libraries folder. like this ([D] = Directory, [F] = file):

    • [D] Libraries
      • [D] Require.js
        • [F] require.js
requirejs_minified

You want the minified version so click that

For simplicity just rename the JavaScript file “require.js”, then create a text file in the same folder with the download url and the version number. That way you can keep track of the version when you update in the future.

Now let’s write some pascal to make this puppy conform to our way of doing things! But always remember, this file works with the document object model (DOM) and must never be used in a node.js application. Node has its own version of require(). So this belongs in SmartCL namespace and visual applications only (!).

Note: Normally I would urge you to save this file to the RTL folder, but that is quite risky. The RTL folder is under the control of our automatic update program (see license) and as such it can be deleted or replaced without further notice.
To avoid any changes you make being erased, place it side-by-side with the pascal file in $Libraries\require.js\SmartCL.Require.pas. Just saying.

Note: This file is copyright, but if you own Smart Mobile Studio you have the right to use it in your projects. If not, visit www.smartmobilestudio.com for licensing options.

{ **************************************************************************** }
{                                                                              }
{ Smart Mobile Studio - Runtime Library                                        }
{                                                                              }
{ Copyright (c) The Smart Company AS. All rights reserved.                     }
{                                                                              }
{ **************************************************************************** }
unit SmartCL.Require;

interface

uses W3C.DOM, System.Types, system.reader;

type

EW3RequireJS = class(EW3Exception);

TW3RequireError = class external (JDomError)
public
  property columnNumber: integer;
  property lineNumber: integer;
  property fileName: string;
  property message: string;
  property name: string;
  property stack: TStrArray;
  property requireType: string;
  property requireModules: TStrArray;
end;

TW3RequireErrHandler = procedure (err: TW3RequireError);

TW3RequireJSConfig = class external "requirejs.config"
  property enforceDefine: boolean;
  property baseUrl: string;
  property paths[name: string]: variant;
  property waitSeconds: integer;
end;

TW3RequireJS = class external "requirejs"
  property config: TW3RequireJSConfig;
  property onError: TW3RequireErrHandler;
end;

function Require: TW3RequireJS; overload;
procedure Require(Files: TStrArray); overload;
procedure Require(Files: TStrArray; const Success: TProcedureRef); overload;
procedure Require(Files: TStrArray; const Success: TProcedureRef;
  const Failure: TW3RequireErrHandler); overload;

implementation

{$R "require.js"}

function Require: TW3RequireJS;
begin
  try
    asm
    @result = require;
    end;
  except
    on e: exception do
    raise EW3RequireJS.Create({$I %FUNCTION%}, nil, e.message);
  end;
end;

procedure Require(Files: Array of string);
begin
  try
    asm
    require(@files);
    end;
  except
    on e: exception do
    raise EW3RequireJS.Create({$I %FUNCTION%}, nil, e.message);
  end;
end;

procedure Require(Files: TStrArray; const Success: TProcedureRef);
begin
  try
    asm
      require(@Files, @Success);
    end;
  except
    on e: exception do
    raise EW3RequireJS.Create({$I %FUNCTION%}, nil, e.message);
  end;
end;

procedure Require(Files: TStrArray; const Success: TProcedureRef;
  const Failure: TW3RequireErrHandler);
begin
  try
    asm
    require(@Files, @Success, @Failure);
    end;
  except
    on e: exception do
    raise EW3RequireJS.Create({$I %FUNCTION%}, nil, e.message);
  end;
end;

initialization
begin
  // When you compile a smart program, it will copy all files imported with
  // the $R compiler define, these will be stored in the $AppName/Res folder
  // and are loaded automatically.
  // Since that is the place you want to store other scripts as well, we
  // create an alias for the location. So $scripts will always point to
  // that path. You can add as many aliases you wish
  require.config.enforceDefine := false;
  require.config.paths['$scripts'] := '/res/';
end;

end.

Now save this as described above and give it a testdrive!
Start a new visual project, save the project before you start coding (important!)
Add a button, save once more (I know, I know.. this is being fixed now. I hate that bug so much). Double click the button in the designer, then add this:

procedure TForm1.W3Button1Click(Sender: TObject);
begin
  require(["https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"],
      procedure ()
      begin
        showmessage("JQuery loaded");
      end);
end;

The above code will load jQuery (latest build) from google’s public API server. To make sure that everything went ok, click the “devtools” button in the Smart display browser and investigate:

Require() works like a charm :)

Require.js works like a charm 🙂

Note: JQuery is here just used as an example. You have absolutely no need for it under Smart, because the way visual controls work in the VJL a control always knows it’s childrens handles. So searching (hence the “query” in jquery) for tags and groups of elements have little meaning for object pascal in the browser. It already knows its children and have direct access to them. So no querying required.

Well — enjoy!

Why C# coders should shut up about Delphi

October 18, 2016 Comments off
13507225_10209662785317165_99874043994628045_n

When in Rome

Those that follow my blog or know me personally – also know that I don’t go out of my way to be confrontational or disrespectful. I try my best to follow the middle-path, to see positive in all things. But sometimes you face a level of stupid that begs a response. A verbal one. And this is one of those cases.

Lately I see more and more Delphi developers getting into debates with C# developers, and they are confronted with an attitude and belief-system that quite frankly is utter nonsense. It’s not based on history or facts but disputes rooted in childish “isms”. A mix of old habits and an unhealthy obsession with the notion that new means better.

It is nothing short of an intellectual emergency.

Old is bad?

If that is the case then C/C++ should be utter shit, because C is 3 years older than Pascal. Pascal was created to replace C and get away from (amongst other things) the absurd and time-consuming header file practice, not to mention the recursive hell that still occur when headers reference other headers and conditional symbols pile up.

Do you know how curly brackets came into being? Jump into your nearest Tardis and set the destination to the mid 1960’s. Not 1969 like Wikipedia will tell you, but a few years earlier. Back when mainframes were the size of Portugal and 1024 bytes of memory made professors all girly inside. You see, back then memory was sparse and pretty much all the languages (or toolkits) needed to save space. So the { } curly’s were used as replacements for words like “begin” and “end”. Why? Because one ascii byte is better than five ascii bytes when there’s only 1024 of them around.

Ps: when I use the word toolkit here I really mean a random soup of asm snippets dipped in venom. The bones collected to make C was actually a mix of homebrew toolkits made by different engineering teams at the time. And each of these toolkits had their own fanclub /slash/ legal representation; because all of them, miraculously, had invented the exact same thing at the same time before everyone else. These guys kept on fighting over who owned what well into the Watcom era. It’s probably the longest standing demonstration of a grown-up tantrum since the roman emperor caligula outlawed clothes.

Fast forward to 1970 and the amount of memory on mainframes had already doubled a few times just like Moore had predicted five years earlier. The C standard that Dennis Richie had painstakingly wrangled from the cold, greedy hands of grumpy old technicians was due for an upgrade. Tests were done by very dull, very serious men in grey clothing – and in their horror they discovered that human beings would interact with english words and phrases faster than symbols and glyphs. So a word like “begin” would be picked up by the brain faster than {. It is just knockout stuff isn’t it.

You cannot praise Anders as a genius architect and at the same time throw his life work in the thrash. Perhaps you should ask yourself why Anders loved object pascal so much that he dedicated half his career making sure universities had access to it.

Living on the edge with a red tie, Nicolaus Wirth rocks the scene!

Living on the edge with a red tie, Nicolaus Wirth rocks the scene!

Enter Niklaus Wirth, a man so clever and academic that he doesn’t catch exceptions; He is the exception. But next to his colleagues over at Berkley our dear Niklaus is the proverbial rock-star. He decided that in order to make programming more accessible for students, easier to learn and above all, establishing a standard for safer code, that they should take science to heart and include that in a programming language design. So he put on his gravest lab coat and began to implement “a better C”. Nine months later pascal was born, and to celebrate Niklaus used colored socks that day. A risky bit of business that could get him expelled from the university and cost him his seat at the strangely brown sorority club, in which he was master of ceremonies. But hey, Nikolaus is a rebel and this was the swinging 70’s after all.

My point? This is why pascal uses “begin” and “end” as opposed to { and }. Science. Real science.

Whimsical satire aside: with the knowledge that C is actually older than pascal, not to mention that it is identical in features, depth and complexity– what is it going to be? Do you still cling to the notion that older have to be of less value than new? Or could it in fact be that you havent really looked closer at object pascal to begin with? Have you even installed a modern version of Delphi and given it a worthy test drive? Or do you just speak out based on what you like and know, as opposed to what you don’t know and havent even tried.

My 8-year-old daughter is like that. She makes up her mind about food before she has even tasted it. Surely a trained engineer can do better?

And I say that because — if we follow your line of reasoning, C/C++ should be incapable of producing C#. How can something old and outdated possibly produce something new and exciting? You do know that C# is written in C and assembler right? And that Java and all the other high level languages out there didn’t spontaneously self assemble. They are all written in C, assembler or pascal. And there is a reason for that.

Just like nature have different levels, from particles to minerals, from minerals to bacteria, from bacteria to plants, from plants to insects (and so on) — so does a computer. Each of these levels have laws and no matter how much you want to introduce something from a higher level into a lower level – that’s just not how reality works.

foodchain

The fact that I have to explain this in 2016 demonstrates how education and academia has degraded after C and Pascal was replaced with Java.

The law is very simple: each level can only emit complexity upwards. So assembler is used to produce C and pascal, C and pascal is used to produce C++ and object pascal, C++ and object pascal is used to bring about every other single piece of tech you take for granted.

So when you criticize Delphi but use C#, you are actually saying “I want a T-Rex to inhabit the mineral world”. It’s just utterly divorced from reality.

It’s like saying Visual Basic 5 is cooler than assembler. You don’t debate with people like that, you just look at them with pity. I don’t know how many years a software engineering  degree is elsewhere, but if you just spent 3 years in college and 2 years at a university followed by one or two additional years getting your diploma – and this is the level of insight you graduate with then I pity you. And I pity your employer because sooner or later you will bring about the apocalypse.

If we apply rational logical thought to the proposition at hand, we cannot but conclude that the notion of “new is always better” is false. It is to mistake marketing for facts and capitalism for science.

Your teacher should have taught you this: “In a computer, like nature, the past is always alive“. Look closely at your brand new pc: Bios, Vesa screen modes, non linear memory, hardware interrupt vectors and a cpu that supports no less than 3 instruction sets. Do you think Windows or the Linux kernel can just ignore this? Why not call up Linus Torvalds and ask him why he’s not using C# in his line of work; or NVidia why their GPU pipeline only ships with C headers and not C++ classes. I sure as hell wouldn’t want to be on the receiving end of that call.

C# is better than Delphi?

Anders Hejlsberg, the father of many languages

Anders Hejlsberg, the father of many languages

Actually, it’s not. What today is known as .net, from its CIL intermediate language right down to the global assembly cache is Delphi. Yes you read that correctly the entire .net product family is Delphi. It was described on Borland’s news-servers years before it magically appeared as Microsoft’s flagship product.

Anders Hejlsberg created and prototyped these technologies while he was working at Borland. And indeed, the father of C# and entire dot net stack is none other than the father of Delphi.

At Borland (in the borland.language newsfeed I vividly remember) these technologies went mentioned under the codename “portable Delphi”. I followed the thread on the news servers for quite some time. It was no secret that Borland was tinkering away on the next big thing, and I believe it was ultimately Borland’s response to Java. Because at the time Java had eaten quite a chunk of Borlands educational seat licenses. And had Anders continued working for Borland, Delphi and C++ builder would perhaps be bytecode based today.

So when you, the C# fanboy, propose that Delphi is somehow inferior to dot net, or that object pascal is outdated and technically behind C# you are not just shooting yourself in one foot, but both feet at the same time. Keep on reading and you will understand why.

But just to make this crystal clear: Anders Hejlsberg is not just the father of C# and dot net: he is also the father of Delphi. And before that he gave birth to Turbo Pascal.

Borland, land of the free

Borland, the company Anders worked for, was put out to pasture by Microsoft. Bill Gates and his thugs launched a financial onslaught that few companies on the planet could have endured. The reason was that Microsoft really had the worst developer tools on the market, while Borland represented the very best. So for a long time Borland was a direct threat to Microsoft. And they were winning every single time.

When Borland later began to flirt with Linux (Delphi Kylix) it must have made the R&D department at Microsoft piss themselves. Delphi is responsible for thousands of desktop applications synonymous with Windows – and if Linux users got their hands on RAD tools like Delphi, they were in a real position to hurt Microsoft. You have to remember that this was before cloud computing. Microsoft didn’t have a fallback strategy and depended on desktop and server sales. Linux could do everything Windows could, but it lacked the desktop applications, the user friendliness and features Borland made simple. But that is a whole different story so let’s not deviate from our timeline.

Weird Science, a fun but completely fictional movie from 1985. I just posted this to liven up an otherwise boring trip down memory lane

Weird Science, a fun but completely fictional movie from 1985. My point? People who don’t know how computers worked were actually afraid this pseudo-garbage could one day be real. Just like C# and Java programmers believe they are top-dog, they are in fact standing on the shoulders of giants. C/C++ and object pascal is holding you up.

What Microsoft did was, basically, to buy out Anders from Borland and at the same time attack the company from every angle. Drowning them in bullshit lawsuits, patent claims and all the nasty, cowardly practices Microsoft is renowned for.

Bill Gates called Anders up personally and gave him “an offer I could not refuse” as Anders dubs it in various interviews over the years.

So to put this myth to rest and be done with it: C# as a language and dot net as a technology did not originate with Microsoft. It has Borland written all over it and its architecture is intimately joined at the hip with Delphi and C++ builder. Companies like Microsoft dont innovate any more, they buy competence and re-brands it as their own.

Dot Net framework, you mean the VCL?

If that is not enough, take a long, hard look at how the .net framework is organized. Pay special attention to the features and methods of the base-classes and RTTI. What you are looking at is the VCL, the visual component library, Delphi and C++ builder’s run time library.

There was never any secret where this came from, but it’s not advertised either so I don’t blame people for not recognizing it. But when people start to behave nasty over what should be either a passionate hobby or a professional discipline, then truth must be told. The very foundation of the dot net framework is taken straight out of the VCL.

And why shouldnt it? The whole platform was whispered about under the codename “portable Delphi” to begin with, it was even designed by the same author – so why should it come as a surprise that it’s basically Delphi reincarnated with a different syntax parser? Either way a few bells should start ringing in your head – telling you that you may have been wrong about Delphi and object pascal in general. Probably because you know very little about Delphi to begin with.

So, what you perhaps believe sets C# apart from Delphi, what you imagine gives dot net an advantage over Delphi – is in reality the opposite: it is Delphi. It originated in Delphi, was inspired by Delphi and flows straight from the inventor of Delphi himself. Anders is responsible for two distinct object pascal development platforms prior to working for Microsoft. Take some time to reflect on that.

You cannot praise Anders as a genius architect and at the same time throw his life work in the thrash. Perhaps you should ask yourself why Anders loved object pascal so much that he dedicated half his career making sure universities had access to it.

Strength in diversity

The fact that C/C++ is alive and well today serves to prove my point: age has no meaning when dealing with fundamental technology. These languages embody the fundamental principles of computing. It’s like a force of nature. Electricity was never invented, it was there all along as a part of nature – we just had to learn the principles in order to tame it. And archetypical programming languages is almost the same thing. They don’t grow old because they represent a fundamental level that can never be replaced.

Things are the way they are for a reason. And programmers before you established standards that address things you might not have to deal with, but that’s because they dealt with it before you. Just because you don’t see the plumbing doesn’t mean it’s not there.

These are the compilers responsible for the foundation on which all other languages, operative systems, applications and services rest. Remove those, and the whole house of cards come crashing down.

So C/C++ and object pascal continue to exist, thrive even, precisely because they interface with the hardware itself, not a virtual machine or bytecode format. Delphi as a product is naturally tailored for operative systems, as is C/C++. But that is because we use programming languages to create applications. There is nothing in the way of someone using compilers like freepascal and writing an operative system from scratch.

Ultibo is an ARM operative system written purely in object pascal

Ultibo is an ARM operative system written purely in object pascal

By contrast, C#, Java and Visual Basic are context dependent languages. They exist purely in context with an operative system or run-time environment. They can’t exist without these and lack the depth C and pascal brings to the table. The depth to span many levels, from the lowest all the way up to cloud and domain driven programming.

Just look at Android, an operative system written in Java right? Well that’s not really true. The Android operative system depends on a native bootstrap, a piece of code that establishes the run-time environment for Java applications. So when you fire up your Android phone, tablet or set-top box, the first thing to boot is a loading mechanism written in vanilla C. This in turn mounts a filesystem and continues to loads in bunch of native drivers. Drivers for the display, storage, wi-fi and all the hardware components that ultimately make up your SoC (system on a chip).

Its only after this long process that the environment is capable of hosting the Java virtual machine. Then and only then is the device capable of executing Java.

7709-f-1

Notice the “C” part of the Java NDK? Wasnt that exactly what Java was supposed to solve? All that hype and here you are, back at where you started!

So Java, which for the past decade or more have bombarded us with advertising like “platform independence” is a total flop! Its like communism and looks good on paper, but once you start testing these ideas in real life – they just don’t work.

Turned out that the java virtual machine when running on small devices like phones and tablets, choked the CPU. Which in turn used more electricity to keep up, which in turn rendered the battery life of these devices null and void. Talk about irony. All that hype and Java couldn’t even deliver its most basic promise: platform independence. And you removed C and pascal from our universities for this? It’s a disaster en-par with the burning of the great library of Alexandria.

There is more than a drop of ego and arrogance in this material. Young people especially like to believe they are smarter than those who lived before them. It’s a very selfish idea that really need to be addressed. Take someone like Alan Turing for example, the inventor of what we call computers today. This man assembled and created the first computer by hand. He even hand carved the wheels that made the mechanism run (which was mechanical during the second world war). I would happily bet $1000 that Alan could out program the lot of us had he gotten the chance. He has been dead for many years, but to imagine yourself smarter or more capable than him would be the definition of arrogance.

PS: This is where we come into the realm of wisdom versus knowledge. The difference may be subtle, but it’s so important to distinguish between them.

C# would have been a sad little language without the work of this man, Miguel de icaza

C# would have been a sad little language without the work of this man, Miguel de icaza

Either way without the native context to support it Java turned out to be a blundering behemoth. And its the exact same with C#. This is why Miguel de Icaza work on Mono has been so instrumental to the success of dot net and C# in particular. It was Miguel and his team that pushed C# into native compilation versus JIT for mobile devices. C# would never have been allowed on IOS or Android otherwise.

So that is the difference between archetypical languages and context based languages. Hopefully you now see why this negative attitude towards Delphi and object pascal doesn’t make sense. It really is just as stupid as these cults that believe in dinosaurs and that human beings once lived side by side with a T-rex. Anyone with a highschool diploma should instinctively know better.

The problem is when people in great enough numbers start to believe in this nonsense, because then they can actually damage important mechanisms of our eco-system. Insane beliefs really is dangerous both socially and technically.

Grow up!

I have no problem using C# and consider it a valuable tool in my toolbox. Same with Delphi. But when it comes to kick-ass desktop applications for Windows and OS X, Delphi has no rival. It gives you a productive edge that I havent found in any other language. And I don’t base that on preference. I base that on engineering and the years of development invested in Delphi by both Borland and Embarcadero.

I just find it odd that C# developers seem to lack the ability to speak well about Delphi, because it’s a tell-tell sign of immaturity to be incapable of that. Object pascal and C++ is identical in every way (except multiple inheritance, which even C++ programmers shun like the plague so no loss there). Why then should educated programmers find it reasonable to praise C but thrash pascal? It’s like saying that one car is faster than another – but when you pop the hood they have the same engine. The exact same machine code generator even.  It is psychological masturbation. We are coders, we shouldnt do things like that. We should examine the system carefully and then make up our minds.

And what is a programming language anyway? It is the ability to describe the solution to a problem. The ability to define and control how a series of activities execute. Each language represents a methodology for solving problems. A mindset. Nothing more.

Languages like C, C++ and object pascal will always exist, they will always thrive, because they are instrumental to everything else (desktop, operative system, services, everything that makes a computer capable of what it does). It doesn’t mean that Delphi is the solution to all problems, far from it. And that is ok.

Context based languages are more often than not designed for a purpose. Java was initially designed as a network language. This makes Java infinitely more suitable for dealing with that line of work. You can do the exact same in C but you would have to add a few libraries and establish a platform. Which is exactly what C and pascal is good at, implementing fundamental technology. Object pascal is a language you would use when creating other languages. C is more popular for virtual machine development, no doubt there, but there is nothing in C/C++ that you wont find in object pascal.

Interestingly, languages that many believe is long since extinct, like Cobol, are actually alive. Cobol was created to deal with large stacks of numbers and to push associated data through formulas. That is its context and no other language is better suited for the banking sector than Cobol. Which incidentally is the one place where Cobol is used to this day. And why not? Why waste millions trying to hammer in a nail with a hacksaw? Why not use a language especially designed for that purpose? SQL is likewise a language especially tailored for its tasks. I don’t hear anyone bitching about how old and outdated that is. It wont grow old because it embodies the principle of relational data.

And just what exactly is old about Delphi? Generics? Posix support? Weak and strong references? Garbage collection? Attributes? class, record and enum helpers? Dependency injection? Model view controller frameworks? The ability to write assembler side by side with pascal? The ability to link with C/C++ objects? Cross compilation for Windows, OS X and mobile platforms? What manner of logic are you using where you praise other languages for these features, but for Delphi the same features makes it old? Stop repeating what someone once told you like a mindless parrot and investigate. You are an engineer, a field of science; start acting like one.

In my work I use several languages: JavaScript, Delphi, Smart Pascal, Mono C# and even Python. I have also fallen in love with LUA believe it or not.

For web-pages I prefer Smart pascal which compiles to JavaScript (node.js is fantastic). Then you have shell scripting, a touch of x86 assembly code, a dash of bash on my Linux box and .. well, there is strength in diversity.

It all depends on what is best for the customer and what language yields the most robust solution. Sometimes C# is better suited for my clients infrastructure, other times Delphi makes more sense. But if I was to pick a single language to cover all of them, it would either be object pascal or C++ (gcc). These really have no rivals and will never go away.

These are the compilers responsible for the foundation on which all other languages, operative systems, applications and services rest. Remove those, and the whole house of cards come crashing down.

So using many languages is actually an enriching experience. It brings more depth to our way of thinking and (consequently) affect the quality of our products.

Anyways, I believe congratulations are in order, because if your favorite language is C#, you have in fact been using Delphi without knowing it. There is so much Delphi in C# and they both originate from the same author. So why not pay a visit to C#’s older brother?

So go download Delphi, Smart Mobile Studio, Lazarus and Remobjects Oxygene – enjoy the decades of research and excellence these dialects represent. It wont hurt you, it will probably do you a great deal of good.

Smart codecs, a draft

October 18, 2016 5 comments

When you hear the word codec, what comes to your mind? For me I get flashbacks to early 2000’s when I worked in visual C++ and Visual Basic on a huge media project. ActiveX was a total cluster fu**, with a proverbial vipers nest of interfaces, vague explanations and more blue-screens than i care to remember.

Working on the RTL for Smart Mobile Studio has forced me to learn a lot of topics that I would, had I chosen not to go down the JavaScript rabbit hole, never have given a second thought. And I have now reached the point where codecs is starting to make more and more sense for the RTL. Let me explain why.

Codec is just short for “encode decode”, and a codec represents just an isolated ability to encode or decode a piece of data. If you have followed the evolution of Smart Mobile Studio and know your way around the RTL – you must have noticed that we have a fair bit of duplicate code hanging around. So far I have found two wildly different CRC implementations, a sexy and fast RC4 encryption routine, RLE compression, URL encoding, Base64 encoding, UTF8 encoding .. the list goes on.

All of these routines, no matter how small or large they may be, does the exact same thing: they encode or decode a piece of data. So you input one type of data and you get something else back.

Part of our RTL update is not just about adding cool new features, it’s also about order, cleaning up and getting the RTL into a form that is better suited for the future. I have already blogged about namespaces and the important role they play in the next version of Smart Mobile Studio. Well, I think its time to put our encoding/decoding capabilities into order as well.

Smart codecs

The first challenge that comes to mind when you sit down to create a codec framework, is the data formats you have to deal with. I mean, what is the point of a codec class if its only capable of processing strings right? And since Smart has all these cool mediums to play with, like streams, buffers and untyped arrays,  we want each codec to support as many such input and output types as possible.

This is where things get’s complicated and the critique I dished out to Microsoft ages ago comes back to haunt me. Because I now see why their codec system had to be so elaborate.

I mean, lets say you have a URL codec. It exists to take strings and replace characters that could be filtered out by the locale on another pc – so all it does is to replace these characters with a %charcode representation. That way the text can be re-mapped on the other side safely.

For a codec designed to process this type of data, you would have to define an input channel that can deal with text – as well as an output channel of the same type. But what if you want the output as a stream or memory buffer? Suddenly input and output gates become more complex, more fluid and data-dependent.

IBinaryTransport to the rescue

In the last update I did something magical. So magical in fact that I was oblivious to the fact that that I had just solved the problem of data mitigation. It was a 2 second mistake that turned out to be a stroke of genius (which I can’t take credit for, because I had no idea I was being genius at the time).

IBinaryTransport is just a super simple interface that gives you info about how much data is available, a reading method and a writing method, and finally the position of the read/write cursor. It’s stupendously simple, yet solves so many problems:

  IBinaryTransport = Interface
    function  DataOffset: integer;
    function  DataGetSize: integer;
    function  DataRead(const Offset: integer; const ByteCount: integer): TByteArray;
    procedure DataWrite(const Offset: integer; const Bytes: TByteArray);
  end;

What I did was to add this interface to both TStream, TAllocation and TBinaryData. I figured it would be handy when calling ToStream() and similar helper functions. But it turned out that with this interface in place – I could throw out TStreamReader, TStreamWriter, TBufferReader, TBufferwriter – and just write a single reader/writer class. TStreamReader actually doesnt have a clue what a stream is, because it speaks to the target via IBinaryTransport.

Same with TReader and TWriter for TBinaryData (memory buffer). They don’t know anything about memory at all, they just know how to communicate with the target through IBinaryTransport.

So how does this affect codecs? It means we can throw out the older model completely. Instead of having to define a whole list of input/output channels, add support for dealing with each of them — all we have to do is make the input and output channels IBinaryTransport (!)

This reduces the basic codec class to this:

  TCustomCodec = class(TObject, ICodecBinding, ICodecProcess )
  private
    FBindings:  TCodecBindingList;
    FCodecInfo: TCodecInfo;
  protected
    /* IMPLEMENTS :: ICodecBinding */
    procedure RegisterBinding(const Binding: TCodecBinding);
    procedure UnRegisterBinding(const Binding: TCodecBinding);
  protected
    /* IMPLEMENTS :: ICodecBinding */
    procedure Encode(const Source: IBinaryTransport;
        const Target: IBinaryTransport); virtual; abstract;

    procedure Decode(const Source: IBinaryTransport;
        const Target: IBinaryTransport); virtual; abstract;
  protected
    function  MakeCodecInfo: TCodecInfo; virtual;
  public
    property Info: TCodecInfo read FCodecInfo;
    constructor Create;virtual;
    destructor Destroy;Override;
  end;

And the work you have to do implementing a new codec to this:

  TURLCodec = class(TCustomCodec)
  protected
    (* IMPLEMENTS :: ICodecProcess *)
    procedure Encode(const Source: IBinaryTransport;
        const Target: IBinaryTransport); override;
    procedure Decode(const Source: IBinaryTransport;
        const Target: IBinaryTransport); override;
  protected
    function MakeCodecInfo: TCodecInfo; override;
  end;

Using a codec

A codec should never be used directly, but via proxy. This gives the framework a chance to create instances on demand, and also makes sure you don’t compile in codecs you never use. A few basic codec classes will be registered when your application starts – but these have always been compiled with your Smart application so there is little or no difference with regards to size or speed.

The benefits however are great: all codecs register with a central manager, they also register their mime-type (the format they work on), making it possible for you to query the codec-manager if it supports a specific encoding/decoding mechanism.

And naturally, it gives us uniformity with regards to data processing.

Here is an example of using the codec-api to URL encode a string:

var
  LBinding: TCodecBinding;
  LList: TCodecList;
  LSource: TStream;
  LTarget: TStream;
  LReader: TReader;
  LWriter: TWriter;
begin

  if CodecManager.QueryByName('url', LList) then
  begin
    LSource := TMemoryStream.Create;
    try
      LTarget := TMemoryStream.Create;
      try

        LWriter := TWriter.Create(LSource as IBinaryTransport);
        try
          LWriter.Options := [woEmulateCursor, woFlexibleBoundaries];
          LWriter.write( TDataType.StringToBytes("This is a string ready for URL-encoding!") );
        finally
          LWriter.free;
        end;
        LSource.position := 0;

        LBinding := TCodecBinding.Create(LList[0]);
        try
          LBinding.Input := LSource as IBinaryTransport;
          LBinding.Output := LTarget as IBinaryTransport;
          LBinding.Encode();
        finally
          LBinding.free;
        end;

        LTarget.position := 0;
        LReader := TReader.Create(LTarget as IBinaryTransport);
        try
          var LBytes := LReader.Read(LTarget.Size);
          writeln( TDataType.bytesToString(LBytes) );
        finally
          LReader.free;
        end;

      finally
        LTarget.free;
      end;
    finally
      LSource.free;
    end;
  end;

The cool part here is that the data can be anything. The source can be a stream, a buffer, a memory allocation – even a socket (!) Same with the target. As long as the target object implements IBinaryTransport the codecs will do their bussiness regardless of medium.

codecs

The output is an URL encoded string, processed at byte level

URL, Base64, UTF8, UTF16 .. and encryption ciphers naturally .. all these processes can now be represented under a single, efficient and small framework. And yes, there will naturally be top-level functions for these, same as before. I don’t expect people to write all of this every time they need to URL encode a string.

The point here is depth, and that Smart Mobile Studio applications can now do more and more of what you would expect from a native compiled system.

Websocket, WebSocket.io and Socket.io

October 16, 2016 8 comments

Wow. Thats is a mouthfull isn’t it? Websocket, websocket.io and socket.io. So what is that all about?

In short, im finishing off the server units for Smart Mobile Studio! And I think people are going to be super pleased and happy about this one.

As you may know, node.js gives your JavaScript more or less the same functionality as classical programming languages. You get to work with sockets, talk to databases, implement protocols – all of it in JavaScript and all of it capable of doing exactly what we are doing in Delphi. That is pretty neat!

This is so fun to make and work with

This is so fun to make and work with

But that also means someone has to expose the node.js functionality in pascal form and then write thin wrappers around that. This is where Smart Mobile Studio really shines, because after six years of constant development – we have built up a very powerful codebase. Smart mobile studio is not just about compiling to JavaScript. There are 10-20 compilers out there doing that. Nope, the power of smart mobile studio is in the infrastructure we have painstakingly constructed for our customers. Hundreds of hand-written classes, units and library files. Add to that our cosy little IDE which is very nice to work with and the advantages starts piling up.

Servers, glorious node.js servers

So whats on the menu? A lot! More than I actually thought we would add in the next update. Here is a list of the server types you will be getting:

  • http server
  • websocket server
  • tcp/ip server
  • socket.io server
  • websocket.io server

To explain the differences:

Websocket is a full-duplex communication stack that allows both client and server to talk; at the same time. It also contains fancy commands for emitting messages to all connected clients, and likewise a client can commit messages to other clients (if the server allows it). You can send both text messages and binary messages. And the cool part is that the websocket engine will collect the data, deal with net-frames and spare you all the razzle you would otherwise have to do.

On top of this we have something called socket.io. This takes the whole thing one step further, allowing you to define a set of commands on the server (by name), and associate that with the code to execute when such a command is received. Socket.io also come in client-form for both browser and node.js itself. And just like the server edition you can define a set of commands for the client as well. This moves websocket into the realm of real-time messaging, where rather than wasting days and weeks coding your own protocol, you can kick back and flesh out your command-set much in the way RemObjects SDK does. Socket.io also contains clustering mechanics, but I wont cover that just yet.

Node.js leveraged for object pascal, love it

Node.js leveraged for object pascal, love it

Websocket.io is sort of third option. It’s basically websocket and socket.io glued together. You don’t have to upgrade the http socket (read up on websocket if you have no clue what that means) if you don’t want to. Websocket.io gives you pretty much exactly the same as websocket + socket.io, but from a unified API. And to be honest this is the library I use the most myself.

So long story short: you get 3 websocket based server classes to play with, all of them inheriting from TNJCustomServer, so you use the same code to work with all servers. And the speed is phenomenal! I have to pinch myself sometimes just to remember that this is kick-ass javascript running the show.

If you think websocket is “communication with training wheels” (I don’t, I frikkin love it) then a raw TCP server is probably your cup of tea. This is a perfect class to use if you need to port over some old Delphi code, if you for some reason hate XML or JSON – or perhaps you just want to dump over raw binary data as quickly as possible. Either way: it’s there, and it works brilliantly.

As you would expect I’m also doing the client side of things. We have supported websocket out of the box for a while now, and I just added a socket.io client to the codebase. I have a few alternatives to try out on the raw tcp stuff, but ultimately tcp is now allowed for HTML5. But a client and server for node.js is ofcourse on the menu.

Benefits

It’s when I sit and work with the codebase like I do now that I see just how much cool stuff we have. When doing research on a library, how to best wrap or implement it in our RTL, I naturally come across hundreds of comments by JavaScript programmers. Things like allocating memory, copying data from one buffer to the next, working with bytes and bits — a lot of these guys are having a really hard time doing classical programming.

But for Smart Pascal that’s not even an issue. We have supported memory allocation, blue-pointers and even a threading model for quite some time now. Yes, threading. Check your RTL folder and you will find it 🙂 It goes without saying that when you have memory streams, file streams, raw buffer classes, stacks, queues and proper inheritance that smart pascal gives you more than just a head-start. The benefits are astronomical in places.

And no, im not just blowing my own horn here — I use Smart Mobile Studio to create services and mobile applications on a daily basis. So I am painfully aware of what we did wrong, but also what we did right. And thankfully we got more right than wrong.

 

 

Hexlog, building a better logging system

October 15, 2016 Leave a comment

Its been quite a busy couple of weeks for me. HexLicense has finally gotten a well deserved update and (drumroll) we have ported the codebase over to Firemonkey. I have deliberately waited a while with the Firemonkey edition, because compilers usually need a couple of releases before they become stable. And the same can be said about runtime libraries (I should know, I have created a few). I wanted to use FMX earlier but, it kinda died on me so many times that I gave up. Thankfully this is no longer the case and Delphi XE Seattle is a joy to work with.

Ironwood prototype

Ironwood prototype

Also, one of the coolest things these past weeks was returning to Smart Mobile Studio as a user. It’s really quite an odd experience because you get so locked into “author” mode when you have worked on a product for so many years. So when you sit down to actually use your own program as a means to an end, it’s a very different experience from looking at it purely architecturally.

I really love what we managed to do with Smart Mobile Studio. That might sound disingenuous since it originated with me, but somehow we captured something; some sense of creative freedom that I cannot find in giant productions like Visual Studio or QT C++. Naturally I’m biased, but I’m no stranger to self-critique either. But the speed at which I knock out a HTML5 or mobile application with Smart Pascal is just way beyond anything I can do in any other devkit. The only other development platform that have the same feel to it is Mono C#, which I love because it doesn’t contain all the .. bloat, I guess is a word, that large production environments insist on giving you. I mean, fire up visual studio and you have so many options – half of them that you will never use unless you specialize within a particular dicipline – that they just get in the way.

Anyways, Hexlicense “Ironwood” was written first and foremost in Smart Mobile Studio. We have started to port the code over to Delphi to make the Xmas deadline, but honestly: I’m so glad I could use Smart to prototype this product, because it would have taken me twice as long in Freepascal or Delphi. I’m not even sure I would have bothered if Visual Studio was my only option. Seriously.

So you may be wondering: why on earth would you implement a licensing system in JavaScript? Well that’s the cool part! Right now most licensing systems are native only. Which means that if you want to really get control over your software you have to fork out for a virtual host, if not a physical server box. The price difference between a node.js hosting solution and a native hosting solution is substantial. So implementing a version of our HexLicense server in Smart Pascal + node.js will save my customers the expense. It also means they can host the server on whatever operative system they see fit. And once again, the price difference between a Linux host (Ubuntu is wonderful to work with) and Microsoft Windows is still a factor.

Coding it in Smart Pascal also opens up the door for license based access to HTML5 based applications, be they compiled to native via Phonegap or Adobe build services or just running in a browser. So once again our JavaScript virtual machine formula get’s it right. And it’s magnificent to play with. Not a day goes by that I don’t learn something new and exciting about JavaScript from object pascal, which is paradoxical. I know.

Back in the saddle

For the past few years my life has revolved around Smart Mobile Studio and the companies I have worked for (a.k.a “the day job”). It must be at least 4-5 years since I actually sat down and built products, delivered components and offered up my services as a Delphi software architect. There havent even been any time for consulting or system design. With a full day job, two kids and a product you live and breathe for there is a limit to how much you manage. Add to that my back injury 4 years ago which rendered me unable to even walk and you get the picture; Thankfully my back is getting better. I do two rounds of boxing every week (or try to) and that has done more for my back than all the doctors and their witch-craft medicine combined.

It feels so good to create new products again. Products that are doable within a reasonable time-frame and that solve real-life practical problems (as opposed to having to solve potential scenarios that havent even occurred yet: the burden of the RTL architect). So while HexLicense for VCL and FMX is in the store, Ironwood is being ported to Delphi – I have decided to wake up another component-set that I initially created for myself. One that deals with a very practical and hands-on challenge, namely: HexLog.

HexLog

Many years ago I was working for Hydro, which is the biggest oil company in Norway. Without getting to detailed (or breaking my NDA) logging was one of the problems we faced. With more than 50 Windows services communicating (read: 50 potential sources of bugs), the company’s lack of proper logging – logging in a format that made sense to people other than us developers (like system administrators, super-users and even insurance companies interested in locating where something broke down) made it almost impossible to work with the codebase.

So one day I had enough and sat down in my spare time to write a modular, thread safe, component based logging system that didn’t just “log some info”, but it did so by proxy. Meaning, that the writing mechanism(s) were isolated in separate components, abstracted from storage – which was isolated in other components. So when we needed XML logging we just hooked up the XML writer; when we needed RTF logging we hooked that up (and so on, for numerous formats).

You would think that Delphi developers in general had logging under wraps right? That is sadly not the case. Some people are very good at logging and have made it into a habit. But more often than not when I’m hired by a client – what do you think I find? Yup, plain old vanilla text-file logging. Which is fine as long as the coders have spent some time making sure the basics are in order. Sadly that is so rare it almost frightens me. Especially when I’ve upgraded software used by pharmacutical companies, doctors and organizations that really (really!) should do full journaling regardless of bugs or errors. In fact Norwegian law demands it in some cases; especially when medicine and prescription drugs are involved. If a doctor or nurse prescribes the wrong medication and a patient dies, the insurance companies will have a field day if there is no logging according to standards. And should it turn out to be the software’s fault.. well, let’s just say there is a reason only large companies operate with “within the hour response time” in their service agreements.

So what are the criteria people tend to forget?

  • File locking issues. It will happen the moment more than one process or thread targets a file
  • Making sure the information that is logged is organized by sections, visually distinct in the file
  • Making sure time and dates use UTC or ISO formatting
  • Logging the actual user, not just the program identity
  • Using mutexes and read-write synchronization when multi-threading is involved
  • Avoiding interface communication from threads without proper understanding of calling conventions and compartment schemes
  • Using memory mapped files rather than torturing the filesystem with an onslaught of IO calls
  • Use tab indentation to make the logs easier to navigate for the human eye
  • The list goes on ..

The most important oversight is not on the list, it’s actually something as simple as logging information that human beings can read, as opposed to adapting the information to what the computer wants to work with. A dentist wont know what to do with a stack-trace or “an error occurred executing MySQLQuery1.Execute”. But he or she will understand a log that states – in plain text – “could not store prescription for patient John Doe, the database reports the disk as full. An email has been sent to the administrator“.

You don’t have to be a programmer to replace a disk or move the database to a better location. But the log must make sense. It should just be there, not getting in the way yet easily accessible.

Journaling and big-data

When you are logging every action an oil-pump (and its regulators) do for 24 hours, logfiles can grow into the gigabyte range. Can you imagine one gigabyte of messy, purely technical jargon to wade through when a critical system is down? Well I can, because that’s exactly one of the things I faced 12 years ago when I was hired to “fix” a couple of bugs. A couple of bugs turned into 2 years of re-writing the entire system from scratch. Notepad crashed when it tried to load the original log-files.

The system was all written in Delphi 4, breaking every rule known to object pascal developers even back then. Like services opening forms and forms using DDE to communicate. It was a miracle that it had worked to begin with.

This is where I decided to write a journaling system that would present me, the programmer, with a unified API for writing, reading and even updating log-items stored in multiple files. So you can set a limit to how many log-items one file can contain, and when the log reaches that limit – it create a new file automatically for you. It takes care of everything in the background, keeping track of the files and their content through an index files. This solution helped solve the problem of monster log files. And you know what? That was the core bug in the system. They had used TStringList to load in the text file, append one item, then saved it back out again. Loading almost a gigabyte of raw text while trying to keep up with GPIO signals firing like mad. So yeah, logging does matter!

HexLog naturally implements this, now even faster than before due to Delphi’s dictionary classes and clever use of balanced trees. The best is that the writer mechanism applies to this type of journaling as well. So if you prefer XML thats not a problem, nor JSON, nor RTF for that matter. I’m even throwing in a PDF writer in update 1.

And did I mention both local logging and network logging? And that you can read the logs via a fancy HTML5 dashboard in any browser, both locally and remotely?

Reading more about HexLog

If you find the topic interesting and worthwhile, head over to my company website and read the release statement here: www.quartexcomponents.com. We dont take orders just yet, but it should ship out in the beginning/middle of next month.

And yes, there will be a server edition both for native Delphi and node.js, so there is a lot of value for money in this package.

 

Try out HexLicense in your browser

October 9, 2016 Leave a comment

If you head over to HexLicense.com you will find both the roadmap for 2016 and beyond – but also that you can now testdrive HexLicense in your browser (!) That is pretty cool if I say so myself.

In the browser?

HexLicense "Ironwood" engine under HTML5

HexLicense “Ironwood” engine under HTML5

Hexlicense consists of two parts: the first is the generation process where you mint license numbers. These numbers have some nifty criteria attached to them, like being able to verify that they have indeed been minted using a root-key,  that they evolve and mutate in a non-linear fashion and naturally: they should obfuscate as much as possible.

The second part is the validation process. This is where the customer inputs the serial number he received when he bought your software. Under Delphi you validate such keys inside your Delphi program via the THexLicense component. In the future you will be able to do this via the HexLicense server system as well, which makes is going to make your life as a developer a lot easier.

HexLicense for Smart Mobile Studio covers both aspects, so you can perform the minting and validation. The code is so universal that it will run on your node.js server, in your visual applications – most of the code is actually shared between Delphi and Smart Mobile Studio.

Note: The demo of HexLicense running in your browser is just for educational purposes. It demonstrates that Smart Mobile Studio is capable of some very nifty things. And it also demonstrates the speed and flexibility of HexLicense.

Hexlicense 1.0.1 for VCL is shipping

October 4, 2016 Leave a comment

HexLicense v1.0.1 has now started shipping to customers! And hot on the heels of the VCL implementation comes the FMX version (due shortly).

HexLicense test running on Android [FMX]

HexLicense test running on Android [FMX]

The Android implementation passed all tests yesterday, with the iOS session due for thursday. So hopefully the FMX edition will ship at the beginning of next week.

Head over to www.hexlicense.com and grab your copy while the 40% discount is on!

What up next?

While focus is on finalizing the FMX platform, the server edition is also being worked on.

You will be happy to know that it’s going to be a low-latency websocket client/server solution. This means your products can validate their licenses from HTML5, node.js, Delphi, FPC, C#, C++ or any language that supports ordinary websocket.

Two servers

Two versions of the server is planned: one native win32/64, and one node.js server written in Smart Mobile Studio. The native version uses the ZeosDB library giving you a rich set of options for what database you want to use. By default it uses sqlite which is more than enough for handling <500.000 licenses. However the pro edition will use mysql embedded for maximum performance.

The websocket prototype is already in the making

The websocket prototype is already in the making

The node.js edition enoys the full onslaught of node modules for data storage. Be it clound managed through Amazon or Azure – or a more humble, local sqlite database. You pick what is best for you and your product.

More ciphers, more encryption and more tools! Head over to hexlicense and check it out