Struggle with designing some scripts
Posted: Tue Oct 28, 2014 3:46 am
Hello!
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!
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!