i had an interesting debate with a colleague this afternoon - it was over some snippets of code that look like this:
public
func build(pipeline:inout Mongo.PipelineEncoder)
{
Self.loadSubscribers(&pipeline, premium: false, limit: self.limit, skip: 0)
Self.loadSubscribers(&pipeline, premium: true, limit: self.limit, skip: 0)
he said this was stupid, that there was obviously a mutating
instance function on Mongo.PipelineEncoder
trying to come out here, and that the code would read much more fluently if it were written like this:
public
func build(pipeline:inout Mongo.PipelineEncoder)
{
pipeline.loadSubscribers(premium: false, limit: self.limit, skip: 0)
pipeline.loadSubscribers(premium: true, limit: self.limit, skip: 0)
but i shot that down because it would run afoul of our organization’s one type per file rule. punctiliously applying that policy would require loadSubscribers
to go in a separate Mongo.PipelineEncoder (ext).swift
file, and this function is too specific to this particular aggregation pipeline to be visible to the entire module.
it was half-seriously suggested that we should break up the DB queries module into individual modules for each database query, which would satisfy the policy by giving each query its own Mongo.PipelineEncoder (ext).swift
file. but i personally felt like that would be a lot of effort to expend in order to satisfy some policy i introduced.
my question is then: do you have a similar one type per file policy in place where you code? if so, have you found it productive or counterproductive?