a_bertrand Posted March 18, 2011 Share Posted March 18, 2011 Just to show what kind of difference there is between 2 scripts, one with tabs the other without, beside that the code is EXACTLY the same. Actually I went so far that I removed all the returns as well. Code 1: <?php // Some comment echo "This is a test"; /*********************************************************** Some multi line comment. ***********************************************************/ for($i=0;$i < 10000;$i++) { // this block will do something $a=sin($i/100.0); $b=rand(0,1000); $c=$a*$b; $d=$a^0xFFFFFF; $a=doNothing($a); } //Now let's create a function function doNothing($a) { // Let's add one to a $a=$a+1; // Now let's multiply it by itself $a=$a*$a; // Square root... we have again $a+1 $a=sqrt($a); // Let's remove 1... and we have $a $a=$a-1; // Do the same inside an if... if(true) { // Oooo yeah! $a=$a*$a; // Why not? $a=sqrt($a); } return $a; } ?> Code 2: <?php echo "This is a test";for($i=0;$i < 10000;$i++){$a=sin($i/100.0);$b=rand(0,1000);$c=$a*$b;$d=$a^0xFFFFFF;$a=doNothing($a);} function doNothing($a){$a=$a+1;$a=$a*$a;$a=sqrt($a);$a=$a-1;if(true){$a=$a*$a;$a=sqrt($a);}return $a;}?> Now to test it without bias, I made a little bash script which call this 1000 times: #!/bin/sh for i in {0..1000} do php -q tabs.php > /dev/null done And guess the results? BOTH took 36 sec to run: real 0m36.025s real 0m35.905s ... Times varies a bit if I run the script multiple time as the server is not used purely for that... Now for the size: tabs.php: 737 bytes notabs.php: 235 bytes Sure you do save quiet a bit of space... but is the space all that important on your server? Beside that honestly I saw no real difference, and therefore I cannot support people which do not indent correctly their script. I said CORRECTLY that means not just add random tabs just to look better, but to really make your code easier to read. BTW tabs in the PHP page are not sent to the browser, unless you put then inside some echo or outside the PHP tags, therefore you will certainly not add network load either. To note that all those test have been done on a linux machine without PHP accelerators. Quote Link to comment Share on other sites More sharing options...
Danny696 Posted March 18, 2011 Share Posted March 18, 2011 Actuallly one took under 36 seconds, even if its just a tenth of a second, your using a small script, image if it was on a very large script.. Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted March 18, 2011 Author Share Posted March 18, 2011 Yes and next time I ran it the script with tab took even less time, as said the little variations are due to the server load. Sorry Danny696 you are completely wrong here as it has a so small impact that you will not see it even with 1000 calls like I'm doing (and this is to force PHP to re-parse the script each time). So again, removing spaces and tabs is purely stupidity. Quote Link to comment Share on other sites More sharing options...
Paul Evans Posted March 18, 2011 Share Posted March 18, 2011 I love to tab now it's just so much easier to debug and read later if you have any issues Spacing is well worth the small amount of time putting it in because it saves time on debugging. Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted March 18, 2011 Author Share Posted March 18, 2011 Honestly it doesn't cost even 2sec to put the tabs correctly if you use an editor which support it. Some use Komodo or InteliJ or Eclipse or NetBeans whatever all those will put the tabs for you while you edit your code. So really there is only to gain while writing correctly a code instead of making a huge mess. Quote Link to comment Share on other sites More sharing options...
Paul Evans Posted March 18, 2011 Share Posted March 18, 2011 well i tab my tabled which makes it easier to look at and debug, i use the same amount of spaces and tabs in every single file i do to determine the genre of something also which makes it so much easier but sadly i still use notepad.exe lmao Quote Link to comment Share on other sites More sharing options...
War_Hero Posted March 18, 2011 Share Posted March 18, 2011 I always tab and indent my code. It helps me so much when trying to debug anything. @Paul - I also tab my tables. It makes it much easier to see the text/info/data on each row and in each cell. And I, too, use the same indent size in each of my scripts. I use Quanta Plus on my Ubuntu laptop, and Notepad++ on my Windows one. Used to use Crimson Editor, but the formatting started to frustrate me. Thanks for this post a_bertrand. :) Quote Link to comment Share on other sites More sharing options...
Djkanna Posted March 19, 2011 Share Posted March 19, 2011 Honestly I'd prefer readability rather than speed, not that it's a big speed difference. If you want un-readable code, that's your choice, but if your showing that code, whether it be in the form of looking for help with it, or giving your application away, make it readable! :D Quote Link to comment 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.