Harbour (programming language): Difference between revisions

Content deleted Content added
m I have made some important changes like the spelling errors and remove likes which pages are not available.
Database support: WP:LINKs: update-standardizes, needless-WP:PIPEs > WP:NOPIPEs, adds. MOS:FIRSTABBReviations clarify, define before parenthetic WP:ABBRs. Small WP:COPYEDITs WP:EoS: WP:TERSE, clarify.
 
(19 intermediate revisions by 14 users not shown)
Line 1:
{{shortShort description|Computer programming language}}
{{multipleMultiple issues|
{{primaryPrimary sources|date=March 2018}}
{{toneTone|date=April 2019}}
}}
{{Use dmy dates|date=June 2014}}
 
{{Infobox programming language
| name = Harbour Project
| logo =
| logo caption =
| screenshot =
| paradigm = [[Multi-paradigm programming language|multi-paradigm]]: [[Imperative programming|imperative]], [[Functional programming|functional]], [[Object-oriented programming|object-oriented]], [[Reflective programming|reflective]]
| screenshot caption =
| year = {{Start date and age|1999}}
| paradigm = [[Multi-paradigm programming language|multi-paradigm]]: [[Imperative programming|imperative]], [[Functional programming|functional]], [[Object-oriented programming|object-oriented]], [[Reflective programming|reflective]]
| designer = Antonio Linares
| family = [[xBase]]
| developer = Viktor Szakáts and community
| designer = Antonio Linares
| latest_release_version = 3.0.0
| developer = Viktor Szakáts and community
| latest_release_date = {{Start date and age|df=yes|2011|07|17}}
| year released = {{Start date and age|1999}}
| latest_preview_version = [https://sourceforge.net/projects/harbour-project/files/binaries-windows/nightly/ 3.2.0dev]
| latest release version = 3.0.0
| typing = Optionally [[duck typing|duck]], [[dynamic typing|dynamic]], [[type safety|safe]], partially [[strong typing|strong]]
| latest_release_date latest release date = {{Start date and age|df=yes|2011|07|17|df=yes}}
| implementations =
| latest_preview_versionlatest preview version = [https://sourceforge.net/projects/harbour-project/files/binaries-windows/nightly/ 3.2.0dev]
| dialects = Clipper, Xbase++, FlagShip, FoxPro, xHarbour
| typing = Optionally [[duck typing|duck]], [[dynamic typing|dynamic]], [[type safety|safe]], partiallypartly [[strongStrong and weak typing|strong]]
| influenced_by = dBase, Clipper
| implementations =
| influenced = [[xHarbour]]
| dialects = Clipper, Xbase++, FlagShip, FoxPro, xHarbour
| operating_system = [[Cross-platform]]
| operating system = [[Cross-platform software|Cross-platform]]
| license = [[Open-source license|Open-source]] [[GNU General Public License|GPL]]-compatible
| website = {{URL|https://harbour.github.io/}}
| file_ext file ext = .prg, .ch, .hb, .hbp
| wikibooks =
| influenced by = [[dBase]], [[Clipper (programming language)|Clipper]]
| influenced = [[xHarbour]]
}}
 
'''Harbour''' is a computer [[programming language]], primarily used mainly to create database/business programs. It is a modernized, [[Open-source software|open source]]d andmodernised [[cross-platform]] version of the older [[Clipper (programming language)|Clipper]] system, which in turn developed from the [[dBase]] database market of the 1980s and 1990s. It is [[free and open-source software]] which license is [[GNU General Public License]] (GPL) compatible.
 
Harbour code usinguses the same databases and can be compiled under a wide variety of platforms, including [[Microsoft Windows|Windows]], [[Linux]], [[Unix]] variants, several [[BSDBerkeley Software Distribution]] (BSD) descendants, [[Mac OS XmacOS]], [[MINIXMinix 3]], [[Windows CE]], [[Pocket PC]], [[Symbian]], [[iOS]], [[Android (operating system)|Android]], [[QNX]], [[VxWorks]], [[OS/2]] (including [[eComStation]] and [[ArcaOS]]),<ref>{{cite web|url=https://ecsoft2.org/harbour|access-date=2020-09-03|title=Harbour}}</ref> [[BeOS]]/[[Haiku (operating system)|Haiku]], [[IBM AIX|AIX]], and [[DOS]].
[[IBM AIX|AIX]] and [[MS-DOS]].
 
== History ==
The idea of a free software Clipper compiler had been floating aroundarising for a long time and the subject hasoccurred often cropped up in discussion on comp.lang.clipper. Antonio Linares founded the Harbour project and the implementation was started in March 1999. The name "Harbour" was proposed by Linares, it is a play on a [[Clipper ship|Clipper]] as a type of ship. Harbour is a synonym for port (where ships dock), and Harbour is a port of the Clipper language.
 
In 2009, Harbour was substantially redesigned, mainly by Viktor Szakáts and Przemyslaw Czerpak.
 
==Database Supportsupport==
Harbour extends the Clipper Replaceable Database Drivers (RDD) approach. It offers multiple RDDs such as [[DBASE|DBFdBase]] (DBF), DBFNTX, DBFCDX, DBFDBT and DBFFPT. In Harbour, multiple RDDs can be used in a singleone application, and new logical RDDs can be defined by combining other RDDs. The RDD architecture allows for [[Inheritance (object-oriented programming)|inheritance]], so that a given RDD may extend the functionalityfunctions of other existing RDD(s). Third-party RDDs, like RDDSQL, RDDSIX, RMDBFCDX, [[Advantage Database Server]], and Mediator exemplify some of the RDD architecture features. DBFNTX implementation has almost the same functionality of DBFCDX and RDDSIX. NETIO and LetoDB<ref>{{cite web |url=https://sourceforge.net/projects/letodb |title=LetoDB |publisher=Sourceforge.net |access-date=2013-12-09}}</ref> provide remote access over [[Transmission Control Protocol|TCP]] protocol(TCP).
 
Harbour also offers [[ODBC]] support by means of an [[Objectobject-oriented programming|OOP]] (OOP) syntax, and [[ActiveX Data Objects|ADO]] (ADO) support by means of [[OLE Automation|OLE]] (OLE). [[MySQL]], [[PostgreSQL]], [[SQLite]], [[Firebird (database server)|Firebird]], [[Oracle (database)|Oracle]] are examples of databases which Harbour can connect to.
Harbour extends the Clipper Replaceable Database Drivers (RDD) approach. It offers multiple RDDs such as [[DBASE|DBF]], DBFNTX, DBFCDX, DBFDBT and DBFFPT. In Harbour multiple RDDs can be used in a single application, and new logical RDDs can be defined by combining other RDDs. The RDD architecture allows for inheritance, so that a given RDD may extend the functionality of other existing RDD(s). Third-party RDDs, like RDDSQL, RDDSIX, RMDBFCDX, [[Advantage Database Server]], and Mediator exemplify some of the RDD architecture features. DBFNTX implementation has almost the same functionality of DBFCDX and RDDSIX. NETIO and LetoDB<ref>{{cite web|url=https://sourceforge.net/projects/letodb |title=LetoDB |publisher=Sourceforge.net |access-date=2013-12-09}}</ref> provide remote access over [[Transmission Control Protocol|TCP]] protocol.
 
[[xBase]] technologies often are confused often with [[RDBMSrelational database management system]] (RDBMS) software. AlthoughWhile thisxBase iswas promoted as truerelational, xBase is more than a simple database system, as at the same time, xBase languages using purely DBF can notcannot provide the full conceptfeatures of a realfull RDBMS.
Harbour also offers [[ODBC]] support by means of an [[Object-oriented programming|OOP]] syntax, and [[ActiveX Data Objects|ADO]] support by means of [[OLE Automation|OLE]]. [[MySQL]], [[PostgreSQL]], [[SQLite]], [[Firebird (database server)|Firebird]], [[Oracle (database)|Oracle]] are examples of databases which Harbour can connect to.
 
==Programming Philosophyphilosophy==
xBase technologies often are confused with [[RDBMS]] software. Although this is true, xBase is more than a simple database system as at the same time xBase languages using purely DBF can not provide the full concept of a real RDBMS.
Unlike Java which is intended to be written once, run anywhere, Harbour aims to be [[Write once, compile anywhere|written once, compiled anywhere]]. As the same compiler is available for all of the above operating systems, there is no need for recordingre-coding to produce identical products for different platforms, except when operating system dependent features are used. Cross-compiling is supported with [[MinGW]]. Under Microsoft Windows, Harbour is more stable but less well-documented than Clipper, but has multi-platform ability and is more transparent, allows for more customisation and can run from a USB flash drive.
 
==Programming Philosophy==
Unlike Java which is intended to be written once, run anywhere, Harbour aims to be [[Write once, compile anywhere|written once, compiled anywhere]]. As the same compiler is available for all of the above operating systems, there is no need for recording to produce identical products for different platforms, except when operating system dependent features are used. Cross-compiling is supported with [[MinGW]].
Under Microsoft Windows, Harbour is more stable but less well-documented than Clipper, but has multi-platform capability and is more transparent, customizable and can run from a USB flash drive.
 
Under Linux and Windows Mobile, Clipper source code can be compiled with Harbour with very little adaptation. Most software originally written to run on Xbase++, FlagShip, FoxPro, xHarbour and others dialects can be compiled with Harbor with some adaptation. As of 2010 many efforts have been made to make the transition from other [[xBase]] dialects easier.
Line 57 ⟶ 56:
[[MinGW]],
[[Clang]],
[[Intel C++ Compiler|ICC]] (ICC),
[[Microsoft Visual C++]] (6.0+),
[[Borland C++]],
Line 66 ⟶ 65:
Harbour can make use of multiple Graphical Terminal emulation, including console drivers, and Hybrid Console/GUIs, such as GTWvt, and GTWvg.
 
Harbour supports external GUI's, free (e.g. HBQt, HWGui, Mini-GUI (latest version based on Qt and QtContribs<ref>{{cite web |title=QtContribs - Harbour Qt Projects |url=https://sourceforge.net/projects/qtcontribs/ |website=SourceForge |date=6 July 2023 |language=en}}</ref>) and commercial (e.g. FiveWin, Xailer). HBQt is a library providing bindings to Qt. HBIDE application is a sample of HBQt potential.
 
Harbour is 100% Clipper-compatible<ref>{{cite web|url=https://harbour.github.io/ |title=Official Harbour page |publisher=The Harbour Project |access-date=2013-12-09}}</ref> and supports many language syntax extensions including greatly extended run-time libraries such as [[OLE Automation|OLE]], Blat, [[OpenSSL]], Free Image, [[GD Graphics Library|GD]], hbtip, hbtpathy, [[PCRE]], hbmzip ([[zlib]]), hbbz2 ([[bzip2]]), [[cURL]], [[Cairo (graphics)|Cairo]], its own implementation of CA-Tools, updated NanFor libraries and many others. Harbour has an active development community and extensive third party support.
Line 72 ⟶ 71:
Any [[xBase]] language provides a very productive way to build business and data intensive applications. Harbour is not an exception.
 
===Macro Operatoroperator (runtime compiler)===
One of the most powerful features of xBase languages is the [[Macro (computer science)|Macro]] Operator '&'. Harbour's implementation of the Macro Operator allows for runtime compilation of any valid Harbour expression. Such a compiled expression may be used as a VALUE, i.e. the right side of an assignment (rvalue), but such a compiled expressionor may be used to resolve the left side (lvalue) of an assignment, i.e. private, or public variables, or a database field.
 
One of the most powerful features of xBase languages is the [[Macro (computer science)|Macro]] Operator '&'. Harbour's implementation of the Macro Operator allows for runtime compilation of any valid Harbour expression. Such a compiled expression may be used as a VALUE, i.e. the right side of an assignment (rvalue), but such a compiled expression may be used to resolve the left side (lvalue) of an assignment, i.e. private, or public variables, or a database field.
 
Additionally, the Macro Operator may compile and execute function calls, complete assignments, or even list of arguments, and the result of the macro may be used to resolve any of the above contexts in the compiled application. In other words, any Harbour application may be extended and modified at runtime to compile and execute additional code on-demand.
 
The latest Macro compiler can compile any valid Harbour code including code to per-process before compile.
Line 94 ⟶ 92:
is the short form of &( SomeId + "postfix" ).
 
===Object-oriented Oriented Programmingprogramming===
 
Programming in an OOP style is a broader issue than a specific library or a specific interface, but OOP programming is something many Clipper programmers have come to expect. CA-Clipper 5.2 and especially 5.3 added a number of base classes, and a matching OOP syntax. Libraries such as [https://web.archive.org/web/20010501165630/http://appsolutions.com/Classy/ Class(y)], FieWin, Clip4Win, and Top Class provide additional OOP functionality.
 
Harbour has OOP extensions with full support for classes including inheritance, based on Class(y) syntax. OOP syntax in Harbour is very similar to that of earlier Clipper class libraries so it should be possible to maintain legacy Clipper code with minimal changes.
 
==Syntax and Semanticssemantics==
[[File:Harbour Sample Code.png|thumb|600px|Harbour code on HBIDE]]
 
Line 106 ⟶ 103:
 
===Built-in data types===
Harbour has six scalar types : [[Null pointer|Nil]], [[String (computer science)|String]], [[calendar date|Date]], [[Logical]], [[Integer|Numeric]], [[Pointer (computer programming)|Pointer]], and four complex types: [[Array data type|Array]], [[Object (computer science)|Object]], [[Closure (computer science)|CodeBlock]], and [[Hash table|Hash]]. A scalar holds a single value, such as a string, numeric, or reference to any other type. Arrays are ordered lists of scalars or complex types, indexed by number, starting at 1. Hashes, or [[associative array]]s, are unordered collections of any type values indexed by their associated key, which may be of any scalar or complex type.
 
Literal (static) representation of scalar types:
Line 116 ⟶ 113:
 
Complex Types may also be represent as literal values:
* Array: <syntaxhighlight lang=visualfoxprofoxpro inline>{ "String", 1, { "Nested Array" }, .T., FunctionCall(), @FunctionPointer() }</syntaxhighlight>
* [[CodeBlock]]: <syntaxhighlight lang=visualfoxprofoxpro inline>{ |Arg1, ArgN| Arg1 := ArgN + OuterVar + FunctionCall() }</syntaxhighlight>
* Hash: <syntaxhighlight lang=visualfoxprofoxpro inline>{ "Name" => "John", 1 => "Numeric key", "Name2" => { "Nested" => "Hash" } }</syntaxhighlight>
Hashes may use ''any'' type including other Hashes as the ''Key'' for any element. Hashes and Arrays may contain ''any'' type as the ''Value'' of any member, including nesting arrays, and Hashes.
 
Codeblocks may have references to Variables of the Procedure/Function>method in which it was defined. Such Codeblocks may be returned as a value, or by means of an argument passed {{monocode|BY REFERENCE}}, in such case the Codeblock will "outlive" the routine in which it was defined, and any variables it references, will be a {{monocode|DETACHED}} variable.
 
Detached variables will maintain their value for as long as a Codeblock referencing them still exists. Such values will be shared with any other Codeblock which may have access to those same variables. If the Codeblock did not outlive its containing routine, and will be evaluated within the lifetime of the routine in which it is defined, changes to its ''Detached Variables''(s) by means of its evaluation, will be reflected back at its parent routine.
 
Codeblocks can be evaluated any number of times, by means of the {{monocode|Eval( ''BlockExp'' )}} function.
 
===Variables===
Line 132 ⟶ 129:
'''Variables have one of the following scopes:'''
 
* {{monocode|LOCAL}}: Visible only within the routine which declared it. Value is lost upon exit of the routine.
* {{monocode|STATIC}}: Visible only within the routine which declared it. Value is preserved for subsequent invocations of the routine. If a STATIC variable is declared before any Procedure/Function/Method is defined, it has a MODULE scope, and is visible within any routine defined within that same source file, it will maintain its life for the duration of the application lifetime.
* {{monocode|PRIVATE}}: Visible within the routine which declared it, and all routines {{monocode|called}} by that routine.
* {{monocode|PUBLIC}}: Visible by {{monocode|all}} routines in the same application.
 
{{monocode|LOCAL}} and {{monocode|STATIC}} are resolved at compile time, and thus are much faster than {{monocode|PRIVATE}} and {{monocode|PUBLIC}} variables which are dynamic entities accessed by means of a runtime [[Symbol table]]. For this same reason, {{monocode|LOCAL}} and {{monocode|STATIC}} variables are {{monocode|not}} exposed to the Macro compiler, and any macro code which attempts to reference them will generate a runtime error.
 
Due to the dynamic nature of {{monocode|PRIVATE}} and {{monocode|PUBLIC}} variables, they can be created and destroyed at runtime, and can be accessed and modified by means of runtime macros, and can be accessed and modifiedor by Codeblocks created on the fly.
 
=== Control Structuresstructures ===
The basic control structures include all of the standard [[dBase]], and [[Clipper (programming language)|Clipper]] control structures as well as additional ones inspired by the [[C (programming language)|C]] or [[Java (programming language)|Java]] programming languages:
 
Line 187 ⟶ 184:
The condition expression(s) has to evaluate to a ''LOGICAL'' value.
 
====SWITCH Statementsstatements====
Harbour supports a SWITCH construct inspired by the C implementation of switch().
 
Line 204 ⟶ 201:
* The ''EXIT'' optional statement is the equivalent of the C statement ''break'', and if present, execution of the SWITCH structure will end when the EXIT statement is reached, otherwise it will continue with the first statement below the next CASE statement (fall through).
 
====BEGIN SEQUENCE Statementsstatements====
BEGIN SEQUENCE
''...''
Line 227 ⟶ 224:
Alternatively TRY [CATCH] [FINALLY] statements are available on ''xhb'' library working like the SEQUENCE construct.
 
===Procedures and Functionsfunctions===
[STATIC] PROCEDURE ''SomeProcedureName''
[STATIC] PROCEDURE ''SomeProcedureName''()
Line 239 ⟶ 236:
[STATIC] FUNCTION ''SomeProcedureName''( ''Param1'' [, ''ParamsN''] )
 
[[Subroutine|Procedures]] and [[Functionfunction (computer science)|Functionsfunctions]] in Harbour can be specified with the [[keyword (computer programming)|keyword]]s <code>PROCEDURE</code>, or <code>FUNCTION</code>. Naming rules are the same as those for ''Variables'' (up to 63 characters non-case sensitive). Both Procedures and Functions may be qualified by the scope qualifier ''STATIC'' to restrict their usage to the scope of the module where defined.
 
The ''INIT'' or ''EXIT'' optional qualifiers, will flag the procedure to be automatically invoked just before calling the application startup procedure, or just after quitting the application, respectively. [[Parameter (computer science)|Parameter]]s passed to a procedure/function appear in the subroutine as local variables, and may accept any type, including references.
Line 251 ⟶ 248:
An example procedure definition and a function call follows:
 
<syntaxhighlight lang="visualfoxprofoxpro">
x := Cube( 2 )
 
Line 258 ⟶ 255:
</syntaxhighlight>
 
===Sample Codecode===
The typical "[["Hello, World!" program|hello world]]" program would be:
<syntaxhighlight lang="visualfoxprofoxpro">
? "Hello, world!"
</syntaxhighlight>
Or:
<syntaxhighlight lang="visualfoxprofoxpro">
QOut( "Hello, world!" )
</syntaxhighlight>
Or:
<syntaxhighlight lang="visualfoxprofoxpro">
Alert( "Hello, world!" )
</syntaxhighlight>
Or, enclosed in an explicit procedure:
 
<syntaxhighlight lang="visualfoxprofoxpro">
PROCEDURE Main()
 
Line 281 ⟶ 278:
</syntaxhighlight>
 
====OOP Examplesexamples====
Main procedure:
<syntaxhighlight lang="vfp">
Line 349 ⟶ 346:
* hbi18n – Tools to localizing text on applications
* hbdoc – Creates documentation for Harbour
 
All tools are multi-platform.
 
Line 356 ⟶ 354:
As of 2015 Harbour development is active and vibrant.
 
==xHarbour Comparisoncomparison==
[[xHarbour]] is a fork<ref>{{cite web|url=http://www.xharbour.org/index.asp?page=about/index |title=About xHarbour |publisher=Xharbour.org |access-date=2013-12-09}}</ref> of the earlier Harbour project. xHarbour takes a more aggressive approach to implementing new features in the language, while Harbour is more conservative in its approach, aiming first of all for an exact replication of Clipper behaviour and then implementing new features and extensions as a secondary consideration. It should also be noted that Harbour is supported on a wide variety of [[operating systems]] while xHarbour only really supports MS Windows and Linux 32-bit.
 
The Harbour developers have attempted to document all hidden behaviour in the Clipper language and test Harbour-compiled code alongside the same code compiled with Clipper to maintain compatibility.
Line 365 ⟶ 363:
A detailed comparison between extensions implemented in Harbour and xHarbour can be found in the source repository of the project on GitHub.<ref>{{cite web|url=https://github.com/harbour/core/raw/master/doc/xhb-diff.txt |title=xhb-diff.txt |website=[[GitHub]] |access-date=2013-12-09}}</ref>
 
==GUI Librarieslibraries and Toolstools==
* '''[https://sourceforge.net/projects/qtcontribs/ hbide]''' – [[Integrated Development Environment]] to help Harbour development and various xBase dialects
* '''[https://ptsource.github.io/Developer-Platform/ PTSource IDE]''' – [[Integrated Development Environment]] includes Harbour
* '''[https://sourceforge.net/projects/hwgui/ HwGui]''' – Open Source cross-platform GUI library for Harbour
* '''[https://hmg.ruano.org/index.php HMG]''' – Free /, Open Source xBase [[Win32]] / [[GUI]] Development System for Harbour
* '''[http://hmgextended.com/ MiniGUI]'''<ref>{{cite web|author=vailtom |url=https://sourceforge.net/projects/hmgs-minigui/ |title=Harbour MiniGUI Extended Edition. &#124; Free Communications software downloads at |publisher=Sourceforge.net |date=17 August 2009 |access-date=2013-12-09}}</ref> – Free / Open Source xBase Win32 / GUI Development System (a [[Fork (software development)]] of both HMG and Harbour)
* '''[https://oohg.github.io/ ooHG]''' – Object Oriented Harbour GUI – a fork "class based and oop programming" of HMG
* '''[http://marinas-gui.org/ Marinas-GUI]''' – Multi-Platform QT Based GUI Development Package for Harbour. Marinas-GUI downloads as a complete installation package for the chosen target platform (IDE, Version Control, Harbour/C Compiler, Libraries etc.) – Basically install and start coding and compiling
 
== See Also also==
* [[Visual FoxPro]]
* [[Visual Objects]]
* [[XBase++|Xbase++]]
* [[PWCT]] free open source visual programming language support Harbour through [[PWCT#Visual Languageslanguages|HarbourPWCT]]
 
==References==
{{Reflist}}
 
== External Links links==
* {{officialOfficial website|https://harbour.github.io}}
* [https://harbour.github.io/the-oasis/ The Oasis] Clipper, FoxPro and Xbase++ community repository
* [http://hbide.vouch.info/ HBIDE]
Line 390 ⟶ 388:
* [https://groups.google.com/group/harbour-users/ Harbour Users Mailing List]
* [http://www.kresin.ru/en/harbour.html Extensive Harbour documentation, libraries, tools site]
*[https://github.com/ {{GitHub|Petewg/harbour-core/wiki}}, Harbour WikiDictionary (Harbourof Functions Dictionary)]Wiki
 
{{xBase}}
Line 411 ⟶ 409:
[[Category:Free software programmed in C]]
[[Category:Multi-paradigm programming languages]]
[[Category:Table-oriented programming]]
<!-- Hidden categories below -->
[[Category:Articles with example code]]