omg... I feel like crying!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

omg... I feel like crying!

Post by Flamie »

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!
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

ok guys, nevermind I found the error.
NEVER... and I mean NEVER put a whitespace after a ?>.
Because if its included in an image file it will not load the image without any error.
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

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
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

it is pretty big, but its all relevant to the player class. breaking it into more classes would just be less memory efficient cause they both need the same variables.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I have never gotten an error for having whitespace after the closing php tag. Are you sure that was the problem?
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

nono you all misunderstood me, the problem was that this Class was included in my config.php.
my config.php was included in my citymap.php which is an image script.
printing whitespaces in an image = nono.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

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
Are you kiddng? It really depends upin what the class actually does.

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.
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

Agreed you gotta design a class thinking of what belongs there not on how long/big it is.
Hehe, you're right d11 but tahts easily avoidable using ob_start() ob_get_contents() and ob_end_clean()
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

But wouldn't it be better to code cleanly and not fix dirty code by using output buffering? Just a thought, but I would rather kill white space after the closing tags as opposed to output buffer my app so I don't get header sent warnings.
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

MrPotatoes 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.
I'm sure they weren't :) Doesn't mean that it's wrong to do it. There's also different defintions of what consitutes "lines of code".
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

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!
jonra
Forum Newbie
Posts: 22
Joined: Thu May 25, 2006 9:35 am
Location: Iowa
Contact:

Post by jonra »

d11wtq wrote:
MrPotatoes 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.
I'm sure they weren't :) Doesn't mean that it's wrong to do it. There's also different defintions of what consitutes "lines of code".
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?
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

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?
jonra
Forum Newbie
Posts: 22
Joined: Thu May 25, 2006 9:35 am
Location: Iowa
Contact:

Post by jonra »

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?
No, I disagree.


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
Post Reply