On Tue, 13 Nov 2007, Graeme Geldenhuys wrote:

> Hi,
> 
> What are your feelings about the use of Variants?  I'm debating this
> in another NG and would like some outside opinion.
> 
> My personal opinion on Variants:
> 
>   *  I don't like them. [if that's a reason]  :-)
>   *  They seem like a bit of a hack. Native types seem to be a
>       better solution to me, even though it might end up being
>       a bit more work (coding wise).

Quite the opposite. Pascal is a type safe language.

If I declare a variable, I want to be sure about what it can
contain. If you declare it as a variant, you'll spend lots of 
time writing code that checks whether it actually contains
a usable value. Using native types, the compiler will tell you
whether it does or not.

>   *  They tend to be slow compared no native types. In
>       Delphi 6 they were very slow. How does it compare
>       in FPC 2.2.0?

They are slower than native types, there is no way around this.
Almost each and every operation involving variants has some 
implicit calls to variant support routines.

Just compare the assembler code generated for this:

Var
  A,B,C : Integer;

begin
  A:=B+C;
end.

and the code for

Var
  A,B,C : Variant;

begin
  A:=B+C;
end.

You should see that it is more than double the size.
If that doesn't convince someone that variants are SLOW, 
then I don't know what will. Use -al for compiler options.

Michael.

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to