Posted on 11-10-2007
Filed Under (Code efficiency, PHP, Planning, Web Development) by dotWdot

Next in our series of strategic planning your next web venture is Functions and includes. I am speaking php, although it applies outwardly to other languages. I won’t go into this too much on the technical front but with intent to plan they are key things to note.

Let your functions carry the site - Every bit of code typed twice is wasted time, poor efficiency and essentially extra cost, to keep this to a minimal every time you have a routine operation that you think you might want to use somewhere else - stick it in a function. Those few extra clicks on your keyboard might save you 5 or 10 minutes later looking for the code snippet you need.

“Functions spitting out arrays will save you days” - if you can get all the fields from a row of data into a nice array spat out of a good efficient function it can be a very useful way of coding more efficiently!

Includes - A good place to learn organisational file structures is well established open source solutions. Get oscommerce, download phpbb, go to wordpress.org and click download, open them up - install them, read the files, check how they do it. Typically all the aspects of the file are split into individual files. So the header may be header.php, footer - footer.php - hell take a guess at ’side_bar.php’. But they are like that for good reason, splitting the site up into as many parts as possible will allow you to be versitile with your site construction - stick a menu there, and on that other page but not on the homepage. Or use a header and footer throughout the site with just two lines of code: Include (”inc_files/header.php”); Include (”inc_files/footer.php”);

By using includes that are mercilessly divided into specific uses you can be harshly efficient with your pages, including only the exact required elements, no generic bit you forgot to cut out or header processing etc.

I usually tend to run a lot of the whole website from 1 main include file also, so I will have my header.php and footer.php but I will also run maindetails.php or similar - this will allow you to set default page operations throughout the site, such as automatically generating titles, headers, feeding meta data, page monitoring, user authentication, database details etc. Although top heavy it allows you to keep the main aspects together.

As a final note when building from the ground up, or any site that has substancial amount of custom functions. Lists and changelogs are a great tool for several reasons. Getting into the programmers mindset of keeping change logs, updating field lists or function lists will save you even more time as you progress. Secondly it allows greater dispersion of responsibility - as discussed in previous planning posts, its a dull point but what would happen if you died? or less dramatically if you wanted to employ a coder to take over? without any form of lists, annotation or change log it would be a nightmare and cost stupendously more than a little bit of while you work annotation. Even if you dictate your annotation and get it typed up! So do the boring - keep lists, annotate.


If you liked this post then check out the rest of the series on programming your next e-business:

    Read More   
Post a Comment
Name:
Email:
Website:
Comments:
    • e-business, SEO, Internet Theory and a little Coding...


  • Blogroll