View Full Version : Best Way to Code

04-06-2012, 06:39 PM
Hi guys,

Im building a site from scratch and Im doing it with only me and my friend so far. When i started I was told to learn HTML and CSS first, which i did and then moved onto PHP, some javascript, and then messed around with joomla to understand how CMS worked.
I have a pretty good idea of how coding works as i did COBOL and PASCAL in college, and some C++ on my own.
The thing is that when I looked in some of the Joomla php files I can see that it is coded completly different to what ive seen on tutorials on the web. Id like to know if there is a definete best way to code, and where i could find out the best way to build a site from scratch without creating the site then having to scrap all the code ive worked on in the future to replace it with better coding conventions. As it would save alot of time, I like jumping in the deep end. :-)

Cheers. Jim.

PS. If you look inside the joomla index.php file youll know what i mean...


// Set flag that this is a parent file.
define('_JEXEC', 1);

if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';

if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE.'/includes/defines.php';

require_once JPATH_BASE.'/includes/framework.php';

// Mark afterLoad in the profiler.
JDEBUG ? $_PROFILER->mark('afterLoad') : null;

// Instantiate the application.
$app = JFactory::getApplication('site');

// Initialise the application.

// Mark afterIntialise in the profiler.
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;

// Route the application.

// Mark afterRoute in the profiler.
JDEBUG ? $_PROFILER->mark('afterRoute') : null;

// Dispatch the application.

// Mark afterDispatch in the profiler.
JDEBUG ? $_PROFILER->mark('afterDispatch') : null;

// Render the application.

// Mark afterRender in the profiler.
JDEBUG ? $_PROFILER->mark('afterRender') : null;

// Return the response.
echo $app;

04-07-2012, 12:20 AM
Well, no I don't know what you mean.

It's just like any application that you look at in that it is divided into multiple levels of abstraction. True, that you cannot tell what is going on just by looking at one file of php any more than you can tell how a C++ program works by reading main(). Programing simply is not that transparent.

The real work of that file you posted is in 'framework.php' and its included files. If you understand the programming language at all, then you just keep going deeper in the includes until you get to some code that you understand. Then you've hit the lowest level of abstraction of the application in question. Everything else should simply call those functions in some sequence that will only make sense when you know what each one of them do.

04-07-2012, 01:33 AM
i don't understand what you are saying because i m well known of this code but in your way of describe i never understand.

fort st john (http://NorthernGroove.com)

04-07-2012, 01:40 AM
Cobol and Pascal are procedural programming languages.

PHP is an object oriented language.

There are huge differences between these two types of languages.

Being familiar with a dozen or more procedural languages it still took me a couple of years to work out how object oriented really works.

Presumably if you don't understand this difference the C++ you wrote was actually C rather than C++ as C is a procedural language and C++ adds the extra constructs needed to make it object oriented.

04-07-2012, 02:02 AM
Thanks akonlaura, i think i need to work on the object-orientated stuff. Do you know where is a good source of information on the OOP side of things.

And Jackson, I know that there is multiple levels of abstraction! I understand how includes work.

I was hoping that someone could point my in the direction of a source to learn the best tips and techniques of creating a site from scratch in the same way.