Harbour Differences

Differences between Harbour and other compatible compilers ( xHarbour, Clipper, xBase++, CLIP, FlagShip )

 

Compile time support for merging multiple .prg modules
New language statements
FOR EACH
WITH OBJECT / END[WITH]
SWITCH / [ CASE / [EXIT] / … ] OTHERWISE / END[SWITCH]
BEGIN SEQUENCE [ WITH <ERRBLOCK> ] … END SEQUENCE
Extended codeblocks
Hash arrays
References to variables stored in arrays
Passing array and hash items by reference
Passing object variables by reference
Detached locals and references
Declaration and initialization of variables
Functions with variable number of parameters
Hb_ArrayToParams() function
Macros with declared symbols
Macro messages
Multivalue macros
Using [] operator for string items
Negative indexes in [] operator used to access items from tail
Using one character length string as numeric value
New bit operators
IN, HAS, LIKE operators
Pre/post incrementation/decrementation and <op>= operators
Global / global external (global_extern)
DATETIME/TIMESTAMP values
Literal date and TIMESTAMP values
Extended literal string in compiler and macrocompiler
Symbol items and function references
OOP scopes
OOP and multiinheritance
OOP and private/hidden datas
OOP and class object/class messages
Typed object variables
Object destructors
Scalar classes
Runtime class modification
Array and string preallocation
DIVERT statement
Namespaces
Multi window GTs and runtime GT switching
Multi thread support
Thread local work areas and concurrent work area access
Harbour tasks and MT support in DOS
Background task
Codeblock serialization / deserialization
Native RDDs
Regular expressions
INET sockets
I18N (internationalization) support
ZLIB (compression/decompression)
Serial port support
Macro compiler
Compiler library
PP library
Lexer
Contrib libraries
Portability
C level compatibility
HBRUN / XBSCRIPT
HBMK2
Performance and resource usage

This list borrowed from Harbour github documentation; please look at there for details.

 

How I can check validity of a macro ?

PROC MAIN()

    nResult   := NIL
    nDivident := 1
    nDivisor  := 0
    cMacro    := " nResult := nDivident / nDivisor "  
    QOutResult( nDivident, nDivisor, cMacro ) // 1  0  UE macro is inValid

    nDivisor  := 2
    QOutResult( nDivident, nDivisor, cMacro ) // 1  2  N  Result is :  0.50

    cMacro    := "AT( 'OK', MyUDF() ) > 0"              
    QOutResult( 'AT( OK', 'MyUDF()', cMacro ) // AT( OK ... U macro is inValid

    cMacro    :=  "{ 1, 2 }[ 2 ]"                       
    QOutResult( '{ 1, 2 }', '[2]', cMacro ) // { 1, 2 } [2]   N Result is : 2

    cMacro    :=  "{ 1, 2 }[ 5 ]"  
    QOutResult( '{ 1, 2 }', '[5]', cMacro ) // { 1, 2 } [5] UE macro is inValid

    lCond := 0
    cMacro    :=  "if( lCond, 'true', MyUDF() )"
    QOutResult( lCond, '', cMacro )           // 0        U macro is inValid   
    ?
    WAIT

RETU // Main()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC QOutResult( xVal1, xVal2, cMacro )

	LOCAL cType := TYPE( cMacro )

	? PAD( xVal1, 10 ), PAD( xVal2, 10 ),  PAD( cType, 3 )

    IF ( cType # "U") 
       ?? "Result is :", &cMacro
    ELSE
       ?? "macro is inValid"
    ENDIF

RETU // QOutResult()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._

See Also:

& (macro evaluation unary) Operator 

Macro Compiler

HB_SetMacro()

ValType()

TYPE()

C5_TYPE()

Coding Guidelines

Coding Guidelines

( by Greg Holmes )

Language Syntax 
The general rule of thumb is: built-in features in lowercase, and custom-written functions in mixed case. 
When specifying the complete syntax of a language element in documentation, the input items, parameters, and so on are referred to using the following symbols:

 Symbol  Description
< >  Indicates user input item
( )  Indicates function argument list
[ ]  Indicates optional item or list
{ }  Indicates code block or literal array
| |  Indicates code block argument list
–>  Indicates function return value
 Repeated elements if followed by a symbol
Intervening code if followed by a keyword
,  Item list separator
|  Indicates two or more mutually exclusive options
@  Indicates that an item must be passed by reference
*  Indicates a compatibility command or function

For example:

    len(<cString>|<aArray>) --> nLength

Metasymbols provide a place holder for syntax elements, and they describe the expected data types. A metasymbol consists of one or more lowercase data type designators followed by a mixed case description. This is known as Hungarian Notation.

 Designator  Description
a  Array
b  Code block
c  Character expression
d  Date expression
exp  Expression of any type
id  Literal identifier
l  Logical expression
m  Memo field
n  Numeric expression
o  Object
x  Extended expression

In this example, dnLower and dnUpper can be either date or numeric:

    @...get...range <dnLower>, <dnUpper>
Filenames and Aliases 
All filenames, in any context, are in upper case. Filenames follow DOS naming conventions (preferably limited to letters, numbers, and the underscore).

    use CUSTOMER
    nHandle := fopen('DATAFILE.DAT')

When referring to specific file types in documentation, include the period.
e.g. “A program is stored in a text file with a .PRG extension.” 
Alias names follow the same conventions as filenames, but are limited to A-Z, 0-9, and the underscore. If a filename begins with a number or contains unusual characters, an alias must be specified when the file is opened or an error will result. 
Note that CA-Clipper does not natively support Windows 95 long filenames, although third-party libraries are available to add the capability.

Fieldnames 
Fieldnames are all uppercase, and always include the alias of the table. Fieldnames may contain underscores, but should not begin with one (because the underscore is generally used to indicate an internal symbol).

    @ 10, 10 say BANKS->BRANCH
    nAge := CUSTOMER->CUST_AGE
Memory Variables 
Memory variables consist of a lowercase type designator followed by a mixed case description (see Hungarian Notation). Although CA-Clipper only recognizes the first 10 characters as unique, variable names may be longer.

    cString := "Hello World"
    nYearlyAverage := CalcYearAvg()

If you use Hungarian Notation for your memory variable names and include the table alias with fieldnames, there will be no conflict between the two.

Commands, Functions, and Keywords 
All built-in commands, functions, and keywords are lowercase. In documentation, the font should be Courier or a similar font. If fonts are not available, then bold or CAPITALIZE the word for emphasis. 
Never use abbreviations — this practice is not necessary with a compiler, although it was common in the early days of dBase (which was an interpreter). 
There should never be a space between the function name and the opening parenthesis. Also, note that the iif() function should never be spelled if().

    replace CUSTOMER->CUSTNAME with cCustName
    nKey := inkey(0)

When specifying commands that have clauses in documentation, separate the keywords with an ellipsis (...) and do not include the to clause, unless it is followed by the file,print, or screen keywords.

    copy...sdf
    set message...center
    @...say...get
Programmer-Defined Functions & Procedures 
These begin with an uppercase letter, followed by mixed case letters as appropriate.

    ? StripBlanks("Hello there, this will have no spaces.")

Function and procedure names may contain underscores, but should not begin with one (they may conflict with internal functions which often start with an underscore). There should be only one return statement per function or procedure, and it should not be indented.

    function SomeFunc (...)
      .
      . <statements>
      .
    return cResult

The return value of a function is not enclosed in parentheses, although parentheses may be used to clarify a complex expression.

    return nValue
    return (nCode * 47) + nAnswer
Preprocessor Directives 
Preprocessor directives are lowercase and are preceded by the # sign.

    #include 'INKEY.CH'

Optionally, you may use single quotes around header files that come with CA-Clipper and double quotes around your own. This convention is purely voluntary, but it helps to distinguish between the two. For example:

    #include 'INKEY.CH'
    #include "MY_APP.CH"

Manifest constants are uppercase.

    #define ESCAPE   27
    if lastkey() == ESCAPE

Pseudo-function names should also be uppercase.

    #define AREA(length, width)   ((length)*(width))
Declarations 
Local variables are grouped according to functionality, and may be declared on one or more lines. The declarations appear as the first code at the beginning of a function or procedure.

    procedure Main ( )
    local nTop, nLeft, nBottom, nRight
    local cOldScreen, cOldColor, nOldCursor

Variables may be declared one per line and accompanied by a description.

    local nCount        // Number of records found.
    local nTotal        // Sum of dollars.

The description can be omitted if better variable names are chosen.

    local nRecordCount
    local nDollarTotal

Variables can be initialized when they are declared, although it is often clearer (and safer) to initialize them immediately before they are used.

    local nRecordCount:=0
    local nDollarTotal:=0
Logicals 
The .T. and .F. are typed in uppercase.
Operators 
The in-line assignment operator (:=) is used for all assignments, and the exact comparison operator (==) is used for all comparisons.

    lContinue := .T.
    nOfficeTotal := nRegionTotal := 0
    lDuplicate := (CUSTFILE->CUSTNAME == cCustName)
    if nLineCount == 4  ...
    if left(PRODUCT->CODE, 3) == left(cProdCode, 3)  ...

Although the compound assignment operators (+=-=*=, etc.) are convenient, they should not be used if readability suffers.

    // The traditional way to accumulate:
    nTotal := nTotal + INVDETAIL->PRICE
    // A good use of a compound assignment operator:
    nTotal += INVDETAIL->PRICE
    // But what does this do?
    nVal **= 2

The increment (++) and decrement (--) operators are convenient, but can lead to obscure code because of the difference between prefix and postfix usage.

    nRecCount++
    nY := nX-- - --nX        // Huh?
Spacing 
Whenever a list of two or more items is separated by commas, the commas are followed by a space.

    MyFunc(nChoice, 10, 20, .T.)

Spaces may be used between successive parentheses.

    DoCalc( (nItem > nTotal), .F. )
    cNewStr := iif( empty(cStr), cNewStr, cStr + chr(13) )

Spaces should surround all operators for readability.

    nValue := 14 + 5 - (6 / 4)

In declarations, often spaces are not used around the assignment operator. This tends to make searching for the declaration of a variable easier.

    local lResult:=.F., nX:=0

Thus, searching for “nX :=” would find the lines where an assignment is made, while searching for “nX:=” would find the declaration line (such as the local above).

Indentation 
Indenting control structures is one of the easiest techniques, yet it improves the readability the most. 
Indent control structures and the code within functions and procedures 3 spaces.

    procedure SaySomething
       do while .T.
          if nTotal < 50
             ? "Less than 50."
          elseif nTotal > 50
             ? "Greater than 50."
          else
             ? "Equal to 50."
          endif
          ...
       enddo
    return

Case statements in a do…case structure are also indented 3 spaces.

    do case
       case nChoice == 1
          ? "Choice is 1"
       case ...
          ...
       otherwise
          ...
    endcase
Tabs 
Do not use tabs in source code — insert spaces instead. Tabs cause problems when printing or when moving from one editor to another, because of the lack of a standard tab width between editors and printers. Typically, printers expand tabs to 8 spaces which easily causes nested control structures to fall off the right-hand side of the page. Commonly, a source code editing program will insert the appropriate number of spaces when the <TAB> key is hit.
Line Continuation 
When a line of code approaches the 80th column, interrupt the code at an appropriate spot with a semicolon and continue on the next line. Indent the line so that it lines up in a readable manner.

    set filter to CUSTFILE->NAME  == 'John Smith  ';
            .and. CUSTFILE->STATE == 'OR'

To continue a character string, end the first line with a quote and a plus sign and place the remainder on the next line. Try to choose a logical place in the string to break it, either at a punctuation mark or after a space.

    @ 10, 10 say "The lazy brown fox tripped over " + ;
                 "the broken branch."
Quotes 
Use double quotes for text that needs to be translated (will appear on the screen), and single quotes for other strings.

    ? "Hello World!"
    cColor := 'W+/B'
    SelectArea('PROP')

This is a simple but extremely effective technique because translation departments often want to see the messages in context (in the source code), so the different quote types indicate which messages are to be translated and which should be left alone.

Comments 
Comments are structured just like English sentences, with a capital letter at the beginning and a period at the end.

    // Just like a sentence.
    /* This comment is longer. As you
       can see, it takes up two lines */

You may encounter old-style comment indicators if you maintain older (Summer’87 and earlier) code.

    && This is an older-style of comment indicator.
    *  The asterisk is also old.

For in-line comments, use the double slashes.

    use CUSTOMER            // Open the data file.
    goto bottom             // The last record.

Note that the ‘//‘ of in-line comments begins at column 40, if possible. This leaves enough room for a useful comment.

Source :  http://www.ghservices.com/gregh/clipper/guide.htm

>= Greater than or equal

 


 >=
 Greater than or equal--binary                   (Relational)
------------------------------------------------------------------------------
 Syntax

     <exp1> >= <exp2>

 Type

     Character, date, logical, memo, numeric

 Operands

     <exp1> and <exp2> are expressions of any data type to be
     compared.

 Description

     The greater than or equal to operator (>=) is a binary operator that
     compares two values of the same data type and returns true (.T.) if
     <exp1> is greater than or equal to <exp2>.

     .  Character:  The comparison is based on the underlying ASCII
        code.  ASCII codes for alphabetic characters are ascending (e.g., the
        code for "A" is 65 and the code for "Z" is 90).

     .  Date: Dates are compared according to the underlying date
        value.

     .  Logical: True (.T.) is greater than false (.F.).

     .  Memo: Treated the same as character.

     .  Numeric: Compared based on magnitude.

 Examples

     .  These examples illustrate how the greater than or equal
        operator (>=) behaves with different data types:

        // Character
        ? "Z" >= "A"             // Result: .T.

        ? "AZ" >= "A"            // Result: .T.
        ? "A" >= "AZ"            // Result: .F.

        // Date
        ? CTOD("12/12/88") >= ;
           CTOD("12/11/88")      // Result: .T.

        // Logical
        ? .T. >= .F.             // Result: .T.

        // Numeric
        ? 2 >= 1                 // Result: .T.
        ? 1 >= 2                 // Result: .F.
        ? 2 >= 2                 // Result: .T.

See Also: $ < <= <> = (equality) == >

> Greater than

 


 >
 Greater than--binary                            (Relational)
------------------------------------------------------------------------------
 Syntax

     <exp1> > <exp2>

 Type

     Character, date, logical, memo, numeric

 Operands

     <exp1> and <exp2> are expressions of any type to be compared.

 Description

     The greater than (>) operator compares two values of the same data type
     and returns true (.T.) if <exp1> is greater than <exp2>.

     .  Character: The comparison is based on the underlying ASCII
        code.  ASCII codes for alphabetic characters are ascending (e.g., the
        code for "A" is 65 and the code for "Z" is 90).

     .  Date: Dates are compared according to the underlying date
        value.

     .  Logical: True (.T.) is greater than false (.F.).

     .  Memo: Treated the same as character.

     .  Numeric: Compared based on magnitude.

 Examples

     .  These examples illustrate how the greater than operator (>)
        behaves with different data types:

        // Character
        ? "Z" > "A"             // Result: .T.
        ? "AZ" > "A"            // Result: .F.
        ? "A" > "AZ"            // Result: .F.

        // Date

        ? CTOD("12/12/88") > ;
           CTOD("12/11/88")     // Result: .T.

        // Logical
        ? .T. > .F.             // Result: .T.

        // Numeric
        ? 2 > 1                 // Result: .T.
        ? 1 > 2                 // Result: .F.

See Also: $ < <= <> = (equality) == >=

 

== Exactly equal

 


 ==
 Exactly equal--binary                           (Relational)
------------------------------------------------------------------------------
 Syntax

     <exp1> == <exp2>

 Type

     All

 Operands

     <exp1> and <exp2> are expressions of the same data type to be
     compared.

 Description

     The exactly equal operator (==) is a binary operator that compares two
     values of the same data type for exact equality depending on the data
     type.  It returns true (.T.) if <exp1> is equal to <exp2> according to
     the following rules:

     .  Array:  Compares for identity.  If <exp1> and <exp2> are
        variable references to the same array, returns true (.T.); otherwise,
        returns
        false (.F.).

     .  Character:  Comparison is based on the underlying ASCII code.
        ASCII codes for alphabetic characters are ascending (e.g., the code
        for "A" is 65 and the code for "Z" is 90).  Unlike the relational
        equality operator (=) , true (.T.) is returned if <exp1> and <exp2>
        are exactly equal including trailing spaces; otherwise, the
        comparison returns false (.F.).  SET EXACT has no effect.

     .  Date:  Dates are compared according to the underlying date
        value; behaves the same as the relational equality operator (=).

     .  Logical:  True (.T.) is exactly equal to true (.T.), and false
        (.F.) is exactly equal to false (.F.).

     .  Memo:  Treated the same as character.

     .  NIL:  True (.T.) if compared to a NIL value; false (.F.) if
        compared to a value of any other data type.

     .  Numeric:  Compared based on magnitude; behaves the same as the
        relational equality operator (=).

     .  Object: Treated the same as array.

 Examples

     .  These examples illustrate how the == operator behaves with
        different data types:

        // Character
        ? "A" == "A"             // Result: .T.
        ? "Z" == "A"             // Result: .F.
        ? "A" == "A "            // Result: .F.
        ? "AA" == "A"            // Result: .F.

        // Array or object

        aOne := { 1, 2, 3 }
        aTwo := { 1, 2, 3 }
        aThree := aOne
        ? aOne == aTwo           // Result: .F.
        // values within the arrays are equal, but the arrays,
        // themselves, are separate and distinct
        ? aOne == aThree         // Result: .T.

See Also: $ < <= <> = (equality) > >=

= (equality) Equal

= (equality)
 Equal--binary                                   (Relational)
------------------------------------------------------------------------------
 Syntax

     <exp1> = <exp2>

 Type

     Character, date, logical, memo, NIL, numeric

 Operands

     <exp1> and <exp2> are expressions of the same data type to
     compare.

 Description

     The equal operator (= ) compares two values of the same data type and
     returns true (.T.) if <exp1> is equal to <exp2> according to the
     following rules:

     .  Character:  The comparison is based on the underlying ASCII
        code.  ASCII codes for alphabetic characters are ascending (e.g., the
        code for "A" is 65 and the code for "Z" is 90).

        When EXACT is OFF, two character strings are compared according to
        the following rules.  assume two character strings, cLeft and cRight,
        where the expression to test is (cLeft = cRight):

        -  If cRight is null, returns true (.T.).

        -  If LEN(cRight) is greater than LEN(cLeft), returns false
           (.F.).

        -  Compare all characters in cRight with cLeft.  If all
           characters in cRight equal cLeft, returns true (.T.); otherwise,
           returns false (.F.).

        With EXACT ON, two strings must match exactly except for trailing
        blanks.

     .  Date: Dates are compared according to the underlying date
        value.

     .  Logical: True (.T.) is equal to true (.T.) and false (.F.)
        equal to false (.F.).

     .  Memo: Treated the same as character.

     .  NIL: True (.T.) if compared to a NIL value; false (.F.) if
        compared to a value of any other data type.

     .  Numeric: Compared based on magnitude.

 Examples

     .  These examples illustrate how the equal operator (=) behaves
        with different data types:

        // Character
        SET EXACT ON
        ? "123" = "123  "        // Result: .T.
        ? " 123" = "123"         // Result: .F.
        SET EXACT OFF
        ? "123" = "12345"        // Result: .F.
        ? "12345" = "123"        // Result: .T.
        ? "123" = ""             // Result: .T.
        ? "" = "123"             // Result: .F.

        // Date
        ? CTOD("12/12/88") = ;
           CTOD("12/12/88")      // Result: .T.

        // Logical
        ? .T. = .T.              // Result: .T.
        ? .F. = .T.              // Result: .F.

        // NIL
        ? NIL = NIL              // Result: .T.
        ? NIL = 12               // Result: .F.
        ? NIL = CTOD("")         // Result: .F.

        // Numeric
        ? 2 = 1                  // Result: .F.
        ? 1 = 1                  // Result: .T.

See Also: $ < <= <> == > >=