omg... I feel like crying!
Moderator: General Moderators
omg... I feel like crying!
Ok guys I need some help.
How can I find an error in a 2000 line class?
It took me 4 hours to find the error was in that class because I woke up this morning and non of my php-image scripts are working such as:
http://www.laene.nl/Marc/worms/pages/citymap.php?id=3
Usually by right clicking -> view source you would find the errors, but not this time its just not telling me anything.
So after hours of commenting out stuff to locate the problem I realised it came from my config.php, and more specificaly from when I include my Player.php Class.
Now this class is 2000 lines long and with me not getting any specific error, I really need to know how I can solve this problem.
Any help will be greatly appreciated as I'm starting to turn insane because of this!
How can I find an error in a 2000 line class?
It took me 4 hours to find the error was in that class because I woke up this morning and non of my php-image scripts are working such as:
http://www.laene.nl/Marc/worms/pages/citymap.php?id=3
Usually by right clicking -> view source you would find the errors, but not this time its just not telling me anything.
So after hours of commenting out stuff to locate the problem I realised it came from my config.php, and more specificaly from when I include my Player.php Class.
Now this class is 2000 lines long and with me not getting any specific error, I really need to know how I can solve this problem.
Any help will be greatly appreciated as I'm starting to turn insane because of this!
- MrPotatoes
- Forum Regular
- Posts: 617
- Joined: Wed May 24, 2006 6:42 am
2K lines for a class isawful large. might want to consider breaking it up into relevant classes.
what's funny is that i've never gotten an error like that with whitespace after the '?>'. i guess because i do most of my inital testing on a windows but but i have moved it to linux. for safety measure i'll make sure to do that now. although it's really just newlines but it doesn't matter
what's funny is that i've never gotten an error like that with whitespace after the '?>'. i guess because i do most of my inital testing on a windows but but i have moved it to linux. for safety measure i'll make sure to do that now. although it's really just newlines but it doesn't matter
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Are you kiddng? It really depends upin what the class actually does.MrPotatoes wrote:2K lines for a class isawful large. might want to consider breaking it up into relevant classes.
what's funny is that i've never gotten an error like that with whitespace after the '?>'. i guess because i do most of my inital testing on a windows but but i have moved it to linux. for safety measure i'll make sure to do that now. although it's really just newlines but it doesn't matter
As long as it's doing it's own job and not umpteen jobs 2k lines is fine. You really cant say that without seeing the code
EDIT | Note: Whitespace after the closing tag *does* matter if any operations following the file need to deal with HTTP headers.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- MrPotatoes
- Forum Regular
- Posts: 617
- Joined: Wed May 24, 2006 6:42 am
no matter which language i've written (C++/Java/PHP/C#/C) none of my files were longer than 500 lines. and this is 3D work, AI and some physics. but hey, if you wanna say that it might need 2K lines then so be it. i'm not gonna fight you on it. but out of all the complicated projects that i've ever been involved with none were that long.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I'm sure they weren'tMrPotatoes wrote:no matter which language i've written (C++/Java/PHP/C#/C) none of my files were longer than 500 lines. and this is 3D work, AI and some physics. but hey, if you wanna say that it might need 2K lines then so be it. i'm not gonna fight you on it. but out of all the complicated projects that i've ever been involved with none were that long.
it really depends on the type of project you're doing really.
usually like normal applications dont require big classes I agree with you. But when it comes to programming video games, specially the player class, just think of the number of functions a player can do in a game, each of those require a function, they add up and make the class pretty big!
usually like normal applications dont require big classes I agree with you. But when it comes to programming video games, specially the player class, just think of the number of functions a player can do in a game, each of those require a function, they add up and make the class pretty big!
Lines of Code is an overrated thing anyways. I honestly wouldn't see any issues with a class that large. In the end, the code has to be somewhere - if the application is huge, it's going to happen. Besides, if all functions in the class relate to the class itself, breaking it up just because it's "too many lines" doesn't seem very efficient in and of itself. It's a huge class for sure, but like I said, the code would have to go somewhere anyways. Why not keep it in the same container with other functions relating to the same functionality (not to use the word function to many times :p )? What's the difference?d11wtq wrote:I'm sure they weren'tMrPotatoes wrote:no matter which language i've written (C++/Java/PHP/C#/C) none of my files were longer than 500 lines. and this is 3D work, AI and some physics. but hey, if you wanna say that it might need 2K lines then so be it. i'm not gonna fight you on it. but out of all the complicated projects that i've ever been involved with none were that long.Doesn't mean that it's wrong to do it. There's also different defintions of what consitutes "lines of code".
- MrPotatoes
- Forum Regular
- Posts: 617
- Joined: Wed May 24, 2006 6:42 am
ok, to not let this thread go on and on i've programed 7 games so far. and i'm telling you, nothing was mind boggling big. i'm out of the system right now but i do know what i'm talking about.
the player class would inheret (remember this is the way that i would do it) a class with empty functions (parent) and it would have a fe functions. update, destroy, init. in the update it would possibly be 20 lines of code max and this is updating all it's physics, movements and interaction with world while taking in player imput. most of the object classes would be like this minu lpayer input. well, how did we do it? called functions in there.
it's alot cleaner and if you have a problem going down you look at the function that is failing can fix that. not look thru ambiguous code all over the place. but hey, that is one way of doing it. if you want long files so be it. its not my code.
i do have to say that cleaner/simple code is MUCH more important than code length. i think we can all agree on that no?
the player class would inheret (remember this is the way that i would do it) a class with empty functions (parent) and it would have a fe functions. update, destroy, init. in the update it would possibly be 20 lines of code max and this is updating all it's physics, movements and interaction with world while taking in player imput. most of the object classes would be like this minu lpayer input. well, how did we do it? called functions in there.
it's alot cleaner and if you have a problem going down you look at the function that is failing can fix that. not look thru ambiguous code all over the place. but hey, that is one way of doing it. if you want long files so be it. its not my code.
i do have to say that cleaner/simple code is MUCH more important than code length. i think we can all agree on that no?
No, I disagree.MrPotatoes wrote:ok, to not let this thread go on and on i've programed 7 games so far. and i'm telling you, nothing was mind boggling big. i'm out of the system right now but i do know what i'm talking about.
the player class would inheret (remember this is the way that i would do it) a class with empty functions (parent) and it would have a fe functions. update, destroy, init. in the update it would possibly be 20 lines of code max and this is updating all it's physics, movements and interaction with world while taking in player imput. most of the object classes would be like this minu lpayer input. well, how did we do it? called functions in there.
it's alot cleaner and if you have a problem going down you look at the function that is failing can fix that. not look thru ambiguous code all over the place. but hey, that is one way of doing it. if you want long files so be it. its not my code.
i do have to say that cleaner/simple code is MUCH more important than code length. i think we can all agree on that no?
Ok, kidding. I do agree with you - I just wouldn't break it up just to break it up at this point. I definitely wouldn't want to work on an application that had a class with 2000 lines, but I don't know I'd look to start breaking it up either. It'd be tough once it was written for me I guess, but I agree completely with what you're saying.
edit: Also it's kind of ironic that we've got this debate on a thread where the main problem was he couldn't easily debug the class because it was 2000 lines of code :p