|
It might surprise you to know that this book is all about debugging
Perl scripts and applications. Just like the bug on the front cover,
Perl bugs can be annoying and difficult to get rid of and in some
cases, just like our little friend, they can sting you. This book will
tell all about how to avoid bugs through better programming, how to
trap bugs, and how to debug your program when all the other methods
have failed.
How much time did you spend debugging your last application? 10% of
the total development time? 20%? 40%? It might surprise you to know
that the general rule of thumb is that you should spend 80% of your
time testing and debugging. The obvious solution is not to introduce
bugs in the first place, but there we have a problem.
You're going to see me saying this a lot, but Perl is a very easy
and freeform language that just breeds bugs. Perl's power lies in the
way that you can write quite complex applications in only a few
lines. Even complex projects like text processing and database
management can be handled with relative ease in Perl. However, that
power comes at a price. A simple typing error can cause a whole heap
of problems in Perl that can be difficult to trace. Turn that into a
logic error and you've got a bigger problem.
Whether they are simple typographical errors, or more significant
problems with your code's logic is largely irrelevant, they're bugs
and they need to be resolved.
It's this debugging process that we cover in this book. In fact, we
go a little bit further. I'm a firm believer in good software design,
and that means obtaining a better understanding of how the text that
you use for a script is translated by the language into a working
program. As part of that process, it's also worth understanding where
mistakes can be made during that parsing stage.
There are of course problems in your program that can be tracked
and caught as part of the program itself for example when you open a
file, you should be testing the return value to make sure it was
successful. Knowing when and where to use these is a valuable part of
the debugging process that can take place during your programs
design. You can also use warnings and pragmas to get Perl to do the
work for you. If you've still got bugs once the program has been
completed then you'll need to know how to use a debugger to find
problems.
An often forgotten type of bug can be resolved through the use of
different optimization techniques. Some things you can spot and
resolve manually, but others require the use of special tools to
enable the problem functions and program areas to be identified. We
can even use the Perl compiler for more than just compiling Perl
programs. With a little work and creative thought, we can use the
compiler to give us in depth information about a script and provide us
with useful starting points for isolating problems.
This book covers all of these areas and more, giving you a detailed
look at how best to approach the problems of writing less error prone
Perl scripts, and at how to resolve and identify bugs after your
script has been completed.
|