The most difficult kind of error to debug, it normally doesn't relate with a mistake in the language but with the problem solving.
This errors will normally be noticed because the results of an operation doesn't match the expected ones in all or some of the cases.
To narrow down this errors, we often need to analyze what's happening at execution time, sometimes we are able to line by line debugging if we have a proper set up environment, still many times, we need to debug in online servers, or other environments without an integrated debugger.
In order to debug this errors we normally need to 'see' what's happening inside the application, for this your best friends in PHP are:
echo; print_r; debug_print_backtrace()
This functions however doesn't allow us to debug in a real environment or to inspect specific cases, Tequila implements a set of debugging functions that works conditionally allowing you to implement them in a real environment and have the ability to inspect what's happening.
Tequila equivalent functions.
Tequila offers the possibility of conditionally activate debugging, please check Tequila documentation for a complete set of functions and the ways to activate in different scenarios
Example of a logical case
Let's imagine an example where $user is the publisher of a document, and the document $author field appear empty
The strategy for tackling this bug would be something like:
1. Try to point out the place where you believe data / execution is going wrong (Controller perhaps?, model?)
2. Add debugging code, i.e. myecho ("executing suspecting function, Value of user = $user");
3. Add debug code (as in 2) in several spots until you can trace the place where the value of $user change
1. Try function / class entry points
2. Try before and after calling other functions that you believe can affect this value
4. Remove all the debugging entries that show correct values
5. Drill down the function where the value was altered
6. Repeat until you can pin point an specific line or section
The idea behind is to narrow the problem to an specific function or segment of the code.
Notes
Remember:
* Try to be logical, common functions used by everyone in the same way are normally not the cause of the problem
* Don't blame it because you cannot understand it
o SQL
o RegEx
o Packages
o Libraries
o Complex strings
* Most times libraries and packages are safe to use, it's more common that your own code is faulty and not the team /public code. (This doesn't mean they cannot contain bugs/issues that no one discovered before, but you shouldn't blame this parts from the beginning)
Dates
Dates are a small challenge in application development, verify that your application date data is congruent. Tequila favors the canonical format:
YYYYMMDD HH:MM:SS
As this is the only universally understood format, while you can use many formats to display dates, we recommend this to store and pass date data.
Be aware of locales with different years like Thai, for this cases we recommend to store normal data and just replace the year on view, as the calendar doesn't match the year it mentions but the current one.
Example:
Thai year: 2552, does not match the calendar of standard year 2552, but matches the calendar of 2009.
Other errors
There are other kinds of possible errors that go beyond debugging, you can read Tequila good practices or other similar documents to better understand this, among this errors:
* Bad architecture design
* Improper code separation
* Non independent functions
* Bad OO coding
Line by line debugging
The best and easiest way to debug in any language is to use a line by line run time debugger in the style of visual studio, where you can see how the application is running and the values are changing, unfortunately this option is not often available in PHP.
You can try installing the debugger in Zend or one of the many options available. (Check IBM link for more info)
Find php framework and more useful information about RAD workflow open source.
Thứ Hai, 12 tháng 10, 2009
Đăng ký:
Đăng Nhận xét (Atom)

Không có nhận xét nào:
Đăng nhận xét