Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

in-class-def constructor declarations #26

Closed
Groostav opened this issue Jun 28, 2016 · 1 comment
Closed

in-class-def constructor declarations #26

Groostav opened this issue Jun 28, 2016 · 1 comment

Comments

@Groostav
Copy link

Groostav commented Jun 28, 2016

For smaller classes, such as data classes and smaller objects, the primary constructor in-class-definition syntax is quite clear and concise:

class Whatever(x: Int, importantDomainThing: String){
  //...
}

but when more traditional enterprise schemes jump in, including long class names, long variable names, multiple dependencies, an IOC/DI container, etc, this syntax needs to be split over multiple lines.

So far our convention I've been going with is something like this:

class OPYLConfigurationApplicator
@Inject constructor(
        private val eventBus: EventBus,
        private val compiler: EvaluableCompiler,
        private val dupeService: DeduplicatingVariableSymbolGeneratingService,
        private val graph: GraphModel
){
    private val whatever = //...

    //note the indentation level is 4, meaning the above constructor is double-indented
}

The double indentation is to make the constructor evocative of long parameter lists which, for us (as per an intelliJ default), are also double-indented on each parameter.

Some other questions:

  • how does this change when implementing many interfaces and/or extending a base class
  • is the newline before @Inject superfluous?
@Groostav
Copy link
Author

I've created this repos first duplicate 😢 #2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant