rajmohan Posted August 28, 2006 Share Posted August 28, 2006 Can any one help me how to write the coding format?And how to use functions and classes Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/ Share on other sites More sharing options...
.josh Posted August 28, 2006 Share Posted August 28, 2006 what do you mean by "coding format?" be more specific. format of what? some pre-defined function? php syntax rules in general? good coding practice? be more specific. Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81473 Share on other sites More sharing options...
Caesar Posted August 28, 2006 Share Posted August 28, 2006 http://www.php.netgood source for all your questions. :-) Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81474 Share on other sites More sharing options...
rajmohan Posted August 28, 2006 Author Share Posted August 28, 2006 i am asking about procedure the way of expression. Example if my coding is wided by another programmer how to they understand? Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81477 Share on other sites More sharing options...
.josh Posted August 28, 2006 Share Posted August 28, 2006 are you asking what is the "best" way to do things like indent and put comments in your code, so that other people can better understand it? Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81480 Share on other sites More sharing options...
rajmohan Posted August 28, 2006 Author Share Posted August 28, 2006 yes man you are correct. because the coding what we are doing should be understand by others. Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81481 Share on other sites More sharing options...
.josh Posted August 28, 2006 Share Posted August 28, 2006 well.. i pretty much answered your question in my question. make sure to properly indent, and keep it consistent. there are different indentation styles out there. there is no "right" way to indent. the key is to actually do it. and to keep it consistent. for example, don't do this:[code]if (blah) { blahblah} else { blahblahblah}[/code]and then later on switch to this:[code]if (blah){ blahblah}else { blahblahblah}[/code]and put comments everywhere. the more the merrier. also, make an effort to research and see if there is a better way to do something. the smaller the code, the better. and prettier. you could do this:[code]echo "1<br>";echo "2<br>";echo "3<br>";echo "4<br>";echo "5<br>";[/code]or you can do this:[code]for ($x = 1; $x < 6; $x++) { echo "$x<br>";}[/code]which do you think is better? Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81482 Share on other sites More sharing options...
Joe Haley Posted August 28, 2006 Share Posted August 28, 2006 Personally, i use the following structure for language constructs:[code=php:0]if (condition) // space between if and (condition){ // on their own lines // 4 spaces, or 1 tab at 4 space widths echo 'hi';}[/code]As for comments, use them. lots of them. and look at PHPDocumenter for generating HTML pages based on formated comments (http://www.phpdoc.org/)For comments, it is most important to explain WHY you are doing something, then simply stating what you are doing.Also, i never exclude curly brackets. even when i can. i find my code is a bit more readable that way[code=php:0]if(condition) print('hi');// i would do:if (condition){ print('hi');}[/code]mind you, these are only my personal preferances. do what looks best to you. But remember: Use the SAME coding-stlye, dont change halfway throgh. (this can lead to verry messy code) Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81483 Share on other sites More sharing options...
rajmohan Posted August 28, 2006 Author Share Posted August 28, 2006 Thank you my friends this will be very usefull way to follow coding structure. and if i am attending an interview they ask me to write a simple coding how can i express my coding to them. Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81488 Share on other sites More sharing options...
.josh Posted August 28, 2006 Share Posted August 28, 2006 i personally go for putting the { on the same line, indenting 3 spaces for the content, and lining up the } with the beginning. to me, it looks cleaner. but that's just me. As far as comments, well, look at example (try to look past the logic of the code :) ):[code]<?php// if user clicked the submit button from form1if ($_POST['submit']) { // did user enter in his name? if ($_POST['name'] != '') { //do something } else { // since user did not enter his name in.. // add some more info to the form error message $error .= " no name entered."; } //end else no name} // end if user clicked submit?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81489 Share on other sites More sharing options...
rajmohan Posted August 28, 2006 Author Share Posted August 28, 2006 you are correct but if they give me a big module how can i express them? if i give more commands that will be disturb to view all lines.putting commant line will be help full for if any one coming to modify the coding. but how to express the interviewer Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81493 Share on other sites More sharing options...
steelmanronald06 Posted August 28, 2006 Share Posted August 28, 2006 grab the phpbb source code, and in there is a text file that is like coding standards or something...it is basically an example on how they want the code to look if your gonna write mods. I use that as a typical coding standard for all my code. PHPBB sucks as a forum, but their code is normally clean and such. Double spaced in the approiate places, well commented, and indents. Quote Link to comment https://forums.phpfreaks.com/topic/18868-how-to-write-php-coding-format/#findComment-81569 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.