doddsey_65 Posted January 1, 2012 Share Posted January 1, 2012 Me and my friend are both php coders, but have different ways of coding. He leaves no whitespace where possible for example: for($i=0;$i<$count;$i++){ if($i<10) echo $i;} whereas I like to keep it looking better with whitespace such as: for($i=0; $i<$count; $i++) { if($i<10) { echo $i; } } imagine 7000 people making a request to a script with 1000 lines. Would his script run faster? He says yes and I agree but he thinks it will be much faster and efficient, whereas I think there wouldnt be much difference. What's your opinion? Quote Link to comment https://forums.phpfreaks.com/topic/254180-help-settle-a-dispute/ Share on other sites More sharing options...
scootstah Posted January 2, 2012 Share Posted January 2, 2012 It's true that the file size is smaller without white space. But a few tabs isn't going to make a whole lot of difference. If you fully minified it you can shave a good chunk of file size off. But the performance gains are negligible. Quote Link to comment https://forums.phpfreaks.com/topic/254180-help-settle-a-dispute/#findComment-1303174 Share on other sites More sharing options...
PaulRyan Posted January 2, 2012 Share Posted January 2, 2012 I'm sure I read somewhere that the lines/white spaces within PHP tags don't affect the processing time. Developers are encouraged to use white space, lines to break up code to make it more readable, same goes for commenting. I'm not 100% sure where I read this, but I will look for it. Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/254180-help-settle-a-dispute/#findComment-1303176 Share on other sites More sharing options...
doddsey_65 Posted January 2, 2012 Author Share Posted January 2, 2012 i too have read that it takes barely anytime to parse and skip white space and tabs so theres no real concern. But my friend is adamant that his way is better. While it will make file size smaller, execution time would be about the same, and even if there was a difference in execution time it would be very small and meager. Quote Link to comment https://forums.phpfreaks.com/topic/254180-help-settle-a-dispute/#findComment-1303179 Share on other sites More sharing options...
QuickOldCar Posted January 2, 2012 Share Posted January 2, 2012 I believe whitespace is negligible, but lots of comments make a difference. Either way I prefer the uncluttered look, everything together is harder to read. Quote Link to comment https://forums.phpfreaks.com/topic/254180-help-settle-a-dispute/#findComment-1303180 Share on other sites More sharing options...
QuickOldCar Posted January 2, 2012 Share Posted January 2, 2012 I actually prefer this, together with for loops, and the curly bracket on same line. But if I happened to not space it, I wouldn't go back and change it. for($i=0; $i<$count; $i++) { if($i < 10) { echo $i; } } Quote Link to comment https://forums.phpfreaks.com/topic/254180-help-settle-a-dispute/#findComment-1303182 Share on other sites More sharing options...
Zane Posted January 2, 2012 Share Posted January 2, 2012 If you really want to trim every bit of whitespace from your PHP, then so be it, there's no harm in it. But if you expect to show someone your code or ask for help with it and expect a decent answer, then do not trim it. imagine 7000 people making a request to a script with 1000 lines. If 7000 people request a PHP script, it is requested through Apache, the PHP script isn't downloaded like a javascript include. There really is no point in your friends concept.... other than obfuscation --- which is NOT security (As you'll constantly be preached in any Security course) Also, 7000 people isn't very many people. On average, this forum alone receives 106,140.88 page views. This includes a very diverse amount of requests. Some people are posting, some are reading, some are skimming, some are editing, the list goes on and on. If you look at the source code for SMF (the forum software we use), you won't see this reckless and ridiculous practice of having no whitespace. I believe you're friend strips it out so his code looks more complex than it is. Sure, his filesize may be lower, but no one will ever read it, unless they're just into that kind of thing. You could minify your car in the same way, but it wouldn't be a very comfortable vehicle. Take out the seats, the roof, the doors, windows, windshield, etc.... and the car will still run. It wouldn't be very aerodynamic though. Quote Link to comment https://forums.phpfreaks.com/topic/254180-help-settle-a-dispute/#findComment-1303283 Share on other sites More sharing options...
ignace Posted January 2, 2012 Share Posted January 2, 2012 Just put the joke on him, next time you find a bug in a file. Throw all code through a php obfuscator and paste it in (but keep a backup). Tell him there is a bug and that you want him to fix it. Add a PS rule saying that for his convenience you have adjusted it to his coding style!! Or take one of his scripts, use NetBeans or something to properly format the code and save it as a version 2. Run both in a benchmark (say 100.000 requests), that should convince either you or him. Quote Link to comment https://forums.phpfreaks.com/topic/254180-help-settle-a-dispute/#findComment-1303390 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.