Chapter 10. Appendix C: Language Comparisons

Qore's syntax superficially appears to be a mixture of C, Java and perl with some unique features to Qore (such as context statements, etc).

Because no independent comparison of Qore with other languages exists, I'll try to compare Qore to perl and Java as objectively as possible in this section (since I used these two languages to get ideas for the interface for Qore). In my opinion, it's not really possible to make totally objective language comparison (particularly when the author of the language makes it!), but I'll do ma best anyway...

10.1. Qore and perl

Firs of all, Qore is not perl; perl is a robust, mature, feature-full, and powerful language, and Qore is a new, young, and (compared to perl) relatively limited language and differs philosophically in some areas.

(Some) similarities to perl:

  • Qore is a weakly-typed scripting language

  • Qore variable references begin with a dollar sign "$". (ex: $value is a valid variable in both perl and Qore)

  • In Qore, subroutines are declared with the keyword sub

  • Qore and perl share many statements (like for, foreach, while, do, if, etc), and operators.

  • Qore and perl share many basic operators

  • Qore and perl both use double-precision floating point numbers

  • Qore uses PCRE to provide perl5-compatible regular expression support

  • Qore and perl support closures that encapsulate the state of local variables accessed within the closure. Qore additionally provides thread-safe access even to these "persistent" local variables, even when the closure is used in a multi-threaded context.

(Some) differences from perl:

  • Qore has a clean and powerful threading model, built-in from the start by design

  • Qore has clean object-oriented features, built-in from the start by design

  • Qore has transparent UTF-8 support (qore's substr(), string splice, index(), reverse(), etc work on character offsets, not byte offsets according to the character encoding used for the string), perl's wide character support is not as transparent - for example, 'printf("%s\n", substr("ä", 0, 1));' will output an invalid character in perl, but work properly in Qore using UTF-8 variable-width characters

  • Qore tends to avoid syntactic shortcuts and require more verbose expressions than perl; Qore has a much smaller grammar than perl; Qore has if statements, but no "unless"; etc

  • A Qore variable can be of any type, whereas in perl the type of variable also depends on the name

    perl:

    @array = (1, "two"); 
    %hash = ( "a", 1, "b", 2);
    $scalar = 3.0;

    Qore:

    $array = (1, "two");
    $hash = ( "a" : 1, "b" : 2);
    $scalar = 3.0;

  • Qore subroutines can be declared with an optional list of local variables to receive subroutine arguments; the parentheses after the subroutine name are not optional.

  • Qore accepts a statement or a statement block after if, while, for, foreach, etc, like C, C++, and Java, but unlike perl that requires a block ("{" "}") after such statements.

  • Qore's splice operator works on strings (respecting character offsets for multi-byte character encodings) as well as lists.

  • Qore has a switch/case statement, whereas perl has none

  • Qore hashes must be specified with a specific syntax, ex:

    ( "key" : expression )
  • Qore's object-oriented features are very different from perl's.

  • Qore's exception handling is more similar to C++ or Java's.

  • Qore has very tight database integration and syntactic support for processing query results (context statements, find expressions)

  • Qore uses 64-bit integers by default even on 32-bit platforms.

  • Qore's operators can change lvalues without references, in Qore a function can change an lvalue only if a reference is passed

  • there is currently no generic equivalent to perl's references. It is only possible to pass values by reference in Qore if the subroutine includes a local variable argument list

  • Qore features support for safe signal handling as well.