Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

114 lines (81 sloc) 4.143 kb
DEVELOPER README
Before you add or change any code, please keep in mind, that I have my own
ideology about code indentation, and many other things. Since most of the code is
done by me please follow my style and do not try to change anything. It would
annoy me and I'll have to change everything back so that all the files look
alike
Also read AModules3_Introduction.pdf which is located inside doc/ directory.
I'd like to point out few things:
-- <?php vs <? -------------
I follow this rule: 'if both work, I use shortest'. Really, php ALWAYS work with
<?. If there are some geeks who use only <?php, I am not willing to copy their
style.
-- unitialized variables --
I do not think it's a bad thing to use unitialized variables (inside functions/methods)
or array elements. People coming from C/C++ might think that unitialized variables
probably contain some mystic garbage. No. They are 'null' and will stay this way.
If I'm accessing unitialized variable inside array, it's 'null'. To make checks for
all this and handle it 'properly' - that would be a waste of my time, CPU time and
HDD space.
-- spaces between lines, functions etc --
I use function folding. I code in VIM. Folding present in many other editors. When
I look at my class code I want to see all the function "folded" fit on my screen,
so I can find and move them easily. PHPdoc wants comments to start before function,
I really don't care about them. Comment should be INSIDE function
-- PHPdoc argument explanation --
php is not a form of documentation. It's a source code. Functions should be commented
enough to understand the idea, but if comments consume more space than the function
itself it seems pointless to me. My moto is: Nicely written code is better than a coment.
There are not much code which is "Nicely written" so we still need few comments.
-- changing major classes --
try to keep everything modular. Don't put all your favorite functions inside api classes.
If you want to add something write a separate class which would be initialized
on demand. DBlite used here (2.x) is much more modular than 1.x version, please keep
it (and other classes) simple and modular.
-- spaces --
a:
if($a==1)return $b;
b:
if( $a == 1 )
return $b;
I consider "b" a space waister. If you do not like characters glued together, you should
configure your font settings. Switch on syntax highlihting. You'll be able to
read code easier. I like everything compact, don't change that. if($a == 1) is fine too.
-- long lines --
noone likes long lines. Split them.
-- complex structures --
if you are not sure what this do:
return(($a=myfunc())!==true?$a:$data);
you should studdy PHP syntax. I won't be writing it this way:
$a = myfunc;
if($a !== true){
return $a;
}else{
return $data;
}
-- other useless stuff --
When you write any of those:
echo "My name is ${name}.";
echo "My name is ".$name.".";
you are obviously waisting space again. It should be:
echo "My name is $name.";
There are cases when you can't write like this, then other syntax is ok:
echo "It's my ".$age."th birday";
-- file format --
keep it UNIX (\n)
-- queries --
If you want to write sql queries somewhere (without using dsql), do not
bother upercasing statements.
SELECT empono FROM people;
C'mon, typing letters in upcase is much slower and gives no good. Many browsers
highlight SQL reserved words inside php strings already. There was a days when
computers had only upper-cased characters, but those times are long gone. No need
to keep some prehistoric traditions even if Oracle does it.
-- closing ?> ---
I see no benefit in adding last ?> at the end of the file, but there is one disadvantage.
It happens that some editors are adding newlines at the end of the file. You click
with your mouse past the last line and newlines are added. If your editor is correct,
someone else's might be not. Adding newlines after ?> for a library files is fatal:
php wil send out headers and nothing will work. In a worst case scenario it happens when
client tries to edit config.php file. Therefore if a file is missing ?>, it's not a
bug, I left it intentionally.
Jump to Line
Something went wrong with that request. Please try again.