New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Break up the massive installPackage
function
#293
Comments
Here's a link to the function in question: |
Ok |
One easy way to recognize this is:
This feels like a method! The usage looks like this: let installationResult = try await installPackage(installationProgressTracker: installationProgressTracker, brewData: brewData) With method it would look more like this: let installationResult = try await installationProgressTracker.installPackage(using: brewData) What do you think? |
Hmm that's an interesting idea! I think it could work. The current architecture is a bit unconventional (most of the logic is completely detached from objects, with some exceptions like BrewDataStorage and OutdatedPackageTracker). I was thinking of gradually making those single-use functions into methods |
Making it a top-level function does come with a number of major drawbacks. One is the mutation of the internal state of installationProgressTracker is really awkward, motivating the use of things like This isn't inherently wrong! And I want to leave stylistic things like this up to you. It is possible to improve this with more top-level functions as well. |
Thanks for the insight! You're right, the mutation of internal state is one of the motivations I had for adding methods to Truth be told, Cork is my second ever programming project, so it has a lot of weirdness stemming from me having no idea what I was doing back then 😂 I'm always happy to learn, so if you think making it a method would make it more convenient, I'm all for it. I just don't want to make massive changes all over the place, which I would not be able to maintain. But I'm okay with a few changes here and there. |
I think you'll find that not making structural improvements over time will lead to a higher maintenance burden - like this current issue! The secret is just to go slowly. |
Yes, you're absolutely correct 😊 |
Ok I've begun a PR: #295 |
I think I may have found a bug though: line 104 of "Installing.swift"
|
Oh yeah, this is a vestige from WAY back when there was still support for installing more than one package at the same time, which is not coming back. I've been meaning to completely remove the
|
So in the end, that loop isn't needed anymore, since there can now be only one package being installed at a time. |
Ah this explains the |
I'm also now noticing some real concurrency issues. In particular, it almost never makes sense to have an Using |
You're right! That's definitely something I'm planning. There are a lot of hidden concurrency issues (like #190, I suspect). I'm reading up on the in-depths of concurrency to hopefully fix it soon 😊 |
This can be tough, but please do let me know what you are reading and how it goes! This is an active project of mine. |
I'm reading this: https://donnywals.gumroad.com/l/practical-swift-concurrency and I'd definitely recommend it! |
Ah, I know it and I have already read a few chapters! I was slightly worried, because Donny wrote it before Swift 5.10 shipped and that version contains major changes related to concurrency. But I really should finish it up! |
Ok, I know this is closed, but I thought I'd just throw some more ideas in here. We did the easy stuff: break up a big if-else into two functions and make use of an instance method instead of a top-level function. But the two remaining functions are still quite large. And now it's harder to simplify. I think there are two things contributing to the verbosity: the logging and the string pattern matching. One idea might be to move the pattern matching into an enum-based system. This might make testing a little easier too. It's possible that using an enum could also internalize some of the logging. Would have to experiment a little to see how that works. But, my next area of investigation would be changing all of the conditionals like |
No problem :) I'll reopen this. I originally wanted to have the matching to be done in an enum, but I couldn't figure out how to do it. You can see if you can figure something out, I'd be really grateful. |
No description provided.
The text was updated successfully, but these errors were encountered: