<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Samet Kilictas's Blog &#187; developer</title>
	<atom:link href="http://samet.kilictas.com/tag/developer/feed/" rel="self" type="application/rss+xml" />
	<link>http://samet.kilictas.com</link>
	<description>Personal E-Notebook</description>
	<lastBuildDate>Fri, 30 Apr 2010 07:29:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Another developer comic</title>
		<link>http://samet.kilictas.com/another-developer-comic/</link>
		<comments>http://samet.kilictas.com/another-developer-comic/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 07:55:06 +0000</pubDate>
		<dc:creator>Samet Kilictas</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Comic]]></category>
		<category><![CDATA[developer]]></category>

		<guid isPermaLink="false">http://samet.kilictas.com/?p=374</guid>
		<description><![CDATA[Thank you Kerem.]]></description>
			<content:encoded><![CDATA[<p>Thank you Kerem.</p>
<p style="text-align: center;">
<p style="text-align: center;"><img class="size-full wp-image-375 aligncenter" title="Compiling" src="http://samet.kilictas.com/wp-content/uploads/2009/11/compiling.png" alt="Compiling" width="413" height="360" /></p>
<p style="text-align: center;">
<p style="text-align: center;"><img class="alignnone size-full wp-image-389" title="comic" src="http://samet.kilictas.com/wp-content/uploads/2009/11/comic.jpg" alt="comic" width="484" height="162" /></p>
]]></content:encoded>
			<wfw:commentRss>http://samet.kilictas.com/another-developer-comic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Coding Guidelines For Developers</title>
		<link>http://samet.kilictas.com/coding-guidelines-for-developers/</link>
		<comments>http://samet.kilictas.com/coding-guidelines-for-developers/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 10:57:31 +0000</pubDate>
		<dc:creator>Samet Kilictas</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Samet]]></category>

		<guid isPermaLink="false">http://samet.kilictas.com/?p=62</guid>
		<description><![CDATA[@author andrej arn @author sam blume @version 4.6 updated 2005-11-24 Basically&#8230; we&#8217;d like to have a clean and professional, bug-free code. Most people have different coding styles. And most think that &#8220;the other style&#8221; is ugly. We don&#8217;t want to force you changing your style. Here is how we do it and like it: o) [...]]]></description>
			<content:encoded><![CDATA[<p><strong>@author andrej arn<br />
@author sam blume<br />
@version 4.6 updated 2005-11-24</strong></p>
<p>Basically&#8230;<br />
we&#8217;d like to have a clean and professional, bug-free code.<br />
Most people have different coding styles. And most think that<br />
&#8220;the other style&#8221; is ugly. We don&#8217;t want to force you changing<br />
your style. Here is how we do it and like it:</p>
<p>o) We use capital letters for constants. e.g. define(&#8216;CONSTANT&#8217;, 1).<br />
We also use the capital form of  TRUE, FALSE and NULL.<br />
This is true for PHP, note that javascript needs lowercase.</p>
<p>o) If a function is described to return bool, expect to get a real bool<br />
(TRUE/FALSE) and not an int (0/1). So please code your functions and<br />
methods that way.</p>
<p>o) Don&#8217;t trust the return values from php methods. If they are stated<br />
to return bool, they often return an int (0/1). So don&#8217;t directly<br />
return that from your functions, convert to (bool) if necessary.</p>
<p>o) Never ever use echo, print and die and the like inside your methods.<br />
Use return.</p>
<p>o) this applies also for white spaces. if you start your file with anything<br />
(an empty line) before the     considered as output. This makes header() calls impossible (cookie,<br />
session). The same applies for white spaces after the ?&gt; tag. take care!<br />
Even a newline is too much. This is a typical php newbie mistake.</p>
<p>o) Everything should be as os independant as possible. Including windows.</p>
<p>o) Make your code work with PHP version 4.3.0+ and 5.0.5+.<br />
Don&#8217;t support php3.</p>
<p>o) Make the php exam. Repeat it from time to time.</p>
<p>http://www.blueshoes.org/en/developer/syntax_exam/</p>
<p><span id="more-62"></span></p>
<p>o) Code object oriented. (PHP4)</p>
<p>o) Avoid setting vars in the global scope. If you need one, prefix it.<br />
Example: $GLOBALS['_Bs_MyClass_MyVar'] = &#8216;foo&#8217;;</p>
<p>o) Avoid using things from global scope inside methods. Instead &#8216;include&#8217;<br />
them in the constructor.</p>
<p>o) Prefix classes with Bs_. This is a poor man&#8217;s namespace.</p>
<p>o) Name your files like the classes: a class named &#8216;Bs_Something&#8217; will<br />
have the file name &#8216;Bs_Something.class.php&#8217;.</p>
<p>o) One class per file.</p>
<p>o) References:<br />
Don&#8217;t return temporaries by reference.<br />
function &amp;foo() {<br />
return new StdClass(); //this is wrong<br />
return $ret = new StdClass(); //this is wrong too</p>
<p>//this is wrong too. (it works at least in php 4.4.1,<br />
//but who knows, it&#8217;s inconsistent, so please don&#8217;t use it.)<br />
return $ret =&amp; new StdClass();</p>
<p>$ret =&amp; new StdClass(); return $ret; //this is right<br />
return FALSE; //this is wrong<br />
return $ret = FALSE; //this is wrong<br />
$ret = FALSE; return $ret; //this is right<br />
$classOne =&amp; new StdClass();<br />
$classTwo =&amp; new StdClass();<br />
return (true) ? $classOne : $classTwo; //this is wrong<br />
}<br />
$object =&amp; foo();</p>
<p>Don&#8217;t pass temporaries by reference:<br />
function foo(&amp;$param) {}<br />
foo(TRUE); //this is wrong<br />
$param = TRUE; foo($param); //this is wrong</p>
<p>//this is wrong. (it works, but who knows, it&#8217;s inconsistent,<br />
//so please don&#8217;t use it.)<br />
foo(new StdClass);</p>
<p>$param =&amp; new StdClass(); foo($param); //this is right</p>
<p>Also take care when encapsulating functions:<br />
function foo() { return new StdClass(); }<br />
function bar(&amp;$param) {}<br />
bar(foo()); //this is wrong<br />
$object = foo(); bar($object); //this is right</p>
<p>When you create a new instance of a class, *always* do it by reference:<br />
$object =&amp; new SomeClass();<br />
^&#8212;-&gt;this one<br />
This is *important*, *important*, *important*!!. Trust me. if you don&#8217;t,<br />
you will after having strange bugs in your code and not finding them<br />
for hours.<br />
Also read http://www.zend.com/manual/language.oop.newref.php please.</p>
<p>o) Please use the same coding style as it is already used, if you can.<br />
I know that changing your coding style is not easy if you&#8217;re used to<br />
something.</p>
<p>old: &#8211; a tab is 2 spaces<br />
new: &#8211; a tab is a tab, we set it to the width of 2, but feel free to<br />
configure your editor to show it as 3, 4, 8, whatever.</p>
<p>- A function is written like:<br />
function something(param, param) {<br />
//some code<br />
}</p>
<p>- An if statement is written like:<br />
if ($this == $that) {<br />
} elseif ($this &gt; $that) {<br />
} else {<br />
}</p>
<p>- Use spaces to separate:<br />
$x .= $y . &#8216;hello&#8217;;   instead of   $x.=$y.&#8217;hello&#8217;;<br />
exceptions are (for readability):<br />
- $array = array(&#8216;key&#8217;=&gt;&#8217;value&#8217;, &#8216;key2&#8242;=&gt;&#8217;value2&#8242;);<br />
- for ($i=1; $i&lt;=10; $i++) {<br />
- function myFunction($a=&#8217;default&#8217;, $b=&#8217;foobar&#8217;) {</p>
<p>o) Naming conventions:</p>
<p>- PHP itself is *very* inconsistent about the naming:<br />
isset() but is_string() =&gt; underscore or not,<br />
strtolower but bin2hex =&gt; to or 2,<br />
create_function but str_shuffle =&gt; verb object, object verb,<br />
strpos(haystack, needle) but in_array(needle, haystack) =&gt; order of param<br />
so let&#8217;s do it better.</p>
<p>- Use studly caps (first letter of each word capitalized (but not the<br />
first one), otherwise lower case, no underscores) for vars, functions<br />
(methods), lists, anything that needs a unique name.<br />
class names go like &#8216;Bs_SomeClass&#8217;.<br />
vars/functions/objects/db-names are started lowercase, class<br />
names/db-table names are started uppercase:<br />
$someVarName         instead of   $some_var_name<br />
someFunctionName()   instead of   some_function_name()<br />
SomeObject           instead of   some_object<br />
this especially also applies for short forms:<br />
$someDbTable         instead of   $someDBTable<br />
$someHtmlString      instead of   $someHTMLString</p>
<p>It is easier to read, and you can be sure how it was written. We think<br />
it&#8217;s better from experience. (An exception is the table field name/term<br />
ID because of a naming convention.)</p>
<p>Often it is hard to decide if a word is made up of multiple words.</p>
<p>These words are considered being one word, not two, and thus have<br />
no capital:<br />
- username  (not userName)<br />
- password  (not passWord)<br />
- blueshoes (not blueShoes)</p>
<p>These words are considered being two words and thus have a capital:<br />
- fileName (not filename)<br />
- passPhraze (not passphraze)<br />
- dateTime  (not datetime)</p>
<p>A few other writings:<br />
- email    (not eMail or so, because someEmail will work while<br />
someeMail or someEmail or someEMail would break the rules.)</p>
<p>Please avoid something like &#8216;$conn1&#8242; (&#8216;$conn2&#8242;, &#8216;$conn3&#8242; &#8230;) because<br />
you cannot see if it was $conn1 or $connl. See what i mean? (one or<br />
a small L, depending on the font)</p>
<p>- Don&#8217;t use the fancy way pdf2html. It&#8217;s kinda breaking the studly<br />
caps rule. it would be pdf2Html and then it&#8217;s not that readable<br />
anymore because both &#8217;2&#8242; and &#8216;H&#8217; are &#8220;upper case&#8221;. So always use<br />
pdfToHtml.</p>
<p>- Use verb object, not object verb. So makeObject(), not objectMake().</p>
<p>- If in doubt, use java syntax/style.</p>
<p>o) Learn the difference between == and === and != and !==. Read the manual<br />
and check http://www.blueshoes.org/en/developer/php_cheat_sheet/</p>
<p>o) Passing by reference: Our code needs to be compatible with PHP 4 and 5.<br />
PHP5 passes all objects by reference while PHP4 passes them by copy.<br />
To make both versions behave the same way, do the following:<br />
To pass by reference (99% of all cases):<br />
function foo(&amp;$theObject, $theInteger) {<br />
&#8230;<br />
}<br />
foo($someObject, 5);<br />
To pass by value (1% of all cases):<br />
function foo($theObject, $theInteger) {<br />
&#8230;<br />
}<br />
$copyOfObject = bs_clone($someObject);<br />
foo($copyOfObject, 5);</p>
<p>o) Private vars and methods start with an underscore.<br />
_foo is a private var, foo is a public var, _foo() is a private method<br />
and foo() a public one.</p>
<p>o) In your classes, define all your public and private class vars using<br />
var $something; or var $_something;<br />
even if you don&#8217;t set a default value. It will help maintaining the code.</p>
<p>o) Document while you code. Please document (phpdoc, like javadoc) your<br />
functions, classes, methods, even class vars. I know that coders are<br />
always in a hurry. But it will save a lot of time in the end!</p>
<p>It looks like this:<br />
/**<br />
* What the function does in one line.<br />
* Here goes some more detailed description on 0-n lines, if needed.<br />
* @access  [public|static|pseudostatic]<br />
* @param   [string|int|double|bool|array|object|mixed] $paramName desc<br />
* @return  datatype  description<br />
* @throws  [bs_exception|bool FALSE|NULL...]<br />
* @see     someFunction(), var someVar<br />
* @todo    description<br />
* @since   bs4.1, php4.3             (comma separated list)<br />
* @status  stable|experimental       (if not set then considered stable)<br />
* @pattern singleton|factory|mvc|observer|facade|&#8230;<br />
*/<br />
function something() {<br />
}</p>
<p>For variables the @var keyword is used instead of @param:<br />
/**<br />
* Some internally used var.<br />
* @access private<br />
* @var    bool $someStatus<br />
* @see    setSomeStatus()<br />
*/<br />
var $_someStatus = FALSE;</p>
<p>The description may include HTML, but please avoid it on the first line.</p>
<p>#@pattern singleton means that the constructor returns a reference<br />
#to an already existing instance, if there is one.</p>
<p>o) Write ecg classes for your code. They will serve other coders<br />
as examples and make the code more safe. Especially when it is<br />
installed on other os&#8217;es, when new php/apache/mysql/&#8230; versions come<br />
out etc. See naming for a definition of ecg.<br />
The classes are in subfolders named &#8216;ecg&#8217;, for an example have a look<br />
at core/util/ecg/Bs_String_PhpUnit.class.php</p>
<p>o) Don&#8217;t eat junk food and never drink Red Bull at night. Pizza is ok. <img src='http://samet.kilictas.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>o) Don&#8217;t use underscores _ in databases (table names, field names).<br />
They are reserved for relations (foreign key by naming convention).<br />
Don&#8217;t use the numbers 2, 3 and 4 inside of db table names. They are<br />
reserved for the same reason.</p>
<p>o) Associative arrays are called &#8216;hash&#8217;, zero-based arrays are called<br />
&#8216;vector&#8217;. Please use these terms. Undefined arrays are called &#8216;array&#8217;.</p>
<p>o) Use the term &#8216;function&#8217; for &#8216;structured&#8217; procedural code. Use the term<br />
&#8216;method&#8217; for functions inside classes. Don&#8217;t use the terms &#8216;procedures&#8217;,<br />
&#8216;subs&#8217;, &#8216;routines&#8217; etc.<br />
sam: &#8220;methods are verbs, classes are substantives.&#8221; <img src='http://samet.kilictas.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>o) When you return inside a switch or something, write the break too.<br />
example:<br />
switch ($x) {<br />
case &#8216;hello&#8217;:<br />
return TRUE;<br />
break;<br />
}<br />
This way it will be harder for someone to &#8216;implement&#8217; bugs into your code.</p>
<p>o) Avoid buggy code. For example if you&#8217;re not 100% sure that a var is<br />
an array, do is_array(), sizeOf($array) and such.</p>
<p>o) To be PHP4 compatible instead of using try-catch use the do-while(FALSE)<br />
try-catch code, something like:<br />
do { // try block<br />
$isOk = someFunction();<br />
if (!$isOk) break;<br />
$isOk = otherFunction();<br />
if (!$isOk) break;<br />
//&#8230;<br />
$isOk = TRUE; //everything worked<br />
} while (FALSE);<br />
if ($isOk) echo &#8216;yeah&#8217;;</p>
<p>o) Form your var declaration blocks etc in a nice way: (note the extra<br />
spaces)<br />
$a        = &#8216;hello&#8217;;<br />
$bbbb     = &#8216;world&#8217;;<br />
$cccccccc = &#8216;foobar&#8217;;</p>
<p>o) Mostly use foreach instead of while-list to loop arrays. See sam&#8217;s<br />
php-bench: http://www.blueshoes.org/en/developer/php_bench/</p>
<p>Note: there are also, and i like them (andrej)<br />
while (list($k,) = each($a)) {<br />
while (list(,$v) = each($a)) {</p>
<p>o) Magic_quotes_gpc was a good idea to prevent sql injection.<br />
Unfortunately this feature can be turned on or off, was on in<br />
previous PHP releases and is turned off by default now. This makes<br />
the situation for libraries and released software a lot harder<br />
which has to work with different configurations.<br />
Check your php.ini, look for &#8220;magic_quotes_gpc&#8221;. It<br />
should be set to Off, not On. (magic_quotes_gpc = Off)<br />
BlueShoes fixes this by checking magic_quotes_gpc, and if it is on,<br />
it goes and undo&#8217;es the changes in _REQUEST, _GET, _POST and _COOKIE<br />
see bs_undoMagicQuotes().<br />
Note that there is other software around that does the opposite.</p>
<p>o) Make sure your code runs error free even if warnings and notices are<br />
enabled.</p>
<p>o) Use the new superglobals (_GET, _POST etc), make sure your code works<br />
if register_globals turned off. And we highly recommend to set<br />
register_globals to off.</p>
<p>o) JavaScript classes are named like in php, for example<br />
&#8220;Bs_FormFieldSelect.class.js&#8221;. If it&#8217;s a lib then it goes like<br />
Bs_FormFieldSelect.lib.js. A lib is simply a collection of functions<br />
for a special task, so not oo-code.</p>
<p>o) If you change something in code someone else maintains (and/or you&#8217;re<br />
not in the @author of the class or the function) then add your comments<br />
along with the date and your name, example:<br />
someCode(); //i did this because of that. 2002/10/16 &#8211;yourname</p>
<p>o) Don&#8217;t add email addresses in plain text. Even the phpdoc comments in<br />
the code get indexed, and thus could be spidered by email crawlers.<br />
Please use &#8220;&#8221; which makes it a bit harder to parse.</p>
<p>o) Naming (Glossary)</p>
<p>ecg          ElectroCardioGram<br />
In the code base you&#8217;ll find many subdirectories with that<br />
name. There are php code files that test our code. we<br />
thought calling them just &#8216;test&#8217; would not give them the<br />
honor they deserve, and prolly someone would just delete<br />
them. The ecg tests show a sysadmin very fast what&#8217;s not<br />
working (anymore) on his system, for example after the<br />
installation or after a php upgrade or whatever.</p>
<p>whtml        wysiwyg html. It&#8217;s a mime type in blueshoes. It means that<br />
the block [part] may be edited using wysiwyg. So it&#8217;s not<br />
xml compliant. A synonym would be &#8220;crappy html&#8221;.</p>
<p>URL: (see Bs_Url.class.php and its methods)<br />
scheme://user:pass@host:port/path?query#fragment<br />
example: url https://bill:gates@order.blue-shoes.com:81/forms/<br />
form.php?lang=fr&amp;sid=456456#address<br />
scheme     = https<br />
host       = order.blue-shoes.com<br />
port       = 81<br />
user       = bill<br />
pass       = gates<br />
path       = /forms/form.php<br />
query      = lang=fr&amp;sid=456456<br />
fragment   = address<br />
domain     = blue-shoes.com<br />
directory  = /forms/<br />
file       = form.php</p>
<p>xpv stands for xPointer vector. Match always returns an array, so xp<br />
is always an array, maybe an empty one.</p>
<p>UID          Unified ID.</p>
]]></content:encoded>
			<wfw:commentRss>http://samet.kilictas.com/coding-guidelines-for-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
