Stephen Posted June 19, 2008 Share Posted June 19, 2008 What's your coding style, or form? Here are some examples grabbed off Wikipedia: if (hours < 24 && minutes < 60 && seconds < 60) { return true; } else { return false; } if (hours < 24 && minutes < 60 && seconds < 60) { return true; } else { return false; } if ( hours< 24 && minutes< 60 && seconds< 60 ) {return true ;} else {return false ;} Using that kind of example, my coding style/form is: if (hours<24 && minutes<60 && seconds<60) { return true; } else { return false; } And with echos I do echo("text"); instead of echo "text";. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/ Share on other sites More sharing options...
Daniel0 Posted June 19, 2008 Share Posted June 19, 2008 What's up with the third one? o_O I use number two. Generally I code after the ZF standard. By the way, this is kind of poll-ish, so I'll move it to the Polls forum. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-568840 Share on other sites More sharing options...
Stephen Posted June 19, 2008 Author Share Posted June 19, 2008 Third one is weird, I just grabbed it off Wikipedia as an example xD. And thanks. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-568843 Share on other sites More sharing options...
serverman Posted June 19, 2008 Share Posted June 19, 2008 i echo' '; Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-568872 Share on other sites More sharing options...
Darklink Posted June 19, 2008 Share Posted June 19, 2008 If you echo using single apostraphes you can't quickly pass variables nor can you make \r\n linebreaks. Anyway, I use the first one in my code. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-568979 Share on other sites More sharing options...
.josh Posted June 19, 2008 Share Posted June 19, 2008 I use the 2nd one. Or rather, that's the closest one. Here's how I would write it: // comment about what I want to be true if ((hours < 24) && (minutes < 60) && (seconds < 60)) { // comment about what happens if true return true; // comment about if it's false } else { // comment about what happens if false return false; } // end if I followed Daniel's link and it looks like I follow about 95% (give or take) of their coding standard. Or rather, they follow me, seeing as how I've been writing code for much longer than they've been around Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-569117 Share on other sites More sharing options...
448191 Posted June 19, 2008 Share Posted June 19, 2008 I used to code like this: if((hours < 24) && (minutes < 60) && (seconds < 60)){ return true; } else { return false; } But since a month or so we've got an an official coding standard at work, resulting in me adopting this style: if((hours < 24) && (minutes < 60) && (seconds < 60)) { return true; } else { return false; } It took some getting use to, but now I do think it is the most readable. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-569182 Share on other sites More sharing options...
.josh Posted June 19, 2008 Share Posted June 19, 2008 I could *probably* live with doing it this way: // comment about what I want to be true if((hours < 24) && (minutes < 60) && (seconds < 60)) { // comment about what happens if true return true; } // comment about what I want to be false else { // comment about what happens if false return false; } // end if..else Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-569251 Share on other sites More sharing options...
corbin Posted June 19, 2008 Share Posted June 19, 2008 I usually do this: if(cond1 == true && cond2 == true && number > number2) { } else { } No commenting at all ;p. I comment the tops of pages sometimes, but... I'm not much of a commenter.... I follow a little bit of the ZF standards.... But, some of it I refuse to follow. (I like my tabs, for example, dammit!) Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-569301 Share on other sites More sharing options...
Stephen Posted June 19, 2008 Author Share Posted June 19, 2008 Yeah, I rarely comment on my scripts :/. I think I should get into the habit though Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-569414 Share on other sites More sharing options...
Orio Posted June 19, 2008 Share Posted June 19, 2008 I also use: <?php if (hours < 24 && minutes < 60 && seconds < 60) { return true; } else { return false; } ?> But only when the block contains more than one line. For an example, I do: <?php for($i = 0; $i < 7; $i++) if($i % 2 == 0) echo $i."<br>"; //And while($i < 7) { if($i % 2 == 0) echo $i."<br>"; $i++; } ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-569430 Share on other sites More sharing options...
Derleek Posted June 20, 2008 Share Posted June 20, 2008 i do it like this: if(x>129038129038) { return blah; } I saw some code organized like this and i just felt it made sense... Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-569838 Share on other sites More sharing options...
Stephen Posted June 20, 2008 Author Share Posted June 20, 2008 Now I'm trying to do it more like this: //Checks if hours is less than 24, minutes less than 60, and seconds less than 60. if (hours<24 && minutes<60 && seconds<60) { return true; //Returns true if the above statement is true. } else { return false; //Returns false if the above statement is false. } Using tab makes it easier to intend for me. Comments I'm not really into the habit still. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-569909 Share on other sites More sharing options...
ILYAS415 Posted June 22, 2008 Share Posted June 22, 2008 Well I use coding style 2 since i find it takes up less space and makes the code seem less confusing. if((hours < 24) && (minutes < 60) && (seconds < 60)){ return true; }else{ return false; } Oh yes and also I only indent when im using dreamweaver (thats about 95% of the time). Before i started using actionscript i wouldn't indent my php at all! Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-571468 Share on other sites More sharing options...
jcaptain007 Posted June 25, 2008 Share Posted June 25, 2008 i used the second one..i've known it as a standard. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-573913 Share on other sites More sharing options...
Daniel0 Posted June 25, 2008 Share Posted June 25, 2008 i used the second one..i've known it as a standard. As far as I know, there is no official standard. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-573914 Share on other sites More sharing options...
keeB Posted June 26, 2008 Share Posted June 26, 2008 My style <?php if(($hours < 24) && ($minutes < 60) && ($seconds < 60)) return true; return false ?> As for multiline things (I am not a fan of else): <?php class MyClass { private $foo = null; public function __construct() { $this->foo = "constructed"; } public function getFoo() { if ($this->foo != null) return foo; // handle the 'else' statement here. } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-574673 Share on other sites More sharing options...
serverman Posted June 26, 2008 Share Posted June 26, 2008 my coding style when i am just doing it for the fun of it i code like this... <?php if ($blah== $blahh){ ?> what ever you would echo<?php }else{ ?> whatever <?php } ?> i use var's more than i need too also but i do every thing wierd lol when i lisson to music in head phones i only have one speaker in myear prolly because i dj as a hobby and if am not using firefox i cant spell Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-574827 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 I guess you didn't use firefox for that post.. As for multiline things (I am not a fan of else): Why not? I mean, you never know what interesting ways people will come up with to circumvent your code, so wouldn't having a "catch-all" or "catch-all-the-rest" type thing be the best thing you can have for that? Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-575005 Share on other sites More sharing options...
nadeemshafi9 Posted June 26, 2008 Share Posted June 26, 2008 i use all three ways and i use without the {} one liners Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-575137 Share on other sites More sharing options...
keeB Posted June 26, 2008 Share Posted June 26, 2008 I guess you didn't use firefox for that post.. As for multiline things (I am not a fan of else): Why not? I mean, you never know what interesting ways people will come up with to circumvent your code, so wouldn't having a "catch-all" or "catch-all-the-rest" type thing be the best thing you can have for that? I do. If my if statement returns something, else will never get executed if the condition is true, so.. 'else' is really what happens If my if statement did not execute Generally, though, I try to keep conditional logic to a minimum. I like to keep my code as straight forward as possible. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-575477 Share on other sites More sharing options...
serverman Posted June 27, 2008 Share Posted June 27, 2008 I guess you didn't use firefox for that post.. shure didn't Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-575724 Share on other sites More sharing options...
KevinM1 Posted June 27, 2008 Share Posted June 27, 2008 I used to code like: function myFunction(){ if($me == "awesome"){ echo "Damn straight."; } else{ echo "You suck."; } } In the last month or so, I've changed to: function myFunction() { if($me == "awesome") { echo "Damn straight."; } else { echo "You suck."; } } It seems more readable to me, especially when using something like Notepad++ which highlights matching braces. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-575906 Share on other sites More sharing options...
nadeemshafi9 Posted July 7, 2008 Share Posted July 7, 2008 you can use a JAVA JIT style coding tec Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-583424 Share on other sites More sharing options...
ILYAS415 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. Quote Link to comment https://forums.phpfreaks.com/topic/110866-coding-style/#findComment-586482 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.