in reply to On elegant coding...
in thread Just thinking ...

I enjoy at least trying to redo these things (whether or not the result is more or less maintainable/elegant is another question). My effort (which I know is probably something like what you already tried):
{ ## main loop show_cache_and_exit("current") if cache_is_good(); unless (cache_is_stale()) { ## cache is dead update_cache(),show_cache_and_exit("current") if i_am_the_writer(); ## we cannot do anything about a bad cache, so retry close_cache(); sleep 5; redo; } ## If I'm not the writer then show old cache show_cache_and_exit("stale") unless i_am_the_writer(); ## If I cannot fork it's up to me update_cache(),show_cache_and_exit("current") unless i_can_fork(); show_cache_and_exit("stale") if i_am_the_parent(); ## child does: be_a_child(); update_cache(); exit 0; }

Replies are listed 'Best First'.
RE: RE: On elegant coding...
by merlyn (Sage) on Oct 14, 2000 at 08:05 UTC
    You know, I actually like this one, except for the excessive backwards-ifs. Where were you three days ago when I was trying to hack out my column? {grin}

    -- Randal L. Schwartz, Perl hacker

RE: RE: On elegant coding...
by runrig (Abbot) on Oct 15, 2000 at 02:25 UTC
    Excessive !?!?! There's 3 if's and 3 unless's. I'd say they're perfectly balanced :-) Really, though, I was just trying to get rid of all the nested blocks, which is sometimes easier to do (in this case anyway, I believe) only after seeing the code WITH all the nested blocks.

    Update:oops, meant to reply to merlyn, and replied to myself instead :-)