Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/254180-help-settle-a-dispute/
Share on other sites

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.

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.