Developer guideline » History » Version 13
Max Milbers, 02/25/2011 04:43 PM
1 | 1 | Max Milbers | h1. Developer guideline |
---|---|---|---|
2 | |||
3 | 12 | Max Milbers | h2. Philosophy and goal |
4 | 13 | Max Milbers | |
5 | 12 | Max Milbers | The goal is to write a small fast and stable core code which is easy to extend. The priorities are as the following: |
6 | - Write OOP and clean in the given MVC structure |
||
7 | - Protect and secure the code |
||
8 | - the code should be fast and performant |
||
9 | - Focus on the core functions |
||
10 | 1 | Max Milbers | |
11 | 12 | Max Milbers | and as last thing, think about eyecandies and design. |
12 | 7 | Max Milbers | |
13 | 12 | Max Milbers | Remember we dont want an ecommerce framework full of features. We want a slim and fast framework which can be easily extended with features. |
14 | 7 | Max Milbers | |
15 | 1 | Max Milbers | - Mistakes might happen, important is to learn from them |
16 | |||
17 | - It is better to do something wrong than to do nothing |
||
18 | 12 | Max Milbers | |
19 | h2. Guidelines for teamwork |
||
20 | 13 | Max Milbers | |
21 | 12 | Max Milbers | The first very important rule is, |
22 | 1 | Max Milbers | |
23 | 13 | Max Milbers | *"Stay at your task"* |
24 | 12 | Max Milbers | |
25 | This means, when you find a bug somewhere while you are working on your task, dont just fix it. Look in the tracker who is responsible for the code, look in the svn history to see who did the last change or even better the changes which cause your bugs. When you dont find any person ask the projectleader (Max Milbers). Give the person some time to correct the code, fix it only, when you get an OK by the projectleader. |
||
26 | |||
27 | This rule is very important for the teamwork and has several reasons. |
||
28 | It often happens that someone is changing something which is effecting the code in many areas. We already had the case that someone (lets call him A) changed the code. Another guym, B, was working on his own code, using code written by A. Due the changes the code of B didnt worked before and B started to "fix" the code of A, which just destroyed the work of A, because B thought in the old structure and A just invented a new system. |
||
29 | Or another annoying and frustrating case is when B says to A, hey there is a bug in your code. A starts immediatly fixing it, but B fixed it also and A gets an conflicted SVN and did his working for nothing or even worse (we had that also), gets an conflicted svn and has to fix the "fix" of B again, because only A really understoods that part of code. |
||
30 | |||
31 | So working in the svn together is quite easy even when we work on the same files, when everyone follows the rules: |
||
32 | - update your svn often |
||
33 | - stay at your task |
||
34 | - dont fix bugs not related to your task without permission by the projectleader. |
||
35 | |||
36 | Note about svn: |
||
37 | If you want to committ a new version, first do an update via SVN of it, then test it again and after that committ it. |
||
38 | |||
39 | h2. Requesting features. |
||
40 | |||
41 | If you have an idea or special interest for VirtueMart, write it in the internal forums where we can discuss it and develop a plan. However, if you start developing something then finish it. Too often developers are very enthuastic and start a great, big, mega feature and end up with nothing useable. Discussion and planning in the forum should make possible to work together |
||
42 | |||
43 | Everyone can add features as many as he wants but must follow 3 rules |
||
44 | 1. it must not slow down the page and/or can be disabled and the standard is disabled |
||
45 | 2. it must fit in the rest of the architecture |
||
46 | 3. it must be bugfree for the release date (Beta, RC, Final) |
||
47 | |||
48 | 7 | Max Milbers | |
49 | h2. Some general coding advices |
||
50 | 1 | Max Milbers | |
51 | 10 | Max Milbers | In general we avoid the use of globals. Globals are hard to maintain and they are unsure variables. |
52 | Here a guide for [[Setting up a Development Environment]] |
||
53 | 7 | Max Milbers | Here are some general tips and tricks for php: [[general php hints]] |
54 | |||
55 | 1 | Max Milbers | h2. Code Formatting: |
56 | |||
57 | We follow the joomla standard in most cases. We use camelCase for methods. For faster copypasting and working with database fields. Both variable and database fields are lowercase and seperated with "_". You may use for internal variables camelCase also. |
||
58 | |||
59 | Example: |
||
60 | |||
61 | |||
62 | 5 | Max Milbers | <pre> |
63 | 4 | Max Milbers | function exampleMethod($data = 0) { |
64 | 2 | Max Milbers | if (!$product_id) $product_id = JRequest::getInt('product_id', 0); |
65 | if ($product_id > 0) { |
||
66 | 1 | Max Milbers | ...; |
67 | } |
||
68 | 2 | Max Milbers | } |
69 | 1 | Max Milbers | </pre> |
70 | 6 | Max Milbers | |
71 | 1 | Max Milbers | h2. SQL Formatting: |
72 | |||
73 | The queries should follow this format: |
||
74 | |||
75 | @$q = 'SELECT `example_id` FROM `#__vm_table` WHERE `user_id`=' . (int)$user_id;@ |
||
76 | |||
77 | or if the |
||
78 | |||
79 | $user_id is an array, use $user_id["myId"] |
||
80 | |||
81 | Placing of the ` improves speed, because the sql-engine can parse faster ( and do not have to reparse). |
||
82 | |||
83 | h2. Variable Formatting: |
||
84 | |||
85 | Due abstract logic many people name their variables or database fields just "id", "key", "value" and so on. |
||
86 | |||
87 | In our case we want to rewrite the structure of an old code, therefore it is very important to find the variable in the code rather fields in the database. |
||
88 | |||
89 | So we want a kind of this: <classname><tablename>variable like here |
||
90 | |||
91 | $vendor_id or $payment_method_id |
||
92 | |||
93 | Exception from this rule is the use of ordering and published. Ordering and published with 0 and 1 as values are useable with the joomla standard methods. |
||
94 | |||
95 | h2. Filename Formatting: |
||
96 | |||
97 | Filenames should be lowercase. |
||
98 | |||
99 | Models filenames (mymodel.php), view direcorynames (myview), all helper files and probably all other files loaded by the Joomla Framework, must be lowercase, no matter how you load the file: |
||
100 | |||
101 | @$this->loadHelper('adminMenu'); // looks for the file helpers/adminmenu.php@ |
||
102 | |||
103 | More complex filenames that are specific to your task and loaded by your own code (using require_once()), e.g. mySpecificClass.php, can be camelcase. |
||
104 | |||
105 | Read this article for more info http://docs.joomla.org/Talk:Developing_a_Model-View-Controller_Component_-_Part_1#Use_lowercase_file_and_folder_names_in_your_components.21 |
||
106 | |||
107 | 11 | Oscar van Eijk | h2. Table names |
108 | |||
109 | Depending on the way mysqld is configured, the MySQL server might be case sensitive on linux systems too, so _always_ use the correct case, preferably lowercase only. |
||
110 | |||
111 | 9 | Oscar van Eijk | h2. URL Requests: |
112 | |||
113 | As written in the section __Filename Formatting__ above, Joomla requires lowercase filenames. However, URL requests are not lowercased by Joomla. In order to find the proper views and controllers, make sure you use lowercase only in requests, e.g.: |
||
114 | |||
115 | $this->setRedirect('index.php?option=com_virtuemart&view=updatesMigration', $msg); // Fails |
||
116 | $this->setRedirect('index.php?option=com_virtuemart&view=updatesmigration', $msg); // Works |
||
117 | |||
118 | |||
119 | 1 | Max Milbers | h2. Character Encoding: |
120 | |||
121 | Like in joomla we use UTF-8. Please ensure the right character set in your IDE. |