Your Coding Structure?

Discussion in 'PHP' started by Jpauls104, Oct 10, 2006.

  1. #1
    I was wondering what your methods were for keeping track of large web projects that require a huge amount of code. Is there a common format which allows for other people to quickly jump in a help?
     
    Jpauls104, Oct 10, 2006 IP
  2. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I find the best method is to put like functionality in like places.

    In a recent directory project, I used an index.php file to direct traffic. Instead of putting functions in that file, it calls functions from the multitude of included files.

    I then split up the functions so that like functions were in their own file. This also lets me assemble libraries of functions and/or objects for use in other projects. It also lets me keep "includes" in a directory outside the webserver.

    You can see this concept in action for projects such as joomla, mambo and phpld.

    Also, it is important to have ongoing documentation in the code if you want to make it easier for other people to jump in and out. Naming variables and functions in ways that also reveal their purpose is also helpful when other people look at your code. For instance, I like to use a variable named $printMe when assembling data from files and/or databases for display to the user -- or for printing to a file.

    I would also suggest using as few globals as possible. Pass data to functions so that they can work on local copies and explictly return the new variable values. Always initialize variables before use. These two things makes it easier for people to jump in because they do not need to figure out how or where a variable got its value. This also extends the usefulness of good functions.
     
    clancey, Oct 10, 2006 IP
  3. Pat Gael

    Pat Gael Banned

    Messages:
    1,331
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Indeed, "slicing" your site by means of different include sections make the site easier to update and debug in case of errors.

    In addition, making a common configuration file which includes a number of variables such as site name, meta tags, common features, etc. etc. makes reusable your coding, enabling its use in multiple sites but customized accordingly with just a few changes to common includes, variables and layout design.
     
    Pat Gael, Oct 10, 2006 IP
  4. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #4
    I manage my code with a LOT of annotations :D

    
    // Bit of this..
    
    // Bit of that..
    
    PHP:
    Lee.
     
    BRUm, Oct 10, 2006 IP