Harbour is a fourth generation (4GL) computer language based on the C language.
You may subscribe from devices like your Android phones and tablets, or any desktop browsers. Feel free to subscribe from multiple devices.
This site is dedicated to extend the knowledge of the Harbour Computer Language. Authors, expert in different aspect of the language, can share their knowledge, by creating and publishing articles.
Harbour is the open/free software implementation of a cross-platform, multi-threading, object-oriented, scriptable programming language, backwards compatible with xBase languages.
This site is and will remain a free resource to the Harbour community. No advertisement will be published on this site. Current hosting is provided by EL SoftWare, Inc.
We hope to create a Software Foundation for Harbour that could be similar to the Python Software Foundation (PFT). Please use the "Contact Us" page if you are interested in creating such foundation.
Some aspects of this site are still under constructions, particularly a searchable reference of the language and additional information to assist VFP developers in migrating to Harbour.
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.
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.”
(The following notice is similar to the one used by python.org
This site does not claim ownership of any third-party code or content (“third party content”) placed on the web site and has no obligation of any kind with respect to such third party content. Any third party content provided in connection with this web site is provided on a non-confidential basis. This site is free to use or disseminate such content on an unrestricted basis for any purpose, and third party content providers grant this site and all other users of the web site an irrevocable, worldwide, royalty-free, nonexclusive license to reproduce, distribute, transmit, display, perform, and publish such content, including in digital form.
Third party content providers represent and warrant that they have obtained the proper governmental authorizations for the export and reexport of any software or other content contributed to this web site by the third-party content provider, and further affirm that any United States-sourced cryptographic software is not intended for use by a foreign government end-user.