PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Sun May 31, 2020 11:09 pm

All times are UTC - 5 hours

Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Oct 28, 2014 3:46 am 
Forum Newbie

Joined: Tue Oct 28, 2014 3:27 am
Posts: 2

I've been struggling with designing / structuring some scripts.

I'm not very experienced in programming in general but I had to write some scripts to make life (a lot) easier at work.
I've been using PHP and in short one script does things like:

Select specific records from an Oracle DB
Create different kinds of output files (XML)
Updating some statuses depending on the specific case
Inserting errors (xml validation errors) back into the DB
Create a .zipfile

Another one handles some return files and does some other actions:

Read a bunch of XML files
Check XML file contents
Inserts some of the XML files into a DB table
Insert some other XML files into another DB table
Update some statuses depending on the contents of the XML
Run an Oracle stored procedure for some specific return files (depending on a check against the result of another query)

The principle is not very complicated.
There needs to be no user interface and in time I'd like to run the scripts automatically via Cron, only checking some script output.

I've been struggling a lot with application/script design and structuring the script.
I can get the script to do what I need it to do but it's possibly (probably) messy, especially if someone else needs get into it or edit it, or even check it out.

It started out small but continues to grow with more and more functions that send around variables or do certain actions and it starts
to get complicated to follow the flow of the script. (Especially for colleagues who haven't worked on it...)

I've been thinking about making it better and cleaner.
I've read about it and thought about making it object oriented but it seems that I can design things in 10 different ways and I seem to fail to see the benefit or find a good way to get things done.

I've been asking colleagues and trying to find out a better / cleaner way but I always get stuck because I don't know what the best (or A GOOD) way is...

Do I make it OO or not?
What needs to be a Class? (and why)
What doesn't need to be a class?
How do I keep it clean and organised?
How do I keep it readable and easy to grasp/follow for others?

I started to try to build some classes to keep things a bit cleaner but soon I realized I wasn't using objects a lot
but just straightforward static functions all the time. And if I did use objects I failed to see how to use them to better the design. (they seemed unnecessary or something)

It's like I'm completely lost in the possibilities and can't see a GOOD way to design things.

Even if I would completely rewrite it (now), I've got this feeling that even then I won't be sure if the design is proper...

I don't even know how or where to start to make things better. That's the reason for the post...

Any help of suggestions to get me starting designing things in a good way would be very welcome!
Thanks for your feedback!

PostPosted: Tue Oct 28, 2014 7:40 am 
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Making the switch to OO can definitely be challenging. When deciding what classes to build and what goes where, I would recommend first considering the . SOLID principles as a whole will lead to very good, extensible, maintainable code. Start with the S. In short, your DBAL shouldn't worry about writing XML, and your XML writer shouldn't care where the data comes from. I need to run out the door now, but I'll be happy to continue this discussing throughout the day, and I'm sure others here also have plenty of insight to share.


PostPosted: Tue Oct 28, 2014 2:45 pm 
Forum Newbie

Joined: Tue Oct 28, 2014 3:27 am
Posts: 2
Thanks for your post Celauran. It's very much appreciated.
I'll read up on the single responsibility principle (and SOLID principles).

If I think about the flow of the program I visualize some kind of controller that manages the flow of all the different steps that the script must to.
I'm not sure if things like such a controller should also be made into some kind of class itself or might this just be some function that triggers other "stuff", other functions or object's methods to get things done?

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 9 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group