It's taking forever! Comments? It gets easier I assume..
Debugging Classes
Moderator: General Moderators
Debugging Classes
I'm working on a 1000 line class that I wrote. It's very complex in nature and I'm not used to writing classes so designing it has been a pain staking process. Debugging it is a royal pain though..
It's taking forever! Comments? It gets easier I assume..
It's taking forever! Comments? It gets easier I assume..
1000 lines seems pretty big for a class.
My main debugging tool:
My main debugging tool:
Code: Select all
function preprint_r($in_array, $die = true) {
echo "<PRE>";
print_r($in_array);
echo "</PRE>";
if($die) die();
}What it does is..
1. Displays a dynamic form and asks some general questions pulled from a database
2. Validates the answers based on possible answers
3. Displays another dynamic form and asks some more questions
4. Validates the answers to this dynamic form based on possible answers
5. Displays 1 or 2 more dynamic forms with questions that are pulled from a database based on the responses to the first questions. There are 4 possible dynamic forms that can be displayed, redOne, redTwo, blueOne, blueTwo, and based on the results of the first form it can display any combination of them in any order.
6. Determines what form to redisplay if anything isn't valid and repopulates all the other selected answers so they don't need to be answered again and marks invalid responses with a red box
7. Saves the results of the questions into a database table upon success
All the forms are created dynamically based on questions stored in a database table. Questions and answers are added via an admin panel.
I can't post it as the code is proprietary (for a client)
1. Displays a dynamic form and asks some general questions pulled from a database
2. Validates the answers based on possible answers
3. Displays another dynamic form and asks some more questions
4. Validates the answers to this dynamic form based on possible answers
5. Displays 1 or 2 more dynamic forms with questions that are pulled from a database based on the responses to the first questions. There are 4 possible dynamic forms that can be displayed, redOne, redTwo, blueOne, blueTwo, and based on the results of the first form it can display any combination of them in any order.
6. Determines what form to redisplay if anything isn't valid and repopulates all the other selected answers so they don't need to be answered again and marks invalid responses with a red box
7. Saves the results of the questions into a database table upon success
All the forms are created dynamically based on questions stored in a database table. Questions and answers are added via an admin panel.
I can't post it as the code is proprietary (for a client)
I'm not familar with PEAR. I figure if I write all my own libraries and framework it will make me a better programmer in the long run.
I'm at the point where I'll have this done by morning and then I have a ton of other stuff to do yet otherwise I would experiment with breaking it apart.
I guess I'll just figure it out as I get more experienced writing complex classes..
I'm at the point where I'll have this done by morning and then I have a ton of other stuff to do yet otherwise I would experiment with breaking it apart.
I guess I'll just figure it out as I get more experienced writing complex classes..
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Yikes, that's an appplication -- not a class. It undoubtedly needs to be split up. I can imagine it has become a real pain to deal with because it is essentially a namespaced procedural program from the looks of it.astions wrote:What it does is..
1. Displays a dynamic form and asks some general questions pulled from a database
2. Validates the answers based on possible answers
3. Displays another dynamic form and asks some more questions
4. Validates the answers to this dynamic form based on possible answers
5. Displays 1 or 2 more dynamic forms with questions that are pulled from a database based on the responses to the first questions. There are 4 possible dynamic forms that can be displayed, redOne, redTwo, blueOne, blueTwo, and based on the results of the first form it can display any combination of them in any order.
6. Determines what form to redisplay if anything isn't valid and repopulates all the other selected answers so they don't need to be answered again and marks invalid responses with a red box
7. Saves the results of the questions into a database table upon success
(#10850)
LOL.. Shows what I knowarborint wrote:Yikes, that's an appplication -- not a class.
It's pretty cool though you can call it with one line of code. I'll get the hang of this OOP stuff soon. I did have to change to an editor that had code folding though lol.
The database class and validation classes are seperate!
Depends on the complexity in all fairness, but I would imagine a day or two (in man-hours) to get an initial version up and running, then an extra half-day to a day to iron out bugs 
Also depends on the availability of pre-defined classes etc. If completely from scratch then a lot longer, however if I have 'common' classes available (such as a database class) then a lot quicker
Framework ftw.
Also depends on the availability of pre-defined classes etc. If completely from scratch then a lot longer, however if I have 'common' classes available (such as a database class) then a lot quicker
Framework ftw.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Yeah that's not really to much to judge anything by. You should spend roughly twice as young planning and designing it as what you should actually spend coding it. The thing is, if your design is unmanageable it's going to take even longer to finish by the time you get so far in because you end up adding code-hacks to it purely to "get it working" only to find you just broke something else. Yes. We've all been guilty of it. Good design from the start can save you heaps of time, even if it feels like you should be sat writing the code.astions wrote:Just out of curiousity, how long would it take you guys to make something like that?
Hi,
In terms of testing and debugging at some point you might want to consider using a unit tester, you write tests as you write the code. Google for SimpleTest or PHPUnit.
As for your "god class", as I have seen it termed, I think many of us have done it, though not as spectacularly as this...
One of the big ideas of using oop is to reuse bits of code in other similar applications, so nice small, tested and reusable classes is the usual target I use.
In terms of testing and debugging at some point you might want to consider using a unit tester, you write tests as you write the code. Google for SimpleTest or PHPUnit.
As for your "god class", as I have seen it termed, I think many of us have done it, though not as spectacularly as this...
One of the big ideas of using oop is to reuse bits of code in other similar applications, so nice small, tested and reusable classes is the usual target I use.
Whoa man, what were you thinking...all that in one classastions wrote:What it does is..
1. Displays a dynamic form and asks some general questions pulled from a database
2. Validates the answers based on possible answers
3. Displays another dynamic form and asks some more questions
4. Validates the answers to this dynamic form based on possible answers
5. Displays 1 or 2 more dynamic forms with questions that are pulled from a database based on the responses to the first questions. There are 4 possible dynamic forms that can be displayed, redOne, redTwo, blueOne, blueTwo, and based on the results of the first form it can display any combination of them in any order.
6. Determines what form to redisplay if anything isn't valid and repopulates all the other selected answers so they don't need to be answered again and marks invalid responses with a red box
7. Saves the results of the questions into a database table upon success.
You should definately consider splitting that into smaller classes.