in reply to Your use of assertions in Perl ?
Imagine you're writing a web browser. It connects to some server accross the web, downloads some content and tries to parse it as HTML, images, flash, sound... There's quite a lot of code, so it's useful to add assertions in many functions.
However, you can't add an assertion like this without it failing (pointlessly) on many many sites:
if (m{<body>}) { die "Mismatched tags!" unless m{</body>}; }
In general, only assert over items that you (or someone in your team) is in control of. Never assert about items that you can't control, such as content from the www or a user - you'll just have to find some way of coping with errors in that.
Oh, and remember that you'll need to be able to tell the difference, and that there shouldn't be a gap between the things that are asserted and the things that are handled...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Your use of assertions in Perl ?
by AZed (Monk) on Sep 19, 2008 at 20:34 UTC |