No announcement yet.

James Battersby Tutorial 06: Basic Best Practice

  • Filter
  • Time
  • Show
Clear All
new posts

  • James Battersby Tutorial 06: Basic Best Practice

    A few of these tutorials feature specific products and opinions. I do not work for any of the mentioned companies and these opinions (although shared by many) are my own. Take them as you will (visit my website for more information on my background).

    06: Basic Best Practice

    What is best practice?

    Best practice refers to a set of unofficial guidelines that developers (of almost any technology) follow in order to make sure that they do the best quality work. This is not only to make their lives easier but also to help others understand what you have done and, when you run into trouble, help you quickly. I am a true believer in best practice, partly because I have to (I'm a member of the British Computer Society) but mainly because it really infuriates me when people are too lazy to follow a few simple rules that would make everyone's lives last a bit longer.

    Web development is distinctly void of many best practices probably because when it was invented there was no such thing. However my background also includes Java programming which is steeped in best practice and most of its concepts can be reflected in web development. I urge you to follow these guidelines - they may infuriate you from time to time at first but once you've done it a few times and hit a problem (you will, we all do) you'll be thankful for your diligence.

    Web Development Best Practices

    Put comments in your code
    They don't have to be very descriptive - just enough to remind you and, more importantly someone else, what that particular bit of code does.

    Write in lower case
    Filenames and your code should always be written in lower case because ITS VERY DIFFICULT TO READ UPPER CASE TEXT ESPECIALLY WHEN THERE IS A LOT OF IT.

    Use camelCase
    camelCase is a recognized way of how you should name things when they have more than one noun in the name. Sticking with the lower case character mantra above camelCase allows you to put multiple words in one word while still making it legible. For example, if I want to refer to an object called Coffee Shop I could do this in a number of ways:
    • coffeeshop (in lowercase)
    • coffeeShop (in camelCase)
    camelCase follows the following format: all characters in lowercase except for the first letter of each word after the first. It just makes your code a little easier to read.

    Indent your code
    Remember when you were first introduced to paragraphs at school? You may have been told to indent the first line of each paragraph if there isn't going to be a gap between them because it makes it easier to read. The same principle applies in web development except for every line. Most web development languages are hierarchically structured meaning one thing may contain another thing. If I were to write down the structure of a 2.4 children family in pseudo code it may look like this:

    as oppose to:


    Pseudo Code
    This refers to code that isn't code. Written in comments the programmer writes down the steps of a function or method in plain language to be read as reference.
    For example:
    if money in bank account <= 0
      ask for loan
      withdraw money

    Do your research
    This covers a couple of ideas. Firstly don't be afraid to ask. There are thousands of web developers around the world and are more than likely to help if you run into trouble. Search through Google, join various message boards (such as HTMLForums) - it is very likely someone else has had the same problem as you at some point.

    The second idea is don't reinvent the wheel. Above the basics you will be able to find that solutions to complex problems already exist and there is no shame in using someone else's solution. If you do be sure to give credit to the original author. If you make an improvement let them know - that way, as a collective, we all become better.

    High Cohesion, Low Coupling
    This has been borrowed directly from Java and other object oriented programming languages.

    Cohesion is the idea that everything or part has a distinct purpose or functionality. One script does one thing, one file is for one purpose etc. This way when something breaks down and you have an idea of what might be the problem, you will know exactly where to look saving you time and effort trying to find the problem if you had one function that did everything. Be strict about what does what.

    Coupling is the idea of things that are connected to each other where a change in one thing affects another. As developers we don't want this at all - if you make a change to something you don't want it to affect something else otherwise you'll go on a wild goose chase. Nothing should depend on anything else.

    As a result you end up files and code that is broken down into distinct parts that do not affect one another should any one of them be changed. At least, that is what you aim for. In web development this can be applied as I explain the purposes of each component but in a nutshell HTML should be used only for content, CSS only for styling, Javascript for "nice to have" effects and AJAX requests, PHP (or any other server side language) should be used for the logic of a web application and MySQL (or any other database language) should be used to manipulate data storage.

    Follow standards
    Standards are invented and maintained so that we all sing from the same sheet thus making our collective work aim towards a common goal. Doing this not only allows external organisations to interpret your work in a uniform way (and hopefully bring to an end of cross browser issues) but it also highlights your professionalism as a developer. Its easy to cheat but in the end you are only cheating yourself. If you followed the previous tutorial you should already have the tools that will notify you when you go astray. Take heed and have patience - you'll be a better person at the end of it.

  • #2
    a very nice tutorial

    where can i findthe other tutorial such as tutorial 1, 2 and other up to tutorial 6??


    • #3
      Hello batt,

      I love the information that you shared here. Thank you for sharing this one.
      I know lots of user's need this information. God Bless.