-
Notifications
You must be signed in to change notification settings - Fork 17
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
Extensibility for Command #92
Comments
The problem with this approach is when you implement a server though. You’ll basically have to do a giant if let rename = command.asRename {
// handle rename
print(rename)
} else if let select = command.asSelect {
// handle select
print(select)
} else {
// send BAD command
} as you indicated — which is not nice and smells like it’s not particularly performant. I still think that |
I agree with @danieleggert that pattern matching is useful when handling commands in the context of a server. This also applies to testing, where you might write a fake server or want to extract information from the command. Enums are more natural and concise. The existing design seems like it has extensibility in the right place—in |
@danieleggert / @mdiep extensibility is necessary to add stuff like the Regarding performance, I’m pretty sure we can come up with a spelling that gets us a jump table. It’s unlikely (not impossible though, I’ll check) that LLVM realises that it could turn those tons of Another option of course is to make a “matcher” protocol that has one function per command that you want to match and requires a special one for “unknown command”. To add a new command, we’d provide a default implementation that goes to the “unknown command”. If only swift had open enums 😅 |
(It does, but only in library evolution mode which isn’t what SwiftPM uses and also it comes with other very serious drawbacks) |
@mdiep / @danieleggert alternative is to keep the enum but "hack it open"
|
I've been thinking about this a little over the last couple of days. What about being able to give the parser additional parsing functions. E.g. we could implement some function
(Note that the above is pseudo-ish code and will not compile) |
@Davidde94 there are two issues:
Your proposal could be part of a solution to (1) but this ticket is about (2). |
I've been thinking a little about this recently. I don't think it matters too much that it's an enum. If we add support for a new command then we can just bump the major version. Adding support for an entirely new set of RFCs seems like good enough cause to push out a new major IMO. |
@Davidde94 we can't do that. "An entirely new RFC" sounds like there are only 1 or 2. But there are many so I don't think this is reasonable. It's very common to the IMAP protocol that new commands/responses get added so we need to support that. We can just add a |
I’d argue, though, that there a few RFCs that add new commands. Most of them just change how existing commands work or what responses contain, etc. Before we move ahead here, I think it would be good to look at any RFCs that aren’t supported, yet. Then see which ones are likely to make sense, and then evaluate what changes would be needed to support them. I’d assume that for most of them we would have to push out a new major version — not due to commands, but due to how they’d change arguments to existing commands and/or responses. #286 was our initial “wish list”. David initially had a list of “all” RFCs here https://github.com/apple/swift-nio-imap/blob/bc1e84b3b8ada9bfbcdd098a77a33e565ac0efea/README.md |
@weissi your solution is a hack though. If we're concerned about pushing too many majors versions we can always batch RFCs. @danieleggert good idea, I can take care of this. Also worth noting that this doesn't only apply to commands, but also responses. |
@Davidde94 yes, it's a hack until https://bugs.swift.org/browse/SR-12666 is resolved. |
This _only_ handles _encoding_ of custom commands. This simply adds a ```swift case custom(name: String, payloads: [CustomCommandPayload]) ``` such that clients of this library do their own encoding of such commands. This is related to the discussion in #92
This _only_ handles _encoding_ of custom commands. This simply adds a ```swift case custom(name: String, payloads: [CustomCommandPayload]) ``` such that clients of this library do their own encoding of such commands. This is related to the discussion in #92
Commands need to be extensible so they can't be a big
enum
.My proposal
The text was updated successfully, but these errors were encountered: