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

Modifier order #3

Open
yole opened this issue May 31, 2016 · 10 comments
Open

Modifier order #3

yole opened this issue May 31, 2016 · 10 comments

Comments

@yole
Copy link
Contributor

yole commented May 31, 2016

If a declaration has multiple modifiers, always put them in the following order:

public / protected / private / internal
final / open / abstract
override
inner
enum / annotation
companion
inline
infix
operator
@cypressious
Copy link

I think you're missing the inline modifier.

@AlexeyTsvetkov
Copy link
Member

I think the style guide should discourage from using the public modifier. The only useful case is overriding supertype member visibility:

open class A {
    protected open val x: Int = 10
}

class B : A() {
    public override val x: Int = 20
}

fun main(args: Array<String>) {
    // error: println(A().x)
    println(B().x)
}

@voddan
Copy link

voddan commented Jun 8, 2016

IMO public should be explicit in libraries and other APIs.

Also it makes sense to have more strict formatting rules for library writes.

@yole
Copy link
Contributor Author

yole commented Jun 8, 2016

We did discuss having a separate set of style rules and inspections for library writers. Explicit public will likely be one of the rules. Explicitly declaring all return types will be another, and actually a more important one.

@zeljkot
Copy link

zeljkot commented Mar 30, 2017

lateinit is missing.
BTW it would be nice if IntelliJ could fix this, like for Java (Inspections -> Java -> Missorted modifiers).

@JakeWharton
Copy link

JakeWharton commented Aug 14, 2017

Needs to add header and impl expect and actual.

@antoniolg
Copy link

What about const? I'd probably use it right after the visibility modifier.

@arturbosch
Copy link

agree with @antoniolg

@mkobit
Copy link

mkobit commented Dec 6, 2017

suspend should also be included

@mtopolnik
Copy link

IntelliJ currently generates overriding method declaration putting suspend in front, this seems like a wrong choice. suspend override fun(...) makes less sense than override suspend fun(...). You can't override a suspend with non-suspend and vice versa, but saying suspend override fun() sounds like you can. If it said override suspend fun(...), that would be the natural way of saying that we're "overriding this suspend fun".

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

10 participants