Shaun_Dark_Lord Posted September 26, 2018 Posted September 26, 2018 I need to rewrite a fairly hefty script, as it's gotten so bloated over the past few months that I feel a rewrite would be more efficient than trying to adapt it further (It needs adapting as it couldn't cope with some unexpected user behaviour.....). Am stumped on how to start over. The original script evolved over time, so I thought breaking it down into sections would give me the building blocks I'd need for the new version. But I'm just staring at them, and not seeing the order in which they need to go. How do the professionals do it? Is there a standard method I can look at?
dhicks Posted September 26, 2018 Posted September 26, 2018 How do the professionals do it? Is there a standard method I can look at? The term you're looking for is "code refactoring", which might give you something to Google for at least. Splitting a large, monlithic program up into smaller chunks is what various language features are for - different languages are going to have different facilities available, but you could try: - Splitting functionality into functions in the same, single script file - still makes for a large wodge of code to view all in one go, but might make it easier to get your head round one function at a time. - Object-orientated features - put the functionality into classes, much the same as with functions but encapsulates the data structure along with the code to manuipulate it. - Pile everything off into a library - can reduce the amount of code crammed onto one screen. - Write a domain-specific langiage - more a feature of particular languages, and probably overkill here. For scripts I've written for school functionality (stuff like integrating with our MIS), I've tended to write stuff in Python, with the actual technical bits (parsers for XML files, etc) away in a library, then the main scripts become nice operation-by-operation lists of stuff-to-do - open file, apply transform, save file, etc. 2
Shaun_Dark_Lord Posted September 26, 2018 Author Posted September 26, 2018 Thanks David - This appears to be quite a deep rabbit-hole!
dhicks Posted September 26, 2018 Posted September 26, 2018 Thanks David - This appears to be quite a deep rabbit-hole! What sort of thing is it you're trying to do, and using what language? I don't know what your situation is like, but I find trying to get any sort of "proper" software developmnent done in a school setting is tricky - for any functionality that needs more than a quick one-off script thrown together, getting the time to sit and concentrate properly can be difficult. 1
browolf Posted September 26, 2018 Posted September 26, 2018 If you can write the functionality of the script in Pseudocode https://www.computerscience.gcse.guru/theory/pseudocode It might be easier to rearrange. 1
Shaun_Dark_Lord Posted September 26, 2018 Author Posted September 26, 2018 What sort of thing is it you're trying to do, and using what language? I don't know what your situation is like, but I find trying to get any sort of "proper" software developmnent done in a school setting is tricky - for any functionality that needs more than a quick one-off script thrown together, getting the time to sit and concentrate properly can be difficult. Google Classroom creation using SIMS report data. I'm currently using powershell, as I'm also using AD user and group data. I'm now looking at creating the process in a flow chart and feeding it test scenarios to see if my planned changes will work. If so, then I can hopefully tackle one function at a time, and get it done in a few weeks............
dhicks Posted September 26, 2018 Posted September 26, 2018 Google Classroom creation using SIMS report data. Is this something that you need to write yourself? Salamander Soft, Wonde, Groupcall (?) and others have existing tools to do exactly this - Wonde's service starts at £15 a month, which is probably about what it costs the school to hire you for an hour, so if it takes you more than about a day's work in total to sort this (including future maintaianance and updating) it's probably cheaper overall just to pay for the service and use your time for something more interesting.
Shaun_Dark_Lord Posted September 26, 2018 Author Posted September 26, 2018 Is this something that you need to write yourself? Salamander Soft, Wonde, Groupcall (?) and others have existing tools to do exactly this - Wonde's service starts at £15 a month, which is probably about what it costs the school to hire you for an hour, so if it takes you more than about a day's work in total to sort this (including future maintaianance and updating) it's probably cheaper overall just to pay for the service and use your time for something more interesting. Where's the fun in that!
dhicks Posted September 26, 2018 Posted September 26, 2018 Where's the fun in that! :-) But if you're inclined to look at scripting solutions anyway, there's way more fun / useful / interesting stuff that you could be doing with that time and ability. Someone else, for a reasonable fee, will take care of the user syncing, which all schools need to deal with, then you can get on with the stuff that's specific to your school (or even specific subjects / lessons / teachers / pupils). 1
Sephiroth Posted September 26, 2018 Posted September 26, 2018 Having done something similar with some of my own scripts, I would suggest trying to break each section down and get a series of functions written, and depending on the complexity of what you're doing, separate scripts. Once you get your functions, it becomes much easier to debug. I would also put in some kind of logging if you haven't already as that has saved my behind several times! For reference, I had a script that did a huge number of things regarding creation and updating student accounts, which I split into 3 scripts, created a database to manage data and split the 3 scripts into multiple functions, logging everything to a logfile. 1
dhicks Posted September 26, 2018 Posted September 26, 2018 Having done something similar with some of my own scripts, I would suggest trying to break each section down and get a series of functions written, and depending on the complexity of what you're doing, separate scripts. Once you get your functions, it becomes much easier to debug. I would also put in some kind of logging if you haven't already as that has saved my behind several times! Agreed - also, error handling, which takes some thought if you're passing errors in some way from script to script. I have one script here that extracts data from the MIS, then another separate script that creates new user accounts and disables existing accounts if users are no longer active. The first script conked out halfway through due to a character encoding issue (a new child joined with Belgian-style punctuation in their name...) and didn't finish producing the list of currently active pupils, at which point the second script decided it was time to disable the pupils it didn't know about, with hilarious consequences.
Sephiroth Posted September 26, 2018 Posted September 26, 2018 Agreed - also, error handling, which takes some thought if you're passing errors in some way from script to script. I have one script here that extracts data from the MIS, then another separate script that creates new user accounts and disables existing accounts if users are no longer active. The first script conked out halfway through due to a character encoding issue (a new child joined with Belgian-style punctuation in their name...) and didn't finish producing the list of currently active pupils, at which point the second script decided it was time to disable the pupils it didn't know about, with hilarious consequences. Yes, error handling is a very good call. I learned that the hard way with student names containing apostrophes, breaking strings (I now convert all slashes to hyphens and apostrophes to backticks) That's exactly why I decided to go with a database. I export from MIS to database with one script, updating row by row with flags for active, leaver and modified. If that dies, there's only 1 record that is potentially wrong, and due to my logging, I can see where. The other 2 parse the database checking for any accounts that need to be created, modified or removed, and the third creates Exchange contacts with appropriate group memberships (we use Exchange for staff and GMail for students... don't go there!) 1
dhicks Posted September 26, 2018 Posted September 26, 2018 I export from MIS to database with one script, updating row by row with flags for active, leaver and modified. It sounds like we are all spending time writing solutions for the exact same problem - hauling data from an MIS and shovling it somewhere else, with different sets of bugs occuring along the way to trip us and our users up.
Garacesh Posted September 28, 2018 Posted September 28, 2018 Having done something similar with some of my own scripts, I would suggest trying to break each section down and get a series of functions written, and depending on the complexity of what you're doing, separate scripts. Once you get your functions, it becomes much easier to debug. I would also put in some kind of logging if you haven't already as that has saved my behind several times! For reference, I had a script that did a huge number of things regarding creation and updating student accounts, which I split into 3 scripts, created a database to manage data and split the 3 scripts into multiple functions, logging everything to a logfile. This is how I did my O365-fixing scripts, since Microsoft is (was?) terrible at doing things.. One script sorts out their email addresses to not be onmicrosoft, one sets their location to UK, one applies the right license depending on if they're staff or student, one assigns roles, one grants admin access to their email inbox, etc, then I just have one script that calls them all in sequence. The added bonus here is that if I just need to fix email addresses or just need to fix licensing, I can run the one or two scripts I need and not waste time on the rest. 'course now we have Salamander doing it all for us now so those scripts are redundant.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now