Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 762 Bytes

inert_defer.md

File metadata and controls

51 lines (35 loc) · 762 Bytes

Pattern: Inert defer

Issue: -

Description

If defer is at the end of its parent scope, it will be executed right where it is anyway.

Examples of correct code:

func example3() {
    defer { /* deferred code */ }

    print("other code")
}


func example4() {
    if condition {
        defer { /* deferred code */ }
        print("other code")
    }
}

Examples of incorrect code:

func example0() {
    defer { /* deferred code */ }
}


func example1() {
    defer { /* deferred code */ }
    // comment
}


func example2() {
    if condition {
        defer { /* deferred code */ }
        // comment
    }
}

Further Reading