Liquid Fire Posted July 27, 2008 Share Posted July 27, 2008 I am very similar to the first one with a minor difference: if(hours < 24 && minutes < 60 && seconds < 60) { return true; } else { return false; } Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-600794 Share on other sites More sharing options...
Third_Degree Posted July 29, 2008 Share Posted July 29, 2008 Well I'll add my two cents I like to call it "pretty but optimized" <?php if ( function( $parameter, $parameter ) ) { print 'Hey ' . $var; } else { print ( 10 / 5 ) + ( 12 / 6 ); } ?> Always print over echo, always single over double quotes, always spaces after parentheses. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-602393 Share on other sites More sharing options...
448191 Posted July 29, 2008 Share Posted July 29, 2008 Well I'll add my two cents I like to call it "pretty but optimized" <?php if ( function( $parameter, $parameter ) ) { print 'Hey ' . $var; } else { print ( 10 / 5 ) + ( 12 / 6 ); } ?> Always print over echo, always single over double quotes, always spaces after parentheses. What's 'optimized' about it? And why print over echo? Theoretically, echo should be faster than print (because print is a function, echo a construct), though no-one has been able to produce a conclusive benchmark to support it. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-602489 Share on other sites More sharing options...
paul2463 Posted July 29, 2008 Share Posted July 29, 2008 I code exactly like the person I plagarised from - oops did that come out loud??? only joking by the way guys... I use method #2 I prefer all my braces to be vertically coincident so I can easily see which opening and closing braces match( obviously on small functions / code ), I write using PHPDesigner which places the matching braces under the opening one and I find it much better for me to debug my own crap that way. ( usually takes ages so it has to be easily read) Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-602499 Share on other sites More sharing options...
Liquid Fire Posted July 29, 2008 Share Posted July 29, 2008 I think having braces on there own line make it easier to read code that has nesting control statements. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-602524 Share on other sites More sharing options...
KevinM1 Posted July 29, 2008 Share Posted July 29, 2008 I think having braces on there own line make it easier to read code that has nesting control statements. That's why I switched to that style myself. I kept getting a lot of parse errors because I'd forget a brace or two. Doing it like this: function myFunc($arg) { foreach($arg as $value) { echo $value; } } Makes it a lot easier on me, and saves me time in the long run as I don't have to hunt for matching braces. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-602569 Share on other sites More sharing options...
nadeemshafi9 Posted July 29, 2008 Share Posted July 29, 2008 do while($_GLOBALS['owight']){ do{ if(check() == 1) echo"<input type=\"text\" name=\"item_name\" value=\"".$item->item_name."\">"; else if(check() == 2) echo "<script>get_adverts(\"main_content_area\");</script>"; else if(check() == 3) echo "<script>get_adverts('main_content_area');</script>"; else foreach($things as $thing) echo $thing["thing_name"]; }while($_SESSION["ok"]); while(mysql_fetch_array($results)) echo $results["feild"]; } Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-602882 Share on other sites More sharing options...
corbin Posted July 29, 2008 Share Posted July 29, 2008 "do while($_GLOBALS['owight']){" Is that even a valid construct? Why not just while? "Makes it a lot easier on me, and saves me time in the long run as I don't have to hunt for matching braces." Lots of editors highlight matching braces, but I can see what you're saying. I personally like: if() { } But, logically if() { } Makes more sense.... Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-602954 Share on other sites More sharing options...
Third_Degree Posted July 29, 2008 Share Posted July 29, 2008 Well I'll add my two cents I like to call it "pretty but optimized" <?php if ( function( $parameter, $parameter ) ) { print 'Hey ' . $var; } else { print ( 10 / 5 ) + ( 12 / 6 ); } ?> Always print over echo, always single over double quotes, always spaces after parentheses. What's 'optimized' about it? And why print over echo? Theoretically, echo should be faster than print (because print is a function, echo a construct), though no-one has been able to produce a conclusive benchmark to support it. 1.print is not a function...http://www.php.net/print 2.Also, PHP was born from C, and C uses print... 3.Lastly, echo checks for parameters whereas print does not, so the return value vs. the check evens out timewise (roughly) Single quotes parse faster than double quotes, you can get conclusive proof of that looking at the php source, this is also why i concatenate how I do. Overall, I guess it's just my programming roots in C coming out in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-603019 Share on other sites More sharing options...
KevinM1 Posted July 29, 2008 Share Posted July 29, 2008 Makes it a lot easier on me, and saves me time in the long run as I don't have to hunt for matching braces. Lots of editors highlight matching braces, but I can see what you're saying. I personally like: if() { } But, logically if() { } Makes more sense.... Oh, I know that a lot of editors highlight matching braces. I mean, I use Notepad++, so I have it right at my fingertips. But, it doesn't really help much if you have several long nested blocks which require you to scroll to see one of the highlighted pair. I rely much more on the indentation markers myself, which is one of the reasons why I like a block style to my coding. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-603074 Share on other sites More sharing options...
Daniel0 Posted July 29, 2008 Share Posted July 29, 2008 Single quotes parse faster than double quotes, you can get conclusive proof of that looking at the php source, this is also why i concatenate how I do. http://phpbench.com indicates that it doesn't matter much. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-603087 Share on other sites More sharing options...
Third_Degree Posted July 29, 2008 Share Posted July 29, 2008 Single quotes parse faster than double quotes, you can get conclusive proof of that looking at the php source, this is also why i concatenate how I do. http://phpbench.com indicates that it doesn't matter much. interesting Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-603112 Share on other sites More sharing options...
corbin Posted July 30, 2008 Share Posted July 30, 2008 Makes it a lot easier on me, and saves me time in the long run as I don't have to hunt for matching braces. Lots of editors highlight matching braces, but I can see what you're saying. I personally like: if() { } But, logically if() { } Makes more sense.... Oh, I know that a lot of editors highlight matching braces. I mean, I use Notepad++, so I have it right at my fingertips. But, it doesn't really help much if you have several long nested blocks which require you to scroll to see one of the highlighted pair. I rely much more on the indentation markers myself, which is one of the reasons why I like a block style to my coding. Heh, yeah I use Notepad++ too. Seems more logical to me to have same level curly braces, but habbits die hard x.x. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-603280 Share on other sites More sharing options...
448191 Posted July 30, 2008 Share Posted July 30, 2008 1.print is not a function...http://www.php.net/print 2.Also, PHP was born from C, and C uses print... 3.Lastly, echo checks for parameters whereas print does not, so the return value vs. the check evens out timewise (roughly) Ah, yeah, I meant it returns a value. My bad. I did some dirty benching myself, and found that passing substrings to echo as arguments is REALLY slow. Print vs echo was too close to call. Anyway, as you point out yourself, it doesn't make any real difference if you use echo or print, performance wise. Doesn't make your coding style 'optimized'. Single quotes parse faster than double quotes, you can get conclusive proof of that looking at the php source, this is also why i concatenate how I do. No conclusive proof of that. Also, unlike the results at phpbench.com, some crude tests I did two years ago show that using double quotes on basic strings is actually slightly faster than using single quotes. We're talking 0.0001ms, and on a different system it might turn out the other way around. Concatenation vs nesting (expanding) variables in double quotes strings came out about 0.007ms in favour of the former. I guess the moral is: it doesn't matter. Overall, I guess it's just my programming roots in C coming out in PHP. That's fine, but it's just preference, doesn't make your coding style 'optimized'. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-603425 Share on other sites More sharing options...
Third_Degree Posted July 30, 2008 Share Posted July 30, 2008 1.print is not a function...http://www.php.net/print 2.Also, PHP was born from C, and C uses print... 3.Lastly, echo checks for parameters whereas print does not, so the return value vs. the check evens out timewise (roughly) Ah, yeah, I meant it returns a value. My bad. I did some dirty benching myself, and found that passing substrings to echo as arguments is REALLY slow. Print vs echo was too close to call. Anyway, as you point out yourself, it doesn't make any real difference if you use echo or print, performance wise. Doesn't make your coding style 'optimized'. Single quotes parse faster than double quotes, you can get conclusive proof of that looking at the php source, this is also why i concatenate how I do. No conclusive proof of that. Also, unlike the results at phpbench.com, some crude tests I did two years ago show that using double quotes on basic strings is actually slightly faster than using single quotes. We're talking 0.0001ms, and on a different system it might turn out the other way around. Concatenation vs nesting (expanding) variables in double quotes strings came out about 0.007ms in favour of the former. I guess the moral is: it doesn't matter. Overall, I guess it's just my programming roots in C coming out in PHP. That's fine, but it's just preference, doesn't make your coding style 'optimized'. fair enough Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-603745 Share on other sites More sharing options...
ardyandkari Posted July 31, 2008 Share Posted July 31, 2008 since i seem to be challenged in reading code i do it like this: <?php if ((!isset($_POST[something))) { this } else { if ("doo"=="doo") { echo "DOO"; } else { echo "wee"; } } this way i can kind of see if and where i am missing squggly brackets. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-605099 Share on other sites More sharing options...
Liquid Fire Posted August 1, 2008 Share Posted August 1, 2008 since i seem to be challenged in reading code i do it like this: <?php if ((!isset($_POST[something))) { this } else { if ("doo"=="doo") { echo "DOO"; } else { echo "wee"; } } this way i can kind of see if and where i am missing squggly brackets. The is the first time i have even seen code formatted like that. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-605761 Share on other sites More sharing options...
ardyandkari Posted August 2, 2008 Share Posted August 2, 2008 most likely so...i just need to do it that way because if i don't, i'm on here asking for help when i am just missing a }...then i fee like an idiot and scurry away to my tiny room....... Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-605839 Share on other sites More sharing options...
Stooney Posted August 2, 2008 Share Posted August 2, 2008 I use tabs for indentation over 4 spaces. After reading the zend stuff I'm curious as to which is more popular/standard (tabs or 4 spaces). <?php if($jim){ dosomething(); } else{ dosomethingelse(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-606288 Share on other sites More sharing options...
ardyandkari Posted August 2, 2008 Share Posted August 2, 2008 i tab...dont know about standards... Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-606308 Share on other sites More sharing options...
nadeemshafi9 Posted August 4, 2008 Share Posted August 4, 2008 Well I'll add my two cents I like to call it "pretty but optimized" <?php if ( function( $parameter, $parameter ) ) { print 'Hey ' . $var; } else { print ( 10 / 5 ) + ( 12 / 6 ); } ?> Always print over echo, always single over double quotes, always spaces after parentheses. What's 'optimized' about it? And why print over echo? Theoretically, echo should be faster than print (because print is a function, echo a construct), though no-one has been able to produce a conclusive benchmark to support it. 1.print is not a function...http://www.php.net/print 2.Also, PHP was born from C, and C uses print... 3.Lastly, echo checks for parameters whereas print does not, so the return value vs. the check evens out timewise (roughly) Single quotes parse faster than double quotes, you can get conclusive proof of that looking at the php source, this is also why i concatenate how I do. Overall, I guess it's just my programming roots in C coming out in PHP. i keep it if(){ } and when i come to edit it i open it up if() { } Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-607510 Share on other sites More sharing options...
nadeemshafi9 Posted August 4, 2008 Share Posted August 4, 2008 do while($_GLOBALS['owight']){ do{ if(check() == 1) echo"<input type=\"text\" name=\"item_name\" value=\"".$item->item_name."\">"; else if(check() == 2) echo "<script>get_adverts(\"main_content_area\");</script>"; else if(check() == 3) echo "<script>get_adverts('main_content_area');</script>"; else foreach($things as $thing) echo $thing["thing_name"]; }while($_SESSION["ok"]); while($a = mysql_fetch_array($results)) echo $a["feild"]; } Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-607512 Share on other sites More sharing options...
keeB Posted September 2, 2008 Share Posted September 2, 2008 i tab...dont know about standards... When working in a team environment, spaces. Save newlines as \n, not \r\n. Standards vary between teams, and can be anything from tabs to spaces to the combination of the two. The only thing that matters is consistency. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-631728 Share on other sites More sharing options...
Daniel0 Posted September 2, 2008 Share Posted September 2, 2008 The carriage return is incredibly annoying when working in vim. I hate that character. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-631775 Share on other sites More sharing options...
neylitalo Posted September 2, 2008 Share Posted September 2, 2008 Daniel0: dos2unix takes care of that. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/page/3/#findComment-631832 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.