-
Notifications
You must be signed in to change notification settings - Fork 20
Follow API naming Guidelines #96
Comments
Swift API Guidlines and SwiftCloudantAlong with Swift 3, there are official API guidelines approved by the Swift community community via the swift evolution process. SwiftCloudant currently does not follow the guidelines that are laid out by the community. The most common violation of the guidelines are enum capitalisation, for example, Our aim should be to make the API as expressive as possible and behave has expected. This may mean departing form the CouchDB way of naming parameters to make their purpose clearer. The example of that General
There are some potential issues with the API, with Swift's explicit nullablity constructs, it is odd that we allow the the assigning of To simplify documentation, validation logic and behave as the user would expect, should required parameters become required for initialization and become explicitly non-null? This goes beyond The naming of parameters are abbreviated, perhaps the abbreviations should be changed to make more sense. For example the public class GetDocumentOperation : CouchOperation, CouchDatabaseOperation, JSONOperation {
// ...
public init(id: String) {
// ....
}
// ...
}
public class GetAttachmentOperation : CouchOperation, CouchDatabaseOperation, DataOperation {
// ...
public init(documentID: String, name: String) {
// ...
}
// ...
} With // more abbreviations The method let viewKey = "api"
let jsonViewKey = jsonValue(of: viewKey) With the above it is plain to see what the intent of the method is without looking at the documentation. While we are also here we should be making it possible to use the native swift types directly with this method. So CouchDBClient
Having to write public init(url: URL) The above will call down into the designated constructor with the username and password set to public init(url: URL, username: String, password: String) this would make it clear that a username and password should both be provided.
The adding operations to the queue to be executed needs improvement. It can be confusing which kind of operation you have when faced the the method signatures: public func add(operation: CouchOperation) -> Operation {}
public func add(operation: Operation) -> Void {} There is no easy solution for this, however we could mitigate the confusion for users by replacing those methods with public func add(couchOperation: CouchOperation) -> Operation
public func add(operation: Operation) -> Void It reduces cognitive burden around if you'll get an object returned or not, However documentation should make it clear with the case of the CouchOperation variant, that the CouchOperation
guard error == nil, let httpInfo = httpInfo
else {
self.complete(error: error!)
return
}
self.complete(response: response, httpInfo: info, error: nil) JsonOperation
CreateDatabaseOperationCreateDatabaseOperation exposes it's database name as an property an an init method which takes no arguments, now the property needs to be set before the operation can be completed. Perhaps the type for the database name needs to be changed to CreateJsonQueryIndexOperationClass needs to be renamed to Properties.
CreateTextQueryIndexOperationPropertiesAgain
TextIndexFieldTypeThis should be relocated from it's current top level and move to be within the The vase entries need to be renamed to be lower case. The cases should be DeleteAttachmentOperationChange type of DeleteQueryIndexOperation
FindDocumentsOperation
Mango Operation
GetDocumentOperation
Operation
QueryViewOperation
OperationRequestBuilder
HTTPInterceptor
ViewOperation
|
So the above gives me view on what needs to be changed to match the guidelines, anyone have any thoughts? @ricellis |
Some APIs do not follow the API naming Guidelines for Swift 3. Such as the enum
Stale
which has the elementsOk
andUpdateAfter
in Swift 3 they should be namedok
andupdateAfter
respectively. There are probably other APIs which do not match the convention, we need to audit and propose replacements for each API that does not follow the guidelines.The guidelines can be found here.
The text was updated successfully, but these errors were encountered: