Re: String or Numeric Variable?



Hi Mike.

Thanks for your comments.

Okay, it appears that using numeric constants will solve the 'readability'
issue and Enum (Fernando's comment) perhaps more efficient? So I'll go with
the numeric route rather than string because I have a ton of these
IF..THENS that work off these all through the program.

But you mentioned LONG as opposed to BYTE or INTEGER. Are you saying that a
LONG type is better for even single-digit numbers used for nothing more than
comparisons (as opposed to having math performed on them) than a BYTE or
INTEGER type?

Obviously the BYTE or INTEGER type would use less memory. But I suppose not
a big deal if you don't over do it. But just why is LONG better?

Thanks.




"Mike Williams" <Mike@xxxxxxxxxxxxxxxxx> wrote in message
news:djtoub$ntj$1@xxxxxxxxxxxxxxxxxxxxxxx
> "ProfitMaxTrading.com" <nospam@xxxxxxxxxx> wrote in message
> news:h2t8f.3642$LR1.1843@xxxxxxxxxxxxx
>
>> Is it best to use a variable of type string and either have it equal
>> "Morning", "Afternoon" or "Night" or "M", "A", "N" for example
>> or perhaps a numeric variable, say type BYTE and give it values
>> of 1, 2 or 3 to mean the same?
>
> It depends what you are doing with it, and how many times you have to
> access it throughout the program. Using a standard integer variable (Byte,
> Integer or Long) is definitely much faster than a string (with Long
> probably being the faster of the three integer types). But, in many cases
> speed really isn't an issue, and the descriptive nature of a string can
> often make your code much more "readable". For example:
>
> If TimeOfDay = "Night" Then . . .
>
> is much more readable than . . .
>
> if TimeofDay = 1 Then . . .
>
> and it is certainly much more readable than using bits as flags and
> checking them. Basically, do what you're most comfortable with. I
> personally like code that makes sense when I read it, even if it does take
> a few more nanoseconds to execute. The exception, of course, is when you
> are using variables in a loop that is going to be executed a very large
> number of times and where speed is of the esscence. Then you would use
> whatever happens to be the fastest in that specific case.
>
> Mike
>
>
>


.



Relevant Pages

  • Re: error converting the varchar value True to a column of data smal
    ... > Is this indicating a problem with the varchar parameters or the smallint ... The string "True" can be coersed ... Afaik, there is no symbolic value TRUE in SQL, the Boolean concept exists, ... If you merely coerse to an integer type, ADO will whine about type mismatch. ...
    (microsoft.public.vb.database.ado)
  • Re: Convert Fraction to Decimal Type
    ... All you need to do is specify a decimal literal instead of integer as one of the expressions. ... I'm having to convert part of the prodName column which is a string to integer type. ... "Dan Guzman" wrote in message ...
    (microsoft.public.sqlserver.programming)
  • Re: how to change pid to string in linux gcc
    ... > Here is a small program which uses pid_t and converts it to a string and displays the string on the standard output. ... is (int or long etc.). ... if long is the largest integer type there is. ... long integer values (for 64-bit integers a length of 22 chars should be ...
    (comp.unix.programmer)
  • Re: strlcpy -- or lack thereof
    ... constant integer with a value of zero, eg sqrt, 'in the ... A so-called 'C string' is a sequence of bytes with values!= 0, ... 'does s point to the string terminator'. ... whose type, in my opinion, really shouldn't be an integer type' ...
    (comp.unix.programmer)