Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-402

Handle MongoSwift name conflicts



    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.1.1
    • Component/s: None
    • Labels:


      In Swift, it is possible and common that two modules may define types with conflicting names. If a user imports both of them in the same file, they can disambiguate which type they mean by prefixing it with the module name. For example, if ModuleA and ModuleB both have a type Foo, the user can refer to a specific one with ModuleA.Foo or ModuleB.Foo

      The driver defines a class called MongoSwift that handles libmongoc initialization and cleanup via two methods, MongoSwift.initialize and MongoSwift.cleanup. This class name is problematic because it makes it difficult for users to disambiguate our types as described above. MongoSwift.Foo will look for a member of the class named Foo, rather than a type in the library named Foo. There are some workarounds for this, as described here: users can add typealiases in separate files, or use a special import syntax for the type in question.

      We have a few options for dealing with this: 

      1) Do nothing. Users can use the solutions in the post linked above to work around this if/when they encounter a naming conflict. IMO, not optimal because the workarounds are non-obvious, and the compiler error you get trying to do this the normal way is confusing if you don't realize we have a class called MongoSwift.

      2) Move the initialize and cleanup functions to be free-floating and get rid of the class. This won't break anyone's existing code, as these functions would still be named MongoSwift.initialize and MongoSwift.cleanup (the MongoSwift prefix would just be unnecessary in most cases.)

      3) Move he initialize and cleanup functions to be free-floating and rename them more descriptively (e.g. initializeMongoSwift), and get rid of the class.

      4) Rename the class to something else, e.g. MongoSwiftDriver.




            kaitlin.mahar Kaitlin Mahar
            kaitlin.mahar Kaitlin Mahar
            0 Vote for this issue
            1 Start watching this issue