To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-03-2003, 08:25 PM   #1
Chris Muench
Junior Member
 
Join Date: Dec 2003
Posts: 5
Writing Maintainable Code

Download program (if you want): http://prdownloads.sourceforge.net/p...2.zip?download

Demo of program: http://phppointofsale.com/PHP_Point_Of_Sale/login.php


I wrote an open source program called PHP Point Of Sale. I wrote this code last year and have done updates along the way. The functionality of the program is great,but the code is hard to maintain and prone to bugs.

I want to do a rewrite but I need some opinions on how to write code that is easy to maintain.

I am not sure if I should program with classes and objects or on even how to approach rewriting it, so their is not so much code to maintain.

Basically here is how my program works.
The program runs on a mysql back-end with tables for customers, items, brands, categories, users, and sales. Currently the database structure is not great, but I know what to do in order to fix it.

Their are 4 parts to the program:
Customers, Items, Sales, and reports

In the Customers and Items module I have files for adding, updating, and deleting info from the customer table in the database.

The sales portion of the program is just to add orders to the sales table. This module also has files for updating, adding, and deleting data from the table.

Reports display sale information with 11 reports to choose from.


But my problem is, how can I somehow cut down on how many files and code I have and make the code easier to maintain. Should I have a file for adding, updating, and deleting data from the program?

What are some strategies you use when planning on how to make code easy to maintain?

Thanks for your suggestions,

Chris Muench
Chris Muench is offline   Reply With Quote
Old 12-03-2003, 10:00 PM   #2
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,124
We now have a forum devoted to this sort of thing; moving the thread there now.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 12-04-2003, 08:14 AM   #3
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
OO is intrinsicly more maintainable then PO code. However, well written PO code is more maintainable then OO code.

I haven't looked at your code yet so what follows is simply info for your digestion:

Limit nesting aids in maintainability - Usually when you nest ifs and loops you are using poor logic. Poor logic is prone to bugs and hard to fix.

Analyse all loops and if statements - You should use the bare minimum of loops and if statements. It will make your code run faster and make it easier to maintain in the long run.

Do not under any circumstances type the same code over and over again. Make it into a function so that if there is a bug you only have to fix it once and you're not chancing the ****roaches around with raid for months.

I'll take a look at your code latter then I'll be able to be more specific.
drawmack is offline   Reply With Quote
Old 12-05-2003, 02:02 PM   #4
Shrike
Not Yet Involved
 
Shrike's Avatar
 
Join Date: Oct 2003
Location: The Eighth, Sursamen
Posts: 2,254
I'm an OO noob but here's my suggestion (sorry if you aren't a noob )

Before starting the project identify each piece of functionality and consider making this a class. Also consider where functionality is duplicated and look at making a generic class which can be reused. Once you have your classes identified, look at the project as a whole and see if the class heirarchy falls down anywhere.

I didn't follow this on my last project, I started well with a framework class and a number of library classes, but the actual output classes became a horrible montrous mess of code

I read somewhere that if you are wondering if your classes are too complex then you have missed the point of OO programming. That rung some bells
__________________
The Hundredth Idiot
Shrike is offline   Reply With Quote
Old 12-05-2003, 03:43 PM   #5
Chris Muench
Junior Member
 
Join Date: Dec 2003
Posts: 5
Thanks, that is a good way to aproach it and I will try to do that tonight. I will see how it turns out!
Chris Muench is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 05:44 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.