Bekz.net - (14016 of 825950 - 2%) 

 Home | Tips & Tricks | General Info | Downloads | NG Archive | Links | Email | Search | Register | Users | Login

 


 

Tips & Tricks

 

Rating: 76% (11 votes registred)
Rate this item:

Back to list

What is the difference between Harbour & xHarbour

xHarbour As Described By Ron Pinkas

xHarbour As Described By Ron Pinkas

Last Update : 10 December 2002

xHarbour is a fork from Harbour created Demeber 2001. It aims to follow a more aggressive development path, and be more responsive to market trends, and users input.

As it stands at this point, xHarbour offers many Syntax extensions over Harbour and Clipper, including:

GLOBAL variables:

GLOBAL <Id1> [,<Id2> [,<IdN>]]

GLOBAL Variables are a new kind of a declared variables. They have PUBLIC like visibility, but are faster than even STATICs. GLOBALs can be referenced from other modules using the syntax:

GLOBAL EXTERNAL <Id1> [,<Id2> [,<IdN>]]

GLOBAL Variables have the added benefit of being *directly* accessible from C code too.

True C Type Structures:

C STRUCTURE <strucName> [Align <align>]
[ MEMBER <memberName> IS <CTYPEDEF> ]
[ MEMBER <memberName[<arrayLength>]> IS <CTYPEDEF> ]
[ MEMBER <memberName> IS <CTYPEDEF>(<arrayLength>) ]
[ MEMBER <memberName> IS|INPLACE <strucName> ]
[ MEMBER <memberName> AS <strucName> ]
[ ... ]
END C STRUCTURE

C Structure can be passed *directly* TO and FROM C code. The full description is beyond the scope of this document - please refer to cstruct.txt in doc folder.

TRY syntax:

TRY
...
[THROW( <Exp> )]
...
CATCH <Id>
...
END

The above is very similar to Clipper BEGIN SEQ, BREAK(), RECOVER USING, END, but is more inline with more "modern" languages, and dismisses the need to worry about Error codeblock.

IN operator:

<Exp> IN <Array_or_StringExp> => .T./.F.

The IN operator is very similar to the @ operator, but is valid on *both* Strings and Arrays. IN is much faster than the equivalent:

aScan( <Array>, <Exp> )

WITH OBJECT syntax:

WITH OBJECT <exp>
...
:<exp>
...
END

HB_QWith() can also be used to retrieve the current WITH OBJECT within a WITH OBJECT block.

The above syntax not only saves typing, but is also MUCH faster than equivalent conventional coding.

FOR EACH Syntax:

FOR EACH <Element> IN <Array> // <Element> must be a declared variable.
<Element> // Enumarate value of each respective element in the <exp>.
HB_EnumIndex() returns
[LOOP]
[EXIT]
NEXT

is not only more elegant than:

FOR Counter := 1 TO Len(Array)
Element := Array[Counter]
...
NEXT

but is also MUCH faster - and it also supports enumerating all properties in an object.

Strings may be indexed like arrays:

<StringExp>[<IndexExp>]

String as Array Index can also accepts a numeric as an assigned value:

<StringExp>[<IndexExp>] := 65 // Same as := 'A'

String Index and all String of 1 character length, automatically carry a secondary CHAR type, which means they are also compatible with numeric operations.

cVar := "hello"; cVar[1] -= 32 // -> "Hello"

Strings and Arrays may be indexed with negative numbers (Reversed), where -1 index the LAST Element (or NIL if the Array is empty):

cVar[-1] // => "o"

assuming cVar is the value "Hello" as per above.

#[x]uncommand and #[x]untranslate directives:

#uncommad and untranslate directives allow the removal of a given rule from the active rules used by the Pre-Processor. It is very much like the #undefine directive.

Extended macro support:

&cMacro.<suffix>

will compile correctly even if cMacro is a declared var.

Optimizations:

String additions is more than 50 times faster than Harbour.

PCODE based optimized SubStr(), Left(), and Right() functions.

Much optimized code for FOR LOOPs, :=, +=, -=, -, +, when involving declared variables and numeric values.

Optimized WHILE .T. loops.

The underlying ITEM API has been rewritten (source/vm/fastitem.c) and is far faster and consumes much less memory.

Much extended Expression Optimizer produces faster code for common functions, and code notations. For example it will automatically convert:

aTail( <aArray> ) to aArray[-1]
SubStr( <cString>, X, 1 ) to cString[X]

which will execute much faster than the above common code.

Optimized generation of Line numbers and other similar optimizations which end up producing smaller and faster executables.

Built-in support for SET TRACE [On|Off] and TraceLog() function.

Optimized and extended Garbage Collector.

Optimized OOP system.

Full support for Clipper undocumented OOP internals (not available in Harbour).

Built-in support for OLE in Win32.

Enhanced aIns() and aDel() dismiss need for subsequent [common] aSize().

New HB_FuncPtr(), HB_ObjMsgPtr() and HB_Exec().

The xHarbour Run-Time library was re-written to take advantage of all above syntax extensions, and is taking full advantage of the resulting speed improvements.

Fixed:

@ x,y GET &xMacro.Suffix
-> Clipper complains: Error C2081 Macro of declared symbol.

@ x,y GET &( xMacro )
-> Clipper complains: Error C2047 GET contains complex macro.

@ x,y GET &( xMacro )[...]
-> Clipper complains: Error C2047 GET contains complex macro.

xHarbour is about twice as fast as Clipper, on most common operations [excluding console screen output, and DBF access], and about 10 times faster than Harbour.

xHarbour should compile and execute all valid Clipper and Harbour code, without any modifications - such code will be automatically optimized to take advantage of xHarbour extensions.

 

 

 

 

© 2002 Bekz.net, Inc. All Rights Reserved.