In Part 3 (Refactoring the function PS_GetFileHashes (Part 3) | Access JumpStart) we arrived at this code with helper functions and a helper class:
So, I am focusing on that very first function PS_GetFileHashes and refactoring that down to something more understandable and compact. I want users to be able to read the function and be able to tell what it is doing and follow along. I’ve refactored a lot of the code out to a class and some helper functions. Looking at the function, I’m going to remove some of the comments since the following line explains what’s happening in place of the comment now.
So the question becomes, how do I refactor the second portion. I’m thinking first that I don’t really like the way aOutput is loaded with the crazy nested functions. I think I’ll move that to our PScmd class in a method that will execute the command and return the array output.
And actually, the part I want to refactor, the loop, isn’t easily lending itself to refactoring. But what if I were to return a dictionary to aOutput instead of an array. It might be more intuitive to loop over each key. Or, I guess I could pass the retVal dictionary by reference. Although I don’t really like that idea because I don’t like passing arguments to functions and have them modified. Although it’s more concise that way AND I am already doing that with aIdx. I guess I’ll try it and see what I think. In fact, I’ll just add it to the RunCmd function and not return anything. So here is the original function portion after all that:
Ok, then in the next segment, I’ll remove my unneeded Dim statements from the beginning of the function, and refactor the Error display code to be briefer in the function itself, and we’ll be done. Whew!