Main image of article Qore: A New Programming Language Worth a Look

New programming languages are created all the time. Over the past 10 years alone, we've seen the emergence of Rust, Dart, Kotlin, Elixir, Red, Julia, TypeScript and Swift—and those are just the better-known ones (lesser-known ones include P4, PureScript, Hopscotch, Hack, Zig, Ballerina and Bosque). 

Here's a new name to add to that list of new languages: Qore. Although Qore hasn’t yet hit version 1.0 (it’s at 0.9.4), it's clear that a lot of work has been done, giving it the feel of a very practical programming language.

What kind of Programming language is Qore?

Qore was originally designed “to facilitate embedding integration logic in a workflow/technical order management system” (i.e., it was designed as a domain specific language). However, it’s now an interpreted, high-level, general-purpose, dynamic programming language with garbage collection. 

Qore’s syntax has been described as a mix of Perl, Java, C++ and D with a touch of Haskell. Considering the extensive detailing of the reference pages, it's surprising that there are so few examples of source code. The only examples I've found were in the examples folder in the Qore GitHub download file and they were narrowly focused on email, webserver, pop3, etc. But perhaps that’s the side effect of a language less than a year old. 

The following example, which gives some flavor of the language, is taken from the file inner.q in the aforementioned examples folder. It uses old-style variables with $ (You'll find mentions of both new-style and old-style in the documentation). The old style is more Perl-like with $ variables, as seen below. The newer style does away with $, and is more Java/C+-like and definitely more compact. 

Both new-style and old-style are compiler directives, so you are free to switch between them. A utility script, old2new, is provided in the examples:

class Base2 {
    # declare some private members
    private $.base2, $.y;

    constructor($a) {
        printf("Base2::constructor(%n)\n", $a);
        $.b = $a;
    }
    copy() {
        printf("Base2::copy() (%n)\n", $.b);
        $.b = $.b + "-copy"; 
    }
    destructor() {
        printf("Base2::destructor() (%n)\n", $.b);
    }
    hello() {
        printf("Base2 hello (%n)\n", $.b);
    }

    # note that "Base2" here is just a regular method, the constructor
    # is always named "constructor"
    Base2($a) {
        printf("Base2::Base2() (%n) %n\n", $.b, $a);
    }
}

The Language

Qore is a scripting language and has a Linux feel to it. The first line in most scripts specifies the location of the Qore interpreter, similar to Python. Also, like Python, # are comments: 

#!/usr/bin/qore

Qore is weakly typed, so variables can hold any type unless you have specified a type. This is known as optionally strong. 

In the example below, the words ‘our’ and ‘my’ are used to distinguish between global and local variables. The int ‘a’ that is assigned a value ‘2’ is also local, whereas the first ‘a’ is global: 

#!/usr/bin/qore
%new-style
our int a = 1;                  # this is a global variable
our (string b, any c, hash d);  # list of global variables
if (a == 1) {
    int a = 2;
    my (string b, any c);
    printf("local a = %d\n", a);
}
printf("global a = %d\n", a);

If you know C or C++, you'll find the syntax quite similar. As well as standard types such as Boolean, String, Integer etc., there's also Number, an arbitrary precision floating point type. But it gets more interesting with things such as multiple assignments in one statement:

(a, b, c, date) = (1, "two", 3.3, 2005-10-28)

Modules

One way to extend the language is by using modules. With Qore, around 60 are provided, including high-level features such as an HTTP server, APIs for networking, working with MySQL, PostgreSQL and SQLite, unit testing and so on. There are also another 20 modules provided separately (and of course, you can write your own). Modules are provided either in source form (user) or compiled C++ (binary). 

In an unusual twist for a scripting language, Qore supports Posix threads. There's an extensive array of classes to manage threading objects such as locks, counters, gates, mutexes and queues. 

Garbage Collection

Qore supports garbage collection, using reference counting. When an object goes out of scope and the reference count reaches 0, the destructor is called. However, it can also detect cycles (as in cyclic directed graphs), which is quite clever (normally, this would make garbage collection difficult). 

Conclusion: Qore Worth a Look

Being a scripting language, Qore could replace C++/Java and Python utilities, especially as there’s no need to compile it.  In fact, you currently can’t compile, but a Qore compiler is under development.

The detailed online reference manual is light on examples, despite giving the language an intensive walk-through. It is a very practical language with many operators, including some from C++ but also list processing. 

The authors admit that it is in a state of transition from the old weakly-typed Perl like language to a stronger-typed language with the new_style syntax. If you are considering Qore, it's worth taking a look at the Qore Wiki, particularly the ProTips page

If this were on Windows, I’d see it as a rival to PowerShell. In any case, this is definitely a language to watch.