{"id":70111,"date":"2021-08-26T04:10:05","date_gmt":"2021-08-26T08:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/good-coding-style-in-php-other-languages-15\/"},"modified":"2021-08-26T04:10:05","modified_gmt":"2021-08-26T08:10:05","slug":"good-coding-style-in-php-other-languages-15","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=70111","title":{"rendered":"Good Coding Style in PHP + Other languages #15"},"content":{"rendered":"<p>Style 1.1: Use proper indenting<\/p>\n<pre style='padding-left:5px;padding-right:5px'>while ($x &lt; $z) {    if ($a == 1)    {       echo &#039;A was equal to 1&#039;;  }   else    {       if ($b == 2)        {           \/\/do something      }       else        {           \/\/do something else     }   }}<\/pre>\n<p><\/p>\n<pre style='padding-left:5px;padding-right:5px'>1.2<br \/>while ($x &lt; $z) { if ($a == 1) {      echo &#039;A was equal to 1&#039;;  } else {        if ($b == 2) {          \/\/do something      } else {            \/\/do something else     }   }}<\/pre>\n<p>Style 2.1: Properly indent conditional statements. Always use braces, it will make later additions of more statements easier.<\/p>\n<pre style='padding-left:5px;padding-right:5px'>while ($x &lt; $z) {   if ($a == 1)    {       echo &#039;A was equal to 1&#039;;  }   else    {       if ($b == 2)        {           \/\/do something      }       else        {           \/\/do something else     }   }}<\/pre>\n<p>Style 2.2<\/p>\n<pre style='padding-left:5px;padding-right:5px'>while ($x &lt; $z) {   if ($a == 1) {      echo &#039;A was equal to 1&#039;;  } else {        if ($b == 2) {          \/\/do something      } else {            \/\/do something else     }   }}<\/pre>\n<p>3.1 Function Calls <br \/>No space between function names and parenthesis.<\/p>\n<pre style='padding-left:5px;padding-right:5px'>   $var = myFunction($x, $y);<\/pre>\n<p>3.2 Function declarations<\/p>\n<p>Use braces properly, give meaningful names to the parameters, always return values from functions. Avoid printing\/echoing inside functions.<\/p>\n<pre style='padding-left:5px;padding-right:5px'>function myFunction($province, $city = ''){   \/\/indent all code inside here   return $result;}   <\/pre>\n<p>4. Use comments before a function. Also, use comments before a block [especially if it uses some difficult to understand logic]use PHPDoc style comments that may work like Javadoc to create documentation from your source files<\/p>\n<pre style='padding-left:5px;padding-right:5px'>\/** *  short description of function * *   Optional more detailed description. * * @param $paramName - type - brief purpose *  @param ... *    ... *   @return type and description *\/<\/pre>\n<p>5. Use include_once or require_once instead of include or require to include a file that contains common variables, functions, classes.<br \/>6. Php tags:  always use<\/p>\n<pre style='padding-left:5px;padding-right:5px'>  <\/pre>\n<p>instead of<\/p>\n<pre style='padding-left:5px;padding-right:5px'>  <\/pre>\n<p>7. to enclose strings use single quote &#8216; &#8216; rather than double quotes &#8221;  &#8220;. Try to use . to concate string variables. You can use double quote and put variables inside.<\/p>\n<pre style='padding-left:5px;padding-right:5px'> $associative_array['name']; $var='My String';   $var2='Very... long... string... ' . $var . ' ...more string... ';  $sql=\"INSERT INTO mytable (field) VALUES ('$var')\";<\/pre>\n<p>8. Follow some conventions for variable and function names<\/p>\n<ul>\n<li> Class name start with uppercase letter. Each word should start with uppercase letter   <\/li>\n<li> Variable and function name may start with lower case letters. Then each word will start with a capital letter <\/li>\n<li> give meaningful names to variables and functions  <\/li>\n<li> Do not make them too lengthy. I prefer less than 12-15 character names    <\/li>\n<li>Do not abbreviate words in variable or function names. Use $url or $articleUrl as variable names, not $URL or $articleURL as <\/li>\n<\/ul>\n<p>From: http:\/\/sitestree.com\/?p=4741<br \/> Categories:15<br \/>Tags:<br \/> Post Data:2006-08-07 13:22:40<\/p>\n<pre><code>    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\"&gt;https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    (Big Data, Cloud, Security, Machine Learning): Courses: &lt;a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"&gt; http:\/\/Training.SitesTree.com&lt;\/a&gt; \n    In Bengali: &lt;a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\"&gt;http:\/\/Bangla.SaLearningSchool.com&lt;\/a&gt;\n    &lt;a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\"&gt;http:\/\/SitesTree.com&lt;\/a&gt;\n    8112223 Canada Inc.\/JustEtc: &lt;a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\"&gt;http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) &lt;\/a&gt;\n    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com'&gt; https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    Medium: &lt;a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"&gt; https:\/\/medium.com\/@SayedAhmedCanada &lt;\/a&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Style 1.1: Use proper indenting while ($x &lt; $z) { if ($a == 1) { echo &#039;A was equal to 1&#039;; } else { if ($b == 2) { \/\/do something } else { \/\/do something else } }} 1.2while ($x &lt; $z) { if ($a == 1) { echo &#039;A was equal to 1&#039;; &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=70111\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-70111","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":24412,"url":"http:\/\/bangla.sitestree.com\/?p=24412","url_meta":{"origin":70111,"position":0},"title":"Good Coding Style in PHP + Other languages #Root","author":"Author-Check- Article-or-Video","date":"April 8, 2021","format":false,"excerpt":"Style 1.1: Use proper indenting while ($x < $z) { if ($a == 1) { echo 'A was equal to 1'; } else { if ($b == 2) { \/\/do something } else { \/\/do something else } } } \u00a0 1.2 while ($x < $z) { if ($a ==\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65714,"url":"http:\/\/bangla.sitestree.com\/?p=65714","url_meta":{"origin":70111,"position":1},"title":"If then else in shell programming. Count the number of files in current directory, and check &#8230; #Linux\/Unix: Shell Programming &#8211; 001","author":"Author-Check- Article-or-Video","date":"July 12, 2021","format":false,"excerpt":"#!\/bin\/sh #count the number of files in current directory, and check if the number is equal to or greater than or less than 26 #NOF represents number of files NOF=`ls -l | wc -l` if [ $NOF -eq 26 ] then echo \"No of files and directories is equal to\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6010,"url":"http:\/\/bangla.sitestree.com\/?p=6010","url_meta":{"origin":70111,"position":2},"title":"\u09aa\u09bf\u098f\u0987\u099a\u09aa\u09bf \u09eb if&#8230;else&#8230;elseif \u09b8\u09cd\u099f\u09cd\u09af\u09be\u099f\u09ae\u09c7\u09a8\u09cd\u099f (PHP 5 if&#8230;else&#8230;elseif Statements)","author":"Author-Check- Article-or-Video","date":"February 7, 2015","format":false,"excerpt":"PHP \u09a4\u09c7 \u0986\u09ae\u09b0\u09be \u0995\u09cb\u09a8 variable \u0998\u09cb\u09b7\u09a3\u09be \u0995\u09b0\u09b2\u09c7 \u09a4\u09be $ \u099a\u09bf\u09b9\u09cd\u09a8 \u09a6\u09bf\u09df\u09c7 \u09aa\u09cd\u09b0\u0995\u09be\u09b6 \u0995\u09b0\u09c7 \u09a5\u09be\u0995\u09bf\u0964 \u0986\u09ae\u09b0\u09be \u09af\u09a6\u09bf if-else statement \u098f\u09b0 \u0995\u09be\u099c \u0995\u09b0\u09a4\u09c7 \u09af\u09be\u0987 \u09a4\u09be\u09b9\u09b2\u09c7 \u0986\u09ae\u09be\u09a6\u09c7\u09b0 \u098f\u0987 \u099a\u09bf\u09b9\u09cd\u09a8 \u09a8\u09bf\u09df\u09c7 \u0995\u09be\u099c \u0995\u09b0\u09a4\u09c7 \u09b9\u09ac\u09c7\u0964 \u0995\u09cb\u09a8 \u0989\u09a6\u09be\u09b9\u09b0\u09a8 \u09a6\u09c7\u0993\u09df\u09be\u09b0 \u0986\u0997\u09c7 \u0986\u09ae\u09b0\u09be \u098f\u0995\u099f\u09c1 if-else \u09ac\u09bf\u09b7\u09df \u099f\u09be \u09ac\u09c1\u099d\u09c7 \u09a8\u09c7\u0987\u0964 \u09aa\u09bf\u098f\u0987\u099a\u09aa\u09bf \u09ab\u09be\u0987\u09b2 \u09b0\u09be\u09a8 \u0995\u09b0\u09be\u09b0 \u0995\u09cd\u09b7\u09c7\u09a4\u09cd\u09b0\u09c7 \u0986\u09ae\u09be\u09a6\u09c7\u09b0 \u0985\u09a8\u09c7\u0995 condition \u09a5\u09be\u0995\u09a4\u09c7\u2026","rel":"","context":"In &quot;\u09aa\u09bf \u098f\u0987\u099a \u09aa\u09bf \u099f\u09bf\u0989\u099f\u09cb\u09b0\u09bf\u09df\u09be\u09b2 \u0964 PHP tutorial&quot;","block_context":{"text":"\u09aa\u09bf \u098f\u0987\u099a \u09aa\u09bf \u099f\u09bf\u0989\u099f\u09cb\u09b0\u09bf\u09df\u09be\u09b2 \u0964 PHP tutorial","link":"http:\/\/bangla.sitestree.com\/?cat=172"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65691,"url":"http:\/\/bangla.sitestree.com\/?p=65691","url_meta":{"origin":70111,"position":3},"title":"Take Two values from the user and do arithmetic operations #Linux\/Unix: Shell Programming &#8211; 001","author":"Author-Check- Article-or-Video","date":"July 11, 2021","format":false,"excerpt":"#!\/usr\/bin\/bash clear echo \"Enter First Number\" read x echo \"Enter Second Number\" read y #does not work for \/bin\/sh (( z = $x + $y )) (( a = $x - $y )) (( b = $x * $y )) (( c = $x \/ $y )) #clear echo \"Addition\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65784,"url":"http:\/\/bangla.sitestree.com\/?p=65784","url_meta":{"origin":70111,"position":4},"title":"Some JavaScript stuff that you need to know #JavaScript","author":"Author-Check- Article-or-Video","date":"July 14, 2021","format":false,"excerpt":"What you really need to learn in Javascript? 1. Where you can place JavaScript codes? Anywhere in the web-pages, ideally in the header section, or in an external file. If you keep javascript codes in an external file, the codes will be re-usable from different web-pages 2. Some basic programming:\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":70121,"url":"http:\/\/bangla.sitestree.com\/?p=70121","url_meta":{"origin":70111,"position":5},"title":"What you really need to learn in Javascript? #13","author":"Author-Check- Article-or-Video","date":"August 26, 2021","format":false,"excerpt":"What you really need to learn in Javascript? 1. Where you can place JavaScript codes? Anywhere in the web-pages, ideally in the header section, or in an external file. If you keep javascript codes in an external file, the codes will be re-usable from different web-pages2. Some basic programming: document.write('Hello\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/70111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70111"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/70111\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70111"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}