448191 Posted July 10, 2008 Share Posted July 10, 2008 BS. White space has no measurable effect on performance. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-586518 Share on other sites More sharing options...
.josh Posted July 10, 2008 Share Posted July 10, 2008 function myFunction() { if($me == "awesome") { echo "Damn straight."; } else { echo "You suck."; } } I hate making my code like that because i read an optimization article that if you put stuff very close together e.g. if ($me == "awesome"){ echo "hi"; }else{ echo "you suck"; } then the server will be able to run the code much faster. or so ive read. Faster, yes. Much faster? No. Cramming code together like that has not yielded noticeable differences in a very long time. The processing time difference between those two are so minute that it's not even considered anymore. Even with a thousand lines of code with another 1000 lines of comments, 1 for each line of code, we're talking like .000000000000001 second differences here. And you would have to have a considerably large chunk of code to even measure it. And you're not even looking at this from a larger perspective. Let's say you really wanted to save those extra pennies. 6 months down the road something changes and the script no longer works. So some poor soul would have to tredge through all that crap trying to find out what went wrong. I think all that downtime before he figures it out would be a hell of a lot more than any amount of time you managed to save by doing that. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-586524 Share on other sites More sharing options...
Mr. Despair Posted July 10, 2008 Share Posted July 10, 2008 I use the first method. Its easiest for me to read when something is really nested. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-586601 Share on other sites More sharing options...
unsider Posted July 11, 2008 Share Posted July 11, 2008 I usually code like # 2 for most things, if statements or functions, etc.... but sometimes I tend to drift in an out of both 1 and 2, depending on the content. If that makes sense? Shrug. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-587328 Share on other sites More sharing options...
Daniel0 Posted July 14, 2008 Share Posted July 14, 2008 function myFunction() { if($me == "awesome") { echo "Damn straight."; } else { echo "You suck."; } } I hate making my code like that because i read an optimization article that if you put stuff very close together e.g. if ($me == "awesome"){ echo "hi"; }else{ echo "you suck"; } then the server will be able to run the code much faster. or so ive read. lmao. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-590026 Share on other sites More sharing options...
nadeemshafi9 Posted July 17, 2008 Share Posted July 17, 2008 function myFunction() { if($me == "awesome") { echo "Damn straight."; } else { echo "You suck."; } } I hate making my code like that because i read an optimization article that if you put stuff very close together e.g. if ($me == "awesome"){ echo "hi"; }else{ echo "you suck"; } then the server will be able to run the code much faster. or so ive read. lmao. technicaly he is right but the disadvantages outweigh any mesurable effects which would be miniscule Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-592549 Share on other sites More sharing options...
Daniel0 Posted July 17, 2008 Share Posted July 17, 2008 Sounds like a member that used to be here who adamantly kept coding without any whitespace whatsoever to save diskspace... Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-592691 Share on other sites More sharing options...
nadeemshafi9 Posted July 18, 2008 Share Posted July 18, 2008 Sounds like a member that used to be here who adamantly kept coding without any whitespace whatsoever to save diskspace... ive seen them do that alot, esewpecialy client side scripsts with web apps. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593000 Share on other sites More sharing options...
KevinM1 Posted July 18, 2008 Share Posted July 18, 2008 Sounds like a member that used to be here who adamantly kept coding without any whitespace whatsoever to save diskspace... ive seen them do that alot, esewpecialy client side scripsts with web apps. Except the JavaScript source code isn't actually written without whitespace. Instead, it's written normally, meaning in a normal coding style so it can be read/edited, then it's either minified or packed when it's ready to go live. No one in their right mind intentionally writes code without whitespace. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593047 Share on other sites More sharing options...
nadeemshafi9 Posted July 18, 2008 Share Posted July 18, 2008 Sounds like a member that used to be here who adamantly kept coding without any whitespace whatsoever to save diskspace... ive seen them do that alot, esewpecialy client side scripsts with web apps. Except the JavaScript source code isn't actually written without whitespace. Instead, it's written normally, meaning in a normal coding style so it can be read/edited, then it's either minified or packed when it's ready to go live. No one in their right mind intentionally writes code without whitespace. is it good to pack it i havent tried ? i have quite a big framework of js Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593217 Share on other sites More sharing options...
Daniel0 Posted July 18, 2008 Share Posted July 18, 2008 The only point in it is reducing bandwidth usage. If you strip all the comments and whitespace then the file will be smaller for the user to download and the site will consequently load faster. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593220 Share on other sites More sharing options...
nadeemshafi9 Posted July 18, 2008 Share Posted July 18, 2008 The only point in it is reducing bandwidth usage. If you strip all the comments and whitespace then the file will be smaller for the user to download and the site will consequently load faster. i think the benifits are outweighed by the disadvantage Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593225 Share on other sites More sharing options...
Stephen Posted July 18, 2008 Author Share Posted July 18, 2008 Have no whitespace and no comments just to save loading time by ".000000000000001" (as an example by Crayon Violet), or have a neat looking script with informative comments. Hmmmmm... Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593234 Share on other sites More sharing options...
Daniel0 Posted July 18, 2008 Share Posted July 18, 2008 Uh... I think you miss the point... You develop it with whitespace and comments and upon deployment you "pack" it. Real world example (jQuery): Unpacked: 97 kB Packed: 30 kB Difference: 67 kB On a 256 kbps connection that amounts to approximately 2 seconds. Also, imagine you get 1000 hits per day. That's 65 MB/day or 1.9 GB/month saved. If you gzip the file then the size will come down to 16 kB and then you will have saved 81 kB per request or 2.3 GB/month with the 1000 hits per day mentioned before. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593239 Share on other sites More sharing options...
proggR Posted July 18, 2008 Share Posted July 18, 2008 That explains google's code. Have you ever looked at the source code for even the homepage? I imagine they would need to make sure they're running as efficiently as possible with the number of requests they would get. At 112 million hits a day, if they had the same sizes before and after compression they'd be saving around 257.6 TB. I should start packing my code. I'd never really thought much about it before. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593656 Share on other sites More sharing options...
Daniel0 Posted July 18, 2008 Share Posted July 18, 2008 One thing that has always struck me as odd is that their HTML is total crap and there is CSS and Javascript all over it. If they properly coded it and separated HTML, CSS and Javascript then they would save a lot of bandwidth seeing as it could be cached by the client. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593671 Share on other sites More sharing options...
nadeemshafi9 Posted July 19, 2008 Share Posted July 19, 2008 One thing that has always struck me as odd is that their HTML is total crap and there is CSS and Javascript all over it. If they properly coded it and separated HTML, CSS and Javascript then they would save a lot of bandwidth seeing as it could be cached by the client. so infact it is very usfull and i am the fool Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-594452 Share on other sites More sharing options...
matthewhaworth Posted July 22, 2008 Share Posted July 22, 2008 No tabs is standard? wtf? I couldn't even imagine typing four spaces before each line... I couldn't be bothered, it'd proper produce RSI lol. I don't understand why that is necessary at all. And is it saying that you don't have to use ?> at the end of PHP-only documents? Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-596751 Share on other sites More sharing options...
Daniel0 Posted July 22, 2008 Share Posted July 22, 2008 And is it saying that you don't have to use ?> at the end of PHP-only documents? The PHP closing tag is technically only necessary if you need something after the PHP block. An argument for omitting it is that you will prevent any accidental whitespace after which will interfere with things that are dependent on that no output has been sent yet (headers for instance). Such things can be incredibly difficult to debug. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-596760 Share on other sites More sharing options...
corbin Posted July 23, 2008 Share Posted July 23, 2008 No tabs is standard? wtf? I couldn't even imagine typing four spaces before each line... I couldn't be bothered, it'd proper produce RSI lol. I don't understand why that is necessary at all. And is it saying that you don't have to use ?> at the end of PHP-only documents? In some editors, you can hit tab, and it will put 4 spaces. I do prefer tabs though.... Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-597151 Share on other sites More sharing options...
proggR Posted July 23, 2008 Share Posted July 23, 2008 In some editors, you can hit tab, and it will put 4 spaces. That would be handy. I read somewhere (and may be wrong) that Python determines blocks of code by the four-space method instead of using braces. Is that true? Like you would have something like if (condition) do this and this and then this end if or something to that effect. If i didn't have an editor like that, it'd drive me nuts. I may have misread that info though. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-597524 Share on other sites More sharing options...
adam84 Posted July 23, 2008 Share Posted July 23, 2008 I used the second one and echo 'This method'; It was the way I was taught. I find it my code to be cleaner that way, but in the end I guess if the code works then whatever Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-597668 Share on other sites More sharing options...
Daniel0 Posted July 23, 2008 Share Posted July 23, 2008 In some editors, you can hit tab, and it will put 4 spaces. That would be handy. I read somewhere (and may be wrong) that Python determines blocks of code by the four-space method instead of using braces. Is that true? Like you would have something like if (condition) do this and this and then this end if or something to that effect. If i didn't have an editor like that, it'd drive me nuts. I may have misread that info though. Python does use indention for that purpose, but what you use to indent doesn't matter as long as you are consistent. You could use one space, two spaces, three spaces, a tab, etc. - it really doesn't matter as long as you don't mix it up. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-597813 Share on other sites More sharing options...
proggR Posted July 23, 2008 Share Posted July 23, 2008 In some editors, you can hit tab, and it will put 4 spaces. That would be handy. I read somewhere (and may be wrong) that Python determines blocks of code by the four-space method instead of using braces. Is that true? Like you would have something like if (condition) do this and this and then this end if or something to that effect. If i didn't have an editor like that, it'd drive me nuts. I may have misread that info though. Python does use indention for that purpose, but what you use to indent doesn't matter as long as you are consistent. You could use one space, two spaces, three spaces, a tab, etc. - it really doesn't matter as long as you don't mix it up. Thanks for clearing that up. I'd like to learn Python someday. I've heard good things about it. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-597886 Share on other sites More sharing options...
RichardRotterdam Posted July 24, 2008 Share Posted July 24, 2008 It depends on if i use an IDE and what language. normally in php i just use dreamweaver and using the enter for every curley bracket becomes annoying so i use nr 1. how ever if i use eclipse or flash develope for developing flash c++ or java it automaticly creates the nr 2 notation so i let it be for what it is Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-598413 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.