Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: Re: Re: Critique

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


in reply to Re: Re: Re: Critique
in thread Critique

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

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

    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!

      but the last thing you need to do is mess with the while loop

      I don't need to, but that's how I'd do it. I have two reasons: I don't split up the logic and having a regular while loop gives me the behaviour I believe is expected for input '2003-11-08' and '2003-11-08', i.e. the same day.

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

      Not to be hyper-pedantic, but rather to prove a point, I point out that you need to check for equality of 0 too, since you have a do {} while construction. This is why I don't like to split up logic. It's easier to introduce a bug. And one day you might rewrite the loop to a regular while loop and then you'd perhaps have to change another condition too. Having this logic split up is not necessary and it doesn't cause more complex code to have it in one place, which is why I advocate against a split.

      If you wish to add additional error checking to cater for the potential idiot user, that's fine too.

      I didn't realize you were aware of the behaviour I pointed out. I think it was worth pointing out none-the-less, since I believe that most people's intuition would go against the behaviour. I'd expect the program to return/output nothing if the start date is after the end date. I'd expect it to output just one day if two identical dates were given. I find this the most intuitive behavior for me and this is how the .. operator works in list context. I'd go crazy if 7 .. 4 would die at me instead of returning an empty list or halting for building up an infinite list.

      But the key things here is that I didn't need additional error checking if I used my loop logic. (Especially since I don't believe that a start date after an end date is an error, just as the .. operator shouldn't consider 7 .. 4 an error.)

      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.

      I've sorry if I provided help not explicitly called for. I had the same objective as you.

      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 the code isn't 100% perfect, is it wrong to point out that? Is it wrong to elaborate on code? The beauty is that you can write whichever code you like, and then other people can complete it to be perfectly tailored to the OP's question, if anyone feels like it. Nothing is enforced on anyone. I didn't downvote your solution, I upvoted it. But I also believe that it should be OK to point out issues with other solutions and be able to discuss them.

      I like that this forum isn't just a Q/A-forum.

      ihb

        Being in a somewhat better frame of mind today, I went back and re-read your original post, and devoid of the blinkers I was wearing yesterday, born of events and frustrations sourced far away from this place, I admit I misread and mis-construed your posts and intent. I apologise.

        Your not wrong.

        Okay, your right:)


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-29 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found