Skip to content
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

Package re-structure #280

Merged
merged 7 commits into from
Feb 10, 2024
Merged

Package re-structure #280

merged 7 commits into from
Feb 10, 2024

Conversation

tonikocjan
Copy link
Contributor

@tonikocjan tonikocjan commented May 8, 2023

  • Re-structured package:
    • PovioKitCore
      • Extensions/
    • PKNetworking
      • ANC/
    • PKPromiseKit
      • Promise/
    • PKSwiftUI
      • Extensions/
      • ActionButton/
      • ProfileImageView/
    • PKUIKit
      • DynamicCollectionCell/
      • GradientView/
      • PaddingLabel
      • TextField
    • PKUtilities
      • a lot of stuff
  • Support for MacOS

@tonikocjan tonikocjan requested a review from a team May 8, 2023 08:58
Copy link
Collaborator

@borut-t borut-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new structure. The core is now small and lean 💪

Comment on lines -23 to -39
do {
return try decoder.decode(type, from: self)
} catch let decodingError as DecodingError {
switch decodingError {
case .typeMismatch(_, let context),
.valueNotFound(_, let context),
.keyNotFound(_, let context),
.dataCorrupted(let context):
Logger.debug("Decoding (failure): \(type.self)", params: ["error": context.debugDescription])
@unknown default:
Logger.debug("Decoding (failure): \(type.self)", params: ["error": "Unknown decoding error."])
}
throw decodingError
} catch {
Logger.debug("Decoding (failure): \(type.self)", params: ["error": error.localizedDescription])
throw error
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Logger is part of the Utilities package, do not want Core to depend on the subpackage.
  2. Logging should be done on the client side.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't agree with both points.

  1. True, but since the Logger is really the core of the whole package, I would leave it in the Core package.
  2. That should be part of the library. Client doesn't and shouldn't know about the implementation details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be part of the library. Client doesn't and shouldn't know about the implementation details.

I disagree. A simple extension function such as this one should be completely pure, i.e. it should not modify the global state.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still tend to disagree. Extension is here for a reason, to "extend" the core functionality. By slashing pretty much all the code, the code left is meaningless, no gain for the developer. We have two options:

  1. revert the change
  2. remove the method completely

Copy link
Contributor Author

@tonikocjan tonikocjan Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function itself is fine, it extends core functionality to use your lingo. But I would not force upon the user as to how they want to handle (and log) the errors.
If it comes to this I will just remove the method.

Comment on lines -23 to -40
func encode(with encoder: JSONEncoder) throws -> [String: Any] {
do {
let data = try encoder.encode(self)
guard let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
throw JSONError.serialization
}
return jsonObject
} catch let encodingError as EncodingError {
switch encodingError {
case .invalidValue(_, let context):
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": context.debugDescription])
@unknown default:
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": "Unknown encoding error."])
}
throw encodingError
} catch {
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": error.self])
throw error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Either revert the change or remove the method completely.

Comment on lines -23 to -39
do {
return try decoder.decode(type, from: self)
} catch let decodingError as DecodingError {
switch decodingError {
case .typeMismatch(_, let context),
.valueNotFound(_, let context),
.keyNotFound(_, let context),
.dataCorrupted(let context):
Logger.debug("Decoding (failure): \(type.self)", params: ["error": context.debugDescription])
@unknown default:
Logger.debug("Decoding (failure): \(type.self)", params: ["error": "Unknown decoding error."])
}
throw decodingError
} catch {
Logger.debug("Decoding (failure): \(type.self)", params: ["error": error.localizedDescription])
throw error
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't agree with both points.

  1. True, but since the Logger is really the core of the whole package, I would leave it in the Core package.
  2. That should be part of the library. Client doesn't and shouldn't know about the implementation details.

Copy link
Collaborator

@borut-t borut-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. Although I have a few concerns:

  • PR should re-structure the package, but is also doing other things
  • PR is adding support for macos
  • PR is changing existing code

We are doing three things in one PR which should be split into three separate PRs. I'm ok with first two points above to be done here, but let's scrap the third out into a separate PR.

Comment on lines -23 to -39
do {
return try decoder.decode(type, from: self)
} catch let decodingError as DecodingError {
switch decodingError {
case .typeMismatch(_, let context),
.valueNotFound(_, let context),
.keyNotFound(_, let context),
.dataCorrupted(let context):
Logger.debug("Decoding (failure): \(type.self)", params: ["error": context.debugDescription])
@unknown default:
Logger.debug("Decoding (failure): \(type.self)", params: ["error": "Unknown decoding error."])
}
throw decodingError
} catch {
Logger.debug("Decoding (failure): \(type.self)", params: ["error": error.localizedDescription])
throw error
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still tend to disagree. Extension is here for a reason, to "extend" the core functionality. By slashing pretty much all the code, the code left is meaningless, no gain for the developer. We have two options:

  1. revert the change
  2. remove the method completely

Comment on lines -23 to -40
func encode(with encoder: JSONEncoder) throws -> [String: Any] {
do {
let data = try encoder.encode(self)
guard let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
throw JSONError.serialization
}
return jsonObject
} catch let encodingError as EncodingError {
switch encodingError {
case .invalidValue(_, let context):
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": context.debugDescription])
@unknown default:
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": "Unknown encoding error."])
}
throw encodingError
} catch {
Logger.debug("Encoding (failure): \(type(of: self))", params: ["error": error.self])
throw error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Either revert the change or remove the method completely.

@borut-t
Copy link
Collaborator

borut-t commented Jan 26, 2024

Great work @tonikocjan. We need some additional changes:

  • rebase branch
  • move /Core/Utilities/MediaPlayer to Utilities subpackage
  • move /Utilities/Logger to Core subpackage (it's a must on every project, even if we don't need Utilities subpackage I should have access to the Logger from the Core subpackage)
  • Async subpackage feels redundant to me. We have async code in other places as well, but we didn't move it here.

@tonikocjan
Copy link
Contributor Author

Async subpackage feels redundant to me.

Apple also has a separate swift package for Async data structures and algorithms. I think separating makes sense as a user might only need some async algorithm that we provide.

We have async code in other places as well, but we didn't move it here.

The other async code is already nicely contained in the Networking and Promise sub-packages. Any other code that strongly utilizes Swift concurrency, should be moved inside the Async package.

Revert promise changes

+1
@tonikocjan tonikocjan requested review from a team and removed request for a team February 9, 2024 11:15
@borut-t
Copy link
Collaborator

borut-t commented Feb 9, 2024

Async subpackage feels redundant to me.

Apple also has a separate swift package for Async data structures and algorithms. I think separating makes sense as a user might only need some async algorithm that we provide.

We have async code in other places as well, but we didn't move it here.

The other async code is already nicely contained in the Networking and Promise sub-packages. Any other code that strongly utilizes Swift concurrency, should be moved inside the Async package.

Great. Let's proceed 👌

Copy link
Collaborator

@borut-t borut-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@borut-t borut-t requested review from dejanskledar and a team February 9, 2024 14:13
@borut-t borut-t merged commit 7c1873c into develop Feb 10, 2024
1 check passed
@borut-t borut-t deleted the macos branch February 10, 2024 08:40
borut-t pushed a commit that referenced this pull request May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants