Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
admin/inc/common.php const reuse
#1
I've been going through all the CMS options on opensourcecms and I must say GetSimple is very nice and clean, and the code is well written for the most part. I was looking through some of the code for my own site customization and noticed some minor code bits that might be written better from a functional standpoint.

Typically, and this is maybe stemming from my DOS batch file scripting, when you declare a constant or variable that is the base path of the following variables, you simply reuse it after setting it.

In the admin/inc/common.php file there is a block of code:

Code:
// Define some constants
define('GSROOTPATH', get_root_path());
define('GSADMINPATH', get_admin_path());
define('GSADMININCPATH', get_admin_path(). 'inc/');
define('GSPLUGINPATH', get_root_path(). 'plugins/');
define('GSLANGPATH', get_admin_path(). 'lang/');
define('GSDATAPATH', get_root_path(). 'data/');
define('GSDATAOTHERPATH', get_root_path(). 'data/other/');
define('GSDATAPAGESPATH', get_root_path(). 'data/pages/');
define('GSDATAUPLOADPATH', get_root_path(). 'data/uploads/');
define('GSTHUMBNAILPATH', get_root_path(). 'data/thumbs/');
define('GSBACKUPSPATH', get_root_path(). 'backups/');
define('GSTHEMESPATH', get_root_path(). 'theme/');

Seems that calling the get_root_path() function over and over is extremely unnecessary and while it's probably not a noticeable performance hit.. maybe a few nanoseconds... from a development standpoint, it means changing a lot more code. Something like this would seem more appropriate, where you reuse the initially defined constants:

Code:
// Define some constants
define('GSROOTPATH', get_root_path());
define('GSADMINPATH', get_admin_path());
define('GSADMININCPATH', GSADMINPATH. 'inc/');
define('GSPLUGINPATH', GSROOTPATH. 'plugins/');
define('GSLANGPATH', GSADMINPATH. 'lang/');
define('GSDATAPATH', GSROOTPATH. 'data/');
define('GSDATAOTHERPATH', GSROOTPATH. 'data/other/');
define('GSDATAPAGESPATH', GSROOTPATH. 'data/pages/');
define('GSDATAUPLOADPATH', GSROOTPATH. 'data/uploads/');
define('GSTHUMBNAILPATH', GSROOTPATH. 'data/thumbs/');
define('GSBACKUPSPATH', GSROOTPATH. 'backups/');
define('GSTHEMESPATH', GSROOTPATH. 'theme/');

This cuts down on the back and forth between the function file and the common file and makes it more developer friendly.

It's no showstopper of course. Thank you for a great product Smile
Reply
#2
Great idea - I went ahead and updated the SVN with this. http://code.google.com/p/get-simple-cms/...tail?r=283
- Chris
Thanks for using GetSimple! - Download

Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Reply
#3
Smile Great idea ! It was perfect.
Reply




Users browsing this thread: 1 Guest(s)