What is Harbour?
Harbour is an open-source implementation of a xBase computer language, that is compatible on any platforms supporting C based applications, meaning MS Windows, Mac OS, Linux, Unix, iOS, and can generate 32-bit and 64-bit applications and libraries.
xBase is the generic term for all programming languages that derive from the original dBASE programming language and database formats (https://en.wikipedia.org/wiki/XBase) that was first released in 1979. Harbour is classified as a 4GL language since its compiler generates pure C source code. Harbour-generated applications are self-contained, meaning they do not require external runtime libraries. Harbour programs can be compiled to use an embedded VM (virtual machine including in final EXE), or without any VM (could run faster but bigger executable). Harbour has an embedded “stand-by” compiler that is similar to VFP’s macros.
Harbour can be classified as an object-oriented, functional and data-centric language that also supports procedures and functions. Harbour can also generate multi-threaded applications, such as web and socket servers. Virtually any C libraries can be embedded with Harbour.
Where does it come from?
The original Harbour implementation was started in 1999 as a 100% clone of Clipper, a defunct language that was a compiler version of dBase. During the last 20 years, Harbour went through majors changes, in part due to a forked version called xHarbour. Most features of xHarbour, a commercial fork, are now re-implemented in Harbour, for the exception of a form builder (closer to FoxPro for Windows than VFP). Most of the development of Harbour was done by a handful of extremely skilled C developers. All the source code and contributor information can be found on GitHub at https://github.com/harbour/core
How come most people have never heard of it?
The Harbour community is comprised of developers from around the world; this is an open-source project with no corporate backing. It has suffered due to conflict between developers wanting to remain a 100% Clipper clone, and those wanting to evolve the language (mainly the xHarbour supporters). I hadn’t heard much of Harbour until I began working for a mid-to-large sized company that relied 100% on it for its core product. I only knew of Xbase++ by Alaska Software. I discovered that Harbour had virtually everything Xbase++ had except for easy web development (but it started to as of early 2020). Unlike Xbase++, Harbour is open-source, all operating systems, and 64-bit compatible.
How does it compare to VFP?
VFP is one of the most amazing languages I had the chance to work with, and I did/do use many of them. VFP 9 is closed source code, not free, and can only run on MS Windows. Only Windows 32-bit applications can be generated (using original system). But VFP has an incredible Form and Class builder, that supports visual inheritance. VFP has native a SQL engine embedded in the language (which was the foundation for MS-SQL). VFP comes with its own CLI (command window) and a decent editor.
Harbour does not have a built-in Form or Class designer. There are multiple open-source and commercial packages that can be used with Harbour core. But none have visual inheritance. Harbour is in the same state as Python: a great language but no easy solution for desktop/UI development. But since most new products are now web apps, so long as you generate HTML, CSS, JS, you should be fine. Will review more on this subject later.
With regard to embedded SQL, I recently released an open-source Harbour-ORM which adds easy support to MariaDB, MySQL and PostgreSQL, and has in-memory tables (VFP cursors). I will add in-memory SQLite support soon or push-cursor-to-server functionality to allow subsequent SQL commands.
As far as the Integrated Development Environment (IDE) for developing applications, the best choice for Harbour is Visual Studio Code (VSCODE). There is an open-source VSCODE extension for Harbour, which brings support for debugging and IntelliSense. VSCODE has so many amazing extensions which will transform it from an editor to a rich IDE.
As far as comparing the languages, they are fairly similar, but in many areas, Harbour has a richer set of options. And where some features are missing, they can be added fairly easily. I have a GitHub repo where I am adding VFP features to Harbour. Harbour does not have a report writer, but you could consume VFP object wrapper to your reports. Harbour is more of a solution to write new Web apps or to extend VFP by creating Harbour COM objects. Harbour, like Python 3, has full UTF8 support. This is crucial feature for when you are accessing UTF8 encoded SQL backends.
One last important note: Harbour-generated programs are MUCH faster than VFP’s. Harbour programs are C programs, so speed differences can be of a factor of ten to several hundred times faster. For example, on a single core I7 laptop Linux VM, using Harbour FastCGI under Lighttpd, we get over 2,000 responses per seconds for a generic “hello world” web page, versus 15 responses per seconds under a VFP/ASP/IIS solution.
How does it compare to other languages?
I wrote an article about this subject on the Harbour Wiki, which I created and host:
“Comparing computer languages, Harbour, VFP and others”
I recommend visiting the link at the top of the article’s web page labeled “Google user forum discussion about this article”. You’ll find extra information and comments/fixes about the article and notes from some X# users.
What could Harbour be used for?
Since Harbour generates pure C code and has a powerful preprocessor, any other C code and libraries can be merged in. You can even write C code inside your PRG files.
Harbour can be used to create Desktop apps, Web apps, COM objects (32-bit and 64-bit), and device-drivers. I even saw someone compile Harbour with Objective-C and create a native iOS app, and another person created a WebAssembly.
In my opinion, Harbour can be a phenomenal tool to create web apps and microservices.
Currently GO is becoming an increasingly popular programming language for creating microservices, especially with large companies in Seattle. Harbour has all the features of GO and all the object-oriented and data-centric features as well.
How does Harbour work?
Harbour is a language and a series of tools. Its syntax is originally from Clipper but has evolved to include all other modern language features like OOP, Hash Arrays (Python Dictionaries), UTF8 support, multi-threading, multi-OS support. Harbour has its root in C, which means that most of the C tooling is also in Harbour. It has a preprocessor, a compiler, a make tool (optional) and a debugger (replaceable). It does not have a CLI, but Visual Code can be used to facilitate rapid prototyping and debugging.
1. The Harbour preprocessor takes PRG files and generates PPO files which are still PRG-like files, but are transformed via preprocessor directives. As in C, those directives are commands defined with a leading “#’ character. We have our typical #define, #include, #if, #elif,#else, #endif, #ifdef, #ifndef. But we have some amazing new directives like #xcommand, #xtranslate that can be used to redefine the language itself. I even heard of a developer that transformed COBOL code into Harbour code. This is also a power set of directives that can help auto-translate VFP command and functions to Harbour equivalents or some newly created functions that would behave like VFP. For example, I implemented the SCAN/ENDSCAN VFP structure using these directives that will call a new VFP_ScanStack() function.
To view examples: https://github.com/EricLendvai/Harbour_VFP/blob/master/hb_vfp.ch
Then there is #pragma directive. This will tell the compiler to behave differently. I listed it in this section, since it looks like a preprocessor directive, but it is used by the Harbour compiler itself. This directive allows you to include actual C code in the middle of your PRG file.
The following is an example of a hybrid Harbour and C code PRG file:
#define MAXLOOP 5
MyOutputDebugString("[Harbour] Starting Hello World")
FOR l_loop := 1 to MAXLOOP
?"Hello Harbour " + alltrim(str(l_loop))
IF l_loop == 3
AltD() // Same as “SET STEP ON” of VFP
MyOutputDebugString("[Harbour] Completed Hello World")
HB_FUNC( MYOUTPUTDEBUGSTRING )
OutputDebugString( hb_parc(1) );
The preprocessor will convert command statements, such as “APPEND BLANK” to a native Harbour function: in this case, “dbAppend()”.
2. The Harbour compiler takes PPO files and generates C files. The same C compiler that was used to build your local copy of Harbour itself will be called to build .obj files, which are actual binary object files.
There are two methodologies for Harbour to create the C source code files. One, the most common, is to create C code that has some PCODE in it, which are basically a series of C arrays with numeric values. This method relies on a Harbour Virtual Machine (HVM), and Harbour Runtime Library (HRL). But all of this gets linked inside a single .EXE or .DLL (or .SO for Linux) you generate with Harbour. The second method is to create C code that does not rely on a HVM and creates all pure C code that can still use the HRL. VFP uses a PCODE-only approach by creating FXP files, which then can get packaged in .APP and .EXE or .DLL. But unlike VFP, Harbour does not rely on VFP runtime files (.dlls). You may wonder why even have a PCODE method in Harbour? The generated C code is smaller, while the source PRGs are larger.
3. The Make tool. To do the final building of a program or library, a linker is needed. The standard C linker can be called. All of these steps can be executed via a MAKEFILE.
Luckily one of the main Harbour contributors created a Harbour-specific make tool instead that automates all building steps. It is called the hbmk2 tool and will use a .HBP file (a text file) as the equivalent of a VFP project file.
Alternatively, Harbour can also generate pseudo-PCODE files, similarly to VFP .FXP files, that are called .HRB files. But those files may not include embedded C code – only pure Harbour source code.
To clarify, there are two type of PCODE in Harbour: one inside C-generated files and one with actual PCODE files with the .HRB extension (not C code).
All of this is more complicated than VFP or other modern languages. But this also provides more options and power to Harbour. Since Harbour is a compiler, most source code errors are detected during the compilation process instead of at runtime.
I created a flowchart that shows the Harbour Language Compilation Process. To view this chart at full scale: https://harbour.wiki
From the home page go to “Click here to review the Harbour Language Compilation Process Diagram.”