+ Reply to Thread
Results 1 to 6 of 6

Thread: discussion: php script design

  1. #1
    mindstorm8191 is offline x10Hosting Member mindstorm8191 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    19

    discussion: php script design

    Personally, I'm not a very skilled web designer, but I have been coding or quite a while now, in various languages other than for web design. My current project is a browser-based game, which as I continue developing it, there becomes increasingly more tasks that must be performed, and these new tasks seem to be dropped into the same files I have already been using. Right now I have a script that is over 600 lines long, and compared to what I'm use to, this is crazy.

    I would like to open a discussion about how people lay out their written code. Do you like to use as few files as possible? Or do you like to divide everything into short, simple scripts that each do simple tasks? I am curious to know if anyone feels that such a large file is a bad thing or not.

  2. #2
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: discussion: php script design

    well as for all the scripts I have written so far, I have not gone back to optimize any of them.

    because when I write the script I just focus on getting it done, usable, and semi-easy to use
    so for me, I'll just write a script, it it is short, its short. But if I need more lines, i'll just have to write more.

  3. #3
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: discussion: php script design

    When a PHP file is executed, the whole file must be read and checked for errors. So obviously, if you keep running a large file, more and more checking needs to be done.
    If you organise the site into many smaller files and only run when you need to perform that specific task, much less checking will need to be done.
    In addition, this will make it easier to organise/update your game and resolve problems when they occur.
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  4. #4
    mindstorm8191 is offline x10Hosting Member mindstorm8191 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    19

    Re: discussion: php script design

    Hmm, I honestly don't know how much dividing my files would be. The largest file I have is an event handler, which runs any necessary code after a given time point has passed. I could divide this file so that it only calls the needed file for each task, but it may end up having to load most of the tasks (at least what's currently available). Would this be any faster than having it all in one location?

  5. #5
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: discussion: php script design

    The other thing to consider is that once your page is run once, PHP compiles it into bytecode so subsequent loads are much quicker. So, most of these things are less of an issue then.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: discussion: php script design

    I don't find file size (in terms of lines or bytes) or file count to be useful metrics, since they're rather simplistic and don't address design concerns. My main development guideline is "reduce dependencies"; each line should depend on other lines, each function on other functions, each class on other classes as little as possible. My second guideline is each file should be a logical unit, such as a class or a group of inter-related functions (what would be termed a "module" in languages that support the concept). A directory might also be used to group files into a module, especially to group classes together. Occasionally, I might put more than one class in a file if all but one are internal helper classes (what would be an inner class in C++). I tend to have many small functions/methods (a few lines each) rather than a few monolithic functions, but again it's more a matter logical tasks than line counts.

    The public API for the classes and modules heavily determines what goes in a file. The class/module should have a single, well defined purpose. Ideally, you should be able to describe the class in one sentence and its API should be somewhat self-documenting. Watch Joshua Bloch's How to Design a Good API and Why it Matters (or read the notes) for more on this.
    Last edited by misson; 07-26-2009 at 01:10 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Cannot get php script to work
    By avidgamer in forum Free Hosting
    Replies: 3
    Last Post: 09-03-2008, 04:35 PM
  2. currently have an application pending php
    By biomasti in forum Free Hosting
    Replies: 1
    Last Post: 09-03-2008, 01:58 PM
  3. Replies: 3
    Last Post: 03-10-2008, 12:22 PM
  4. Creating MySql database/table using php script
    By bushimports in forum Free Hosting
    Replies: 1
    Last Post: 02-02-2008, 12:43 AM
  5. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers