Emmtee Posted May 8, 2003 Share Posted May 8, 2003 looking at the current PHP code there's SQL code which is rendered beyond unreadability... example: $specials_query_raw = "select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and s.status = '1' order by s.specials_date_added DESC"; now look at it, when clearly formatted like this: $specials_query_raw = " SELECT p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS. " s WHERE p.products_status = '1' and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and s.status = '1' ORDER by s.specials_date_added DESC" ; i bet you could read the second example MUCH faster than the original one SQL queries work well with multiline requests, so no problem on this... additional benefits: - more compact diff files with clearer changes and easy matching - allows keeping patches when just small parts of the request code change - much better readability (reduced debugging time, reduced human errors) That's why I suggest to adapt to such formatting for the SQL code ... another issue are the LOADS of interpreter-close, interpreter-open blocks... it's a nice feature to use it, but without clear comments it renders the if-else structure horrible to see - take any html page code of OSC and take a look for something like this: <?php } ?> ... then try to find the part where the block starts... ... suggesstion: use COMMENTS like <?php if (something) { #### START OF BLOCk_SOMETHING #### ?> ..... <?php } ############## END OF BLOCk_SOMETHING ##### ?> last thing I saw: very short HTML code between Interpreter-mode-changes suggestion -> use echo/print for short HTML snipplets inside PHP code feedback welcome http://www.oscommerce.com/community/contributions,1762 Link to comment Share on other sites More sharing options...
Emmtee Posted May 11, 2003 Author Share Posted May 11, 2003 fix: when re-formatting SQL statements, one can encounter errors due to split results page function in general.php - it's using spaces in front of SQL keywords - when indenting with tabs, this can be a killer, removing the spaces yields old behaviour for me, tests still in progress... btw: i split default.php into 3 submodules in order to get it into a readable form.... discovering some redundancy in HTML code :) example: <!-- body - left nav end --> <!-- body - main part start --> <?php print '<td width="100%" valign="top">'; if ($category_depth == 'nested') { ## CASE 1 include(DIR_WS_MODULES . 'default_nested.php'); } elseif ($category_depth == 'products' || $HTTP_GET_VARS['manufacturers_id']) { ## CASE 2 include(DIR_WS_MODULES . 'default_products.php'); } else { ## CASE 3 (ELSE/DEFAULT) include(DIR_WS_MODULES . 'default_default.php'); } print '</td>'; ?> <!-- body - main part end --> <!-- right_navigation start--> http://www.oscommerce.com/community/contributions,1762 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.