Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Critique

by ihb (Deacon)
on Dec 08, 2003 at 11:44 UTC ( [id://313061]=note: print w/replies, xml ) Need Help??


in reply to Re: Critique
in thread Critique

Nice code!

But unfortunately I found a bug. If $start is after $end then your routine will loop till death.

Just changing not to 0 <= won't do the whole trick though, as your construction still would print the meals for the first date. A regular for/while loop would suite better here.

This is a good example of why one shouldn't have == instead of <= or >= unless one has to in loop conditions.

ihb

Replies are listed 'Best First'.
Re: Re: Re: Critique
by BrowserUk (Patriarch) on Dec 08, 2003 at 14:12 UTC

    That's not a bug, that's GIGO :)

    How could start be after end?


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!
    Wanted!

      Someone inputs a start date that's after the end date...?

        Then that someone ignored the instructions, unless there is a universe where time runs backwards (Red Dwarf not withstanding;), hence Garbage In, Garbage Out.

        The point is that if you want to allow for the possiblity that someone using the program doesn't understand the difference between "Enter start date" and "Enter end date", and you wish to have the program perform remedial action, then that is your perrogative, but the last thing you need to do is mess with the while loop.

        Simply add

        die 'Dont be silly' unless Date_Cmp( $start, $end ) < 0;

        after the input.

        Of course, they could also type ^C at the first prompt and they fail to get the correct output. Is that the programs fault?

        Or they might redirect the output to the nul device. Should the program attempt to trap and handle that situation?

        Don't think I'm getting on your case, but the code was offered as how I would code it, as requested in the original post. If you or the OP, or anyone else wish to use it as is, that's fine. If you wish to add additional error checking to cater for the potential idiot user, that's fine too. You entirely welcome to ignore the code completely too.

        Again, that tirade isn't aimed at you personally, but is a general comment against third-party, hyper-pedantic critisism and "corrections" of code offered by a 2nd party to a first party with the sole intent of being of assistance to the 1st party.

        The keyword in that legalistic gobbaldy gook is "assistance". Code posted here is intended to be of assistance, an example, a pointer in (hopefully a right) direction. As such, it comes without warrenty or support and should be viewed and used in that light.

        The expectation that the code will be 100% perfect, tailored exactly to the OP's needs, environment or skill levels is not just optimistic, it is dangerous. If that expectation is allowed to take hold, grow and flourish, then this site would die. Who would bother to spend their personal time trying to produce such code for no reward beyond "Personal satisfaction + XP", which in my opinion is worth just a little less than personal satisfaction alone.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        Hooray!
        Wanted!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://313061]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found