Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
New WEEKDAYS function.
Message
De
22/08/2003 02:30:41
Walter Meester
HoogkarspelPays-Bas
 
 
À
21/08/2003 18:24:01
Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00821896
Message ID:
00822486
Vues:
20
Hi Mike,

>I like it! You're removing weekend days instead of keeping weekdays. That means computing 2/7ths instead of 5/7ths. Multiplying by 2 has to be faster than multiplying by 5.

Glad you like it. However, I don't think multiplying by 2 in stead of 5 does have any noticable performance impact.

>To make it more readable, I'd reduce the DOW() calls from two to one because they are being called twice. The MOD or % is only being called one time depending on the result of the IIF().

Originally I had coded it this way. But I decided to include the DOW() in the return statement as it was slightly faster.

>Are you aware that with a table open, your routine will run slower than with no table open? In fact, the more fields, the slower it will go? It will also return incorrect results if ever it is run with a table open that has a field name that matches one of the variables?

I never did any benchmarking on that. Good point. however I'm not thinking this has serious performance hits. I however recall that using the m. prefix is slightly slower than not using at least with no table open.

And yes I'm aware that omiting the m. can have serious consequence when a field in the selected workarea has the same name. In my systems I do avoid that by using a three letter prefix in tablefieldnames and not using a type prefix for variables.

I know this comes down to the discussion of naming conventions again. I know there are many different viewpoint over here, though I think it is save to say that you'll have to pick one and use that one consistently. A long time ago I decided not to use the m. prefix because it looks ugly to me and burdens me in reading the code. Also I do not use a scope prefix. The only prefixes I use are for variables: n,c,l,d and x for Numberic, Character, Logical, Date and Unknown respectively

I don't want to start this discussion about naming conventions again as it is some kind of endless holy war where everyone sticks to its viewpoints. Let's leave it that the way of naming variables is something personal and in general does not have anything to do with the quality of coding itself, and in itself has only limited impact on readability.


>
LPARAMETERS dDate1, dDate2
>LOCAL nDays, nDow
>
>nDays = ABS(dDate1-dDate2)+1
>nDow = DOW(MIN(dDate1,dDate2),2)
>
>RETURN nDays - INT(nDays/7)*2 - ;
>	IIF(nDow = 7, SIGN(nDays % 7), SIGN(nDow - 7 + (nDays % 7))+1)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform