Friday, August 01, 2008

TGI g_friday

Found in a package body:

g_friday CONSTANT VARCHAR2(6) := 'Friday';

...then a couple of hundred lines later:

if to_char(business_date,'fmDay') = g_friday then
    ...end-of-week processing...
else
    ...regular processing...
end if;

Now that's flexible. If end-of-week processing is ever moved to the weekend, all you have to do is set g_friday := 'Saturday'.

10 comments:

Anonymous said...

Except that you couldn't, because the field is only six characters long. It would have to be 'Saturd', which of course wouldn't work. :-)

Anonymous said...

g_friday is short for "gee, is it Friday already? Better run the end-of-week processing." So they're embedding business logic in the variable names.

Noons said...

:)
Perfect example of why "abstraction" can be a recipe for disaster: when applied by the clueless!
Folks who don't have the slightest why it's needed in the first place and what it means, should "abstract" from programming...

Unknown said...

One optimization that the PL/SQL compiler can perform is constant inlining.Perhaps that what he was going for.

Joel Garry said...

LOL! It Saturd all right!

word: uusqwzh

Noons said...

HEy guys:
the link to send WTF messages is not working: the email bounces!

William Robertson said...

A couple of emails seem to have bounced recently, though one did show up a couple of days later. The notification for this comment got through, though. Not sure what's going on with the Bigfoot email distribution service.

Anonymous said...

I now consult at a company that does this ad infinitum.
Every constant they can think of is declared in a package and called from every other piece of software in the company.

Very handy when we are taken over by aliens and 'Yes' and 'No' are changed to 'Nwubyb' and 'Weeewoop'...

Anonymous said...

I see a use : avoid errors when typing the string. It is an extreme case, but it makes sens for longer strings, especially if it is used more than once.

FredV said...

I had this problem once too, the problem is how to test for a specific day in a locale independent way. (Since fmDay and consorts return a format based on the locale settings of the server). So for example while in Europe you'd get 1-7 for mon-sun in America however you get 1-7 for sun-sat, or "Freitag" instead of "Friday".